| | |
| | | } |
| | | |
| | | public boolean isChinese() { |
| | | if (raw.length < 31) return false; |
| | | int isChinese = raw[30] & 0x0000ffff; |
| | | |
| | | return (isChinese == 0xfdff); |
| | |
| | | </entry> |
| | | <entry> |
| | | <key>ORGSCHEMA</key> |
| | | <value>SPATIALDB</value> |
| | | <!--value>SPATIALDB, CMMS_SPATIALDB</value--> |
| | | <!--value>SPATIALDB</value--> |
| | | <value>SPATIALDB, CMMS_SPATIALDB</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTDB</key> |
| | |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Statement; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryCollection; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | import com.vividsolutions.jts.geom.LinearRing; |
| | | import com.vividsolutions.jts.geom.MultiLineString; |
| | | import com.vividsolutions.jts.geom.MultiPoint; |
| | | import com.vividsolutions.jts.geom.MultiPolygon; |
| | | import com.vividsolutions.jts.geom.Point; |
| | | import com.vividsolutions.jts.geom.Polygon; |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.eofms.util.postjts.JtsBinaryWriter; |
| | | import org.geotools.data.DataSourceException; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.SchemaNotFoundException; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.jdbc.JDBCUtils; |
| | | import org.geotools.data.postgis.PostGISDialect; |
| | | import org.geotools.filter.LengthFunction; |
| | | import org.geotools.jdbc.JDBCDataStore; |
| | | import org.geotools.referencing.NamedIdentifier; |
| | |
| | | import org.opengis.filter.expression.Literal; |
| | | import org.opengis.referencing.crs.CoordinateReferenceSystem; |
| | | |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.GeometryCollection; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | import com.vividsolutions.jts.geom.MultiLineString; |
| | | import com.vividsolutions.jts.geom.MultiPoint; |
| | | import com.vividsolutions.jts.geom.MultiPolygon; |
| | | import com.vividsolutions.jts.geom.Point; |
| | | import com.vividsolutions.jts.geom.Polygon; |
| | | import com.vividsolutions.jts.io.WKBWriter; |
| | | import com.vividsolutions.jts.io.WKTWriter; |
| | | |
| | | import com.ximple.eofms.jobs.context.AbstractDgnFileJobContext; |
| | | import com.ximple.eofms.util.postjts.JtsBinaryWriter; |
| | | |
| | | public abstract class AbstractDgnToPostGISJobContext extends AbstractDgnFileJobContext { |
| | | |
| | | private static Map<String, Class> GEOM_TYPE_MAP = new HashMap<String, Class>(); |
| | | private static Map<String, Class> GEOM3D_TYPE_MAP = new HashMap<String, Class>(); |
| | | |
| | |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | |
| | | protected void dropTable(Connection conn, String tableName) throws SQLException { |
| | | protected boolean dropTable(Connection conn, String tableName) throws SQLException { |
| | | Statement stmt = conn.createStatement(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("DROP TABLE \""); |
| | |
| | | sb.append(tableName); |
| | | sb.append("\""); |
| | | // sb.append(" CASCADE"); |
| | | stmt.execute(sb.toString()); |
| | | if (!conn.getAutoCommit()) |
| | | conn.commit(); |
| | | JDBCUtils.close(stmt); |
| | | |
| | | try { |
| | | stmt.execute(sb.toString()); |
| | | } catch (SQLException e) { |
| | | getLogger().warn("Execute-" + sb.toString()); |
| | | getLogger().warn(e.getMessage(), e); |
| | | return false; |
| | | } finally { |
| | | if (!conn.getAutoCommit()) |
| | | conn.commit(); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | protected void dropGeometryColumn(Connection conn, String tableName, String geomField) throws SQLException { |
| | | protected boolean dropGeometryColumn(Connection conn, String dbSchema, String tableName, String geomField) throws SQLException { |
| | | Statement stmt = conn.createStatement(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("SELECT \"public\".DropGeometryColumn('','"); |
| | | sb.append("SELECT \"public\".DropGeometryColumn('"); |
| | | sb.append(dbSchema); |
| | | sb.append("','"); |
| | | sb.append(tableName); |
| | | sb.append("','"); |
| | | sb.append(geomField); |
| | | sb.append("')"); |
| | | stmt.execute(sb.toString()); |
| | | if (!conn.getAutoCommit()) |
| | | conn.commit(); |
| | | JDBCUtils.close(stmt); |
| | | try { |
| | | stmt.execute(sb.toString()); |
| | | } catch (SQLException e) { |
| | | getLogger().warn("Execute-" + sb.toString()); |
| | | getLogger().warn(e.getMessage(), e); |
| | | return false; |
| | | } finally { |
| | | if (!conn.getAutoCommit()) |
| | | conn.commit(); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | protected String dropGeometryColumn(String dbSchema, String tableName, String geomField) { |
| | |
| | | conn.commit(); |
| | | } |
| | | |
| | | protected void dropTable(Connection conn, String schemaName, String tableName) throws SQLException { |
| | | protected boolean dropTable(Connection conn, String schemaName, String tableName) throws SQLException { |
| | | Statement stmt = conn.createStatement(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("DROP TABLE \""); |
| | |
| | | sb.append(tableName); |
| | | sb.append("\""); |
| | | // sb.append(" CASCADE"); |
| | | stmt.execute(sb.toString()); |
| | | stmt.close(); |
| | | conn.commit(); |
| | | try { |
| | | stmt.execute(sb.toString()); |
| | | } catch (SQLException e) { |
| | | getLogger().warn("Execute-" + sb.toString()); |
| | | getLogger().warn(e.getMessage(), e); |
| | | return false; |
| | | } finally { |
| | | stmt.close(); |
| | | conn.commit(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | protected void dropGeometryColumn(Connection conn, String dbSchema, String tableName, String geomField) throws SQLException { |
| | | protected boolean dropGeometryColumn(Connection conn, String dbSchema, String tableName, String geomField) throws SQLException { |
| | | Statement stmt = conn.createStatement(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("SELECT \"public\".DropGeometryColumn('"); |
| | |
| | | sb.append("','"); |
| | | sb.append(geomField); |
| | | sb.append("')"); |
| | | stmt.execute(sb.toString()); |
| | | stmt.close(); |
| | | conn.commit(); |
| | | |
| | | try { |
| | | stmt.execute(sb.toString()); |
| | | } catch (SQLException e) { |
| | | getLogger().warn("Execute-" + sb.toString()); |
| | | getLogger().warn(e.getMessage(), e); |
| | | return false; |
| | | } finally { |
| | | stmt.close(); |
| | | conn.commit(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | protected String dropGeometryColumn(String dbSchema, String tableName, String geomField) { |
| | |
| | | |
| | | SimpleFeatureType featureType = featureTypes.get(featureTypeName); |
| | | String featureName = featureType.getName().getLocalPart(); |
| | | String currentSQL = null; |
| | | if (isExistFeature(featureType)) { |
| | | try { |
| | | conn = getConnection(); |
| | | if (dropTableMode) { |
| | | dropGeometryColumn(conn, featureName, |
| | | dropGeometryColumn(conn, featureName, getTargetSchema(), |
| | | (featureType).getGeometryDescriptor().getLocalName()); |
| | | dropTable(conn, featureName); |
| | | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | } else { |
| | | deleteTable(conn, featureName); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (isProfileMode()) accumulateUpdateTime(); |
| | | } |
| | | } else { |
| | |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (isProfileMode()) accumulateUpdateTime(); |
| | | } |
| | | } |
| | |
| | | Connection conn = null; |
| | | SimpleFeatureTypeBuilder typeBuilder1 = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName); |
| | | featureType1 = typeBuilder1.buildFeatureType(); |
| | | String currentSQL = null; |
| | | |
| | | if (isExistFeature(featureType1)) { |
| | | try { |
| | | conn = getConnection(); |
| | | if (dropTableMode) { |
| | | try { |
| | | dropGeometryColumn(conn, featureName, |
| | | dropGeometryColumn(conn, getTargetSchema(), featureName, |
| | | (featureType1).getGeometryDescriptor().getLocalName()); |
| | | } catch (PSQLException e) { |
| | | logger.debug(e.getMessage(), e); |
| | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType1); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | } else { |
| | | deleteTable(conn, featureName); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } else { |
| | | try { |
| | |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | stmt.execute(stmtText); |
| | | currentSQL = stmtText; |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } |
| | | } |
| | |
| | | Connection conn = null; |
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalIndexTextFeatureTypeBuilder(featureName); |
| | | featureType2 = typeBuilder.buildFeatureType(); |
| | | String currentSQL = null; |
| | | if (isExistFeature(featureType2)) { |
| | | try { |
| | | conn = getConnection(); |
| | | if (dropTableMode) { |
| | | dropGeometryColumn(conn, featureName, |
| | | dropGeometryColumn(conn, getTargetSchema(), featureName, |
| | | (featureType2).getGeometryDescriptor().getLocalName()); |
| | | dropTable(conn, featureName); |
| | | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType2); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | } else { |
| | | deleteTable(conn, featureName); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } else { |
| | | try { |
| | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType2); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } |
| | | } |
| | |
| | | Connection conn = null; |
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName); |
| | | featureType3 = typeBuilder.buildFeatureType(); |
| | | String currentSQL = null; |
| | | if (isExistFeature(featureType3)) { |
| | | try { |
| | | conn = getConnection(); |
| | | if (dropTableMode) { |
| | | try { |
| | | dropGeometryColumn(conn, featureName, |
| | | dropGeometryColumn(conn, getTargetSchema(), featureName, |
| | | (featureType3).getGeometryDescriptor().getLocalName()); |
| | | } catch (PSQLException e) { |
| | | logger.debug(e.getMessage(), e); |
| | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType3); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | } else { |
| | | deleteTable(conn, featureName); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } else { |
| | | try { |
| | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType3); |
| | | for (String stmtText : schemaTexts) { |
| | | Statement stmt = conn.createStatement(); |
| | | currentSQL = stmtText; |
| | | stmt.execute(stmtText); |
| | | JDBCUtils.close(stmt); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | if (currentSQL != null) |
| | | logger.warn("executeSQL:" + currentSQL); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } |
| | | } |
| | |
| | | conn = getConnection(); |
| | | if (dropTableMode) { |
| | | dropGeometryColumn(conn, getTargetSchema(), featureName, |
| | | ((FeatureTypeImpl)featureType).getGeometryDescriptor().getName().getLocalPart()); |
| | | (featureType).getGeometryDescriptor().getName().getLocalPart()); |
| | | dropTable(conn, getTargetSchema(), featureName); |
| | | |
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType); |
| | |
| | | } else { |
| | | deleteTable(conn, getTargetSchema(), featureName); |
| | | } |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } catch (IOException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (SQLException e) { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); |
| | | logger.warn(e.getMessage(), e); |
| | | } finally { |
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); |
| | | } |
| | | } else { |
| | | String tempStmt = null; |