?? ?
2012-11-23 3052e5d870a90ee5f3ea3d3dff887436d8ccdfea
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
@@ -129,6 +129,7 @@
    }
    public boolean isChinese() {
        if (raw.length < 31) return false;
        int isChinese = raw[30] & 0x0000ffff;
        return (isChinese == 0xfdff);
xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml
@@ -78,8 +78,8 @@
        </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>
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractDgnToPostGISJobContext.java
@@ -8,16 +8,29 @@
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;
@@ -35,21 +48,8 @@
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>();
@@ -194,7 +194,7 @@
        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 \"");
@@ -203,24 +203,45 @@
        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) {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/AbstractOracleToPostGISJobContext.java
@@ -190,7 +190,7 @@
        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 \"");
@@ -199,12 +199,20 @@
        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('");
@@ -214,9 +222,18 @@
        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) {
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/GeneralDgnConvertPostGISJobContext.java
@@ -533,31 +533,35 @@
        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 {
@@ -569,14 +573,16 @@
                    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();
            }
        }
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/IndexDgnConvertPostGISJobContext.java
@@ -311,13 +311,14 @@
            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);
@@ -330,19 +331,23 @@
                        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 {
@@ -351,15 +356,19 @@
                    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);
                }
            }
        }
@@ -370,30 +379,35 @@
            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 {
@@ -401,16 +415,20 @@
                    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);
                }
            }
        }
@@ -421,12 +439,13 @@
            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);
@@ -439,19 +458,23 @@
                        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 {
@@ -459,16 +482,20 @@
                    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);
                }
            }
        }
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/postgis/OracleConvertPostGISJobContext.java
@@ -332,7 +332,7 @@
                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);
@@ -344,13 +344,12 @@
                } 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;