Dennis Kao
2014-02-10 336ad059eeb373446f994dbb89d2fda0e07825fb
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeoserverIntegrateConfigJob.java
@@ -245,6 +245,9 @@
                String viewName = sbView.toString();
                if (allViewNames.contains(viewName)) {
                    resetThemesPostgisDataView(connection, ownerName, null, viewName);
                    if (tid == 106) {
                        resetFlowThemesPostgisDataView(connection, ownerName, null, viewName);
                    }
                }
            }
@@ -454,6 +457,45 @@
        }
    }
    private void resetFlowThemesPostgisDataView(Connection connection, String ownerName,
                                            String currentSchema, String viewName) throws SQLException {
        String themeViewName = viewName + "-flow-oms";
        ResultSet rs = null;
        Statement stmt = connection.createStatement();
        try {
            StringBuilder sbSQL = new StringBuilder("CREATE OR REPLACE VIEW \"");
            sbSQL.append(themeViewName).append("\" AS SELECT ");
            rs = connection.getMetaData().getColumns(null, currentSchema, viewName, "%");
            while (rs.next()) {
                String fieldName = rs.getString("COLUMN_NAME");
                sbSQL.append("t." + fieldName).append(", ");
            }
            sbSQL.append("fc.dyncolor, fo.fowner, fo.flow FROM ");
            if (currentSchema != null)
                sbSQL.append("\"").append(currentSchema).append("\".\"").append(viewName).append("\" AS t,");
            else
                sbSQL.append("\"").append(viewName).append("\" AS t,");
            sbSQL.append("xpwtheme").append(FDYNCOLOR_SUFFIX).append(" AS fc,");
            sbSQL.append("xpwtheme").append(FOWNER_SUFFIX).append(" AS fo WHERE ");
            sbSQL.append("t.tid = fc.tid AND t.oid = fc.oid AND ");
            sbSQL.append("t.tid = fo.tid AND t.oid = fo.oid");
            // sbSQL.delete(sbSQL.length() - 2, sbSQL.length());
            String sql = sbSQL.toString();
            stmt.execute(sql);
            sbSQL.delete(0, sbSQL.length());
            PrintfFormat pf = new PrintfFormat(ALTER_VIEWSQL + ownerName);
            sql = pf.sprintf(themeViewName);
            stmt.execute(sql);
        } finally {
            JDBCUtils.close(rs);
            JDBCUtils.close(stmt);
        }
    }
    private HashMap<String, String> retrieveViewDef(Connection connection, String schemaName, String tablePattern) throws SQLException {
        PreparedStatement stmt = connection.prepareStatement(QUERY_VIEWDEFSQL + "'" + tablePattern + "'");
        stmt.setString(1, schemaName);