| | |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/log4j.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz.properties svneol=native#text/plain |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs_edb.xml -text svneol=unset#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs_shapefiles.xml svneol=native#text/xml |
| | | xdgnjobs/ximple-jobcarrier/src/test/java/com/ximple/eofms/XQuartzJobCarrierTest.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/pom.xml svneol=native#text/xml |
| | |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DataReposVersionManager.java -text |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DummyFeatureConvertJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2EdbGeoJob.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2MySQLJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2OraSDOJob.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2PostGISJob.java svneol=native#text/plain |
| | |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractDgnFileJobContext.java -text |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/AbstractOracleJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/OracleUpgradeJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/AbstractDgnToEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/AbstractOracleToEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/DummyFeatureConvertEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/FeatureDgnConvertEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/GeneralDgnConvertEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/IndexDgnConvertEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/edbgeo/OracleConvertEdbGeoJobContext.java -text svneol=unset#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractDgnToMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/AbstractOracleToMySQLJobContext.java svneol=native#text/plain |
| | | xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/context/mysql/DummyFeatureConvertMySQlJobContext.java svneol=native#text/plain |
| | |
| | | <dependency> |
| | | <groupId>com.vividsolutions</groupId> |
| | | <artifactId>jts</artifactId> |
| | | <version>1.10</version> |
| | | <version>1.11</version> |
| | | </dependency> |
| | | |
| | | <!-- Apache --> |
| | |
| | | <groupId>org.geotools</groupId> |
| | | <artifactId>gt-epsg-h2</artifactId> |
| | | <version>${gt2.version}</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>com.h2database</groupId> |
| | | <artifactId>h2</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | |
| | | <version>5.1.12</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.h2database</groupId> |
| | | <artifactId>h2</artifactId> |
| | | <version>1.2.134</version> |
| | | </dependency> |
| | | |
| | | <!-- EnterpriseDB --> |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>xedb-gt-geospatial</artifactId> |
| | | <version>0.1.1</version> |
| | | </dependency> |
| | | |
| | | <!-- quartz-scheduler--> |
| | | <dependency> |
| | | <groupId>org.quartz-scheduler</groupId> |
| | |
| | | <version>1.1.0-rc</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>xerces</groupId> |
| | | <artifactId>xercesImpl</artifactId> |
| | | <version>2.9.1</version> |
| | | </dependency> |
| | | <!-- Tests or legacy --> |
| | | <dependency> |
| | | <groupId>org.testng</groupId> |
| | |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.h2database</groupId> |
| | | <artifactId>h2</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>xerces</groupId> |
| | | <artifactId>xercesImpl</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <artifactId>testng</artifactId> |
| | | <groupId>org.testng</groupId> |
| | | <classifier>jdk15</classifier> |
| | |
| | | <includes> |
| | | <include>log4j.properties</include> |
| | | <include>quartz.properties</include> |
| | | <include>quartz_jobs.xml</include> |
| | | <!--<include>quartz_jobs.xml</include>--> |
| | | <include>quartz_jobs_edb.xml</include> |
| | | </includes> |
| | | <!-- |
| | | <excludes> |
| | |
| | | <job> |
| | | <name>ConvertDgn2PostGisIntoPostgre</name> |
| | | <group>DEFAULT</group> |
| | | <description>A job that convert dgn to shapefiles</description> |
| | | <description>A job that convert dgn to postgis</description> |
| | | <job-class>com.ximple.eofms.jobs.OracleConvertDgn2PostGISJob</job-class> |
| | | <volatility>false</volatility> |
| | | <durability>false</durability> |
| | |
| | | <value>192.168.11.99</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PGDDATBASE</key> |
| | | <key>PGDATBASE</key> |
| | | <value>pgNSTPC</value> |
| | | </entry> |
| | | <entry> |
| | |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTFILE</key> |
| | | <value>true</value> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>CONVERTELEMIN</key> |
| | |
| | | </entry> |
| | | <entry> |
| | | <key>COPYCONNECTIVITYMODE</key> |
| | | <value>true</value> |
| | | <value>false</value> |
| | | </entry> |
| | | <entry> |
| | | <key>PROFILEMODE</key> |
New file |
| | |
| | | <?xml version='1.0' encoding='utf-8'?>
|
| | |
|
| | | <job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
|
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| | | xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
|
| | | version="1.8">
|
| | |
|
| | | <pre-processing-commands>
|
| | | <delete-jobs-in-group>*</delete-jobs-in-group>
|
| | | <!-- clear all jobs in scheduler -->
|
| | | <delete-triggers-in-group>*</delete-triggers-in-group>
|
| | | <!-- clear all triggers in scheduler -->
|
| | | </pre-processing-commands>
|
| | |
|
| | | <processing-directives>
|
| | | <!-- if there are any jobs/trigger in scheduler of same name (as in this file), overwrite them -->
|
| | | <overwrite-existing-data>true</overwrite-existing-data>
|
| | | <!-- if there are any jobs/trigger in scheduler of same name (as in this file), and over-write is false, ignore them rather then generating an error -->
|
| | | <ignore-duplicates>false</ignore-duplicates>
|
| | | </processing-directives>
|
| | |
|
| | | <schedule>
|
| | | <job>
|
| | | <name>ConvertDgn2GeoSpatialIntoEdb</name>
|
| | | <group>DEFAULT</group>
|
| | | <description>A job that convert dgn to gdb spatial</description>
|
| | | <job-class>com.ximple.eofms.jobs.OracleConvertDgn2EdbGeoJob</job-class>
|
| | | <volatility>false</volatility>
|
| | | <durability>false</durability>
|
| | | <recover>false</recover>
|
| | | <!--job-data-map allows-transient-data="true"-->
|
| | | <job-data-map>
|
| | | <entry>
|
| | | <key>JOBDATA_DIR</key>
|
| | | <value>C:\Usr\Projects\XDCAD\nstpcjobs</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBHOST</key>
|
| | | <value>192.168.11.99</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBDATBASE</key>
|
| | | <value>tpcdb</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBPORT</key>
|
| | | <value>5444</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBSCHEMA</key>
|
| | | <value>public</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBUSER</key>
|
| | | <value>tpcdb</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>EDBPASS</key>
|
| | | <value>simple000</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORAHOST</key>
|
| | | <value>192.168.11.200</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORAINST</key>
|
| | | <value>nntpc</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORAPORT</key>
|
| | | <value>1521</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORAUSER</key>
|
| | | <value>spatialdb</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORAPASS</key>
|
| | | <value>spatialdb000</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ORGSCHEMA</key>
|
| | | <value>SPATIALDB, CMMS_SPATIALDB</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>CONVERTDB</key>
|
| | | <value>true</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>CONVERTFILE</key>
|
| | | <value>false</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>CONVERTELEMIN</key>
|
| | | <value>false</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>CREATEDUMMY</key>
|
| | | <value>false</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>ELEMLOG</key>
|
| | | <value>true</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>USEWKB</key>
|
| | | <value>true</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>TESTMODE</key>
|
| | | <value>false</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>TESTCOUNT</key>
|
| | | <value>2</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>COPYCONNECTIVITYMODE</key>
|
| | | <value>false</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>PROFILEMODE</key>
|
| | | <value>true</value>
|
| | | </entry>
|
| | | <entry>
|
| | | <key>USEZONE121</key>
|
| | | <value>true</value>
|
| | | </entry>
|
| | | </job-data-map>
|
| | | </job>
|
| | |
|
| | | <trigger>
|
| | | <simple>
|
| | | <name>convertTrigger</name>
|
| | | <group>DEFAULT</group>
|
| | | <job-name>ConvertDgn2GeoSpatialIntoEdb</job-name>
|
| | | <job-group>DEFAULT</job-group>
|
| | | <start-time>2008-03-01T18:10:00</start-time>
|
| | | <!-- repeat indefinitely every 10 seconds -->
|
| | | <repeat-count>0</repeat-count>
|
| | | <repeat-interval>500</repeat-interval>
|
| | | <!-- <repeat-interval>72000000</repeat-interval> -->
|
| | | </simple>
|
| | | </trigger>
|
| | |
|
| | | </schedule>
|
| | | </job-scheduling-data>
|
| | |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.ximple.eofms</groupId> |
| | | <artifactId>xedb-gt-geospatial</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | | <artifactId>mysql-connector-java</artifactId> |
| | | </dependency> |
| | |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createMultiLineString(new LineString[]{(LineString) gobj}); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = ellipseElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createLineString(coordinateList.toCoordinateArray()); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = lineElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = arcElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = lineStringElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | |
| | | txtElement.getRotationAngle(); |
| | | |
| | | line.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | line, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = geometryFactory.createLineString(coordinateList.toCoordinateArray()); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | } else { |
| | | gobj = lineElement.toGeometry(geometryFactory); |
| | | } |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | } |
| | | |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | } |
| | | |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = complexShape.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = txtElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
| | |
| | | gobj = nodeElement.toGeometry(geometryFactory); |
| | | } |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | fLinkage.getFsc(), |
New file |
| | |
| | | package com.ximple.eofms.jobs;
|
| | |
|
| | | import com.ximple.eofms.jobs.context.AbstractOracleJobContext;
|
| | | import com.ximple.eofms.jobs.context.edbgeo.FeatureDgnConvertEdbGeoJobContext;
|
| | | import com.ximple.eofms.jobs.context.edbgeo.GeneralDgnConvertEdbGeoJobContext;
|
| | | import com.ximple.eofms.jobs.context.edbgeo.IndexDgnConvertEdbGeoJobContext;
|
| | | import com.ximple.eofms.jobs.context.edbgeo.OracleConvertEdbGeoJobContext;
|
| | | import com.ximple.eofms.util.BinConverter;
|
| | | import com.ximple.eofms.util.ByteArrayCompressor;
|
| | | import com.ximple.eofms.util.FileUtils;
|
| | | import com.ximple.eofms.util.StringUtils;
|
| | | import com.ximple.io.dgn7.ComplexElement;
|
| | | import com.ximple.io.dgn7.Dgn7fileException;
|
| | | import com.ximple.io.dgn7.Dgn7fileReader;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.ElementType;
|
| | | import com.ximple.io.dgn7.IElementHandler;
|
| | | import com.ximple.io.dgn7.Lock;
|
| | | import com.ximple.util.PrintfFormat;
|
| | | import oracle.jdbc.OracleConnection;
|
| | | import oracle.jdbc.OracleResultSet;
|
| | | import oracle.sql.ARRAY;
|
| | | import oracle.sql.BLOB;
|
| | | import org.apache.commons.collections.OrderedMap;
|
| | | import org.apache.commons.collections.OrderedMapIterator;
|
| | | import org.apache.commons.collections.map.LinkedMap;
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.data.jdbc.JDBCUtils;
|
| | | import org.geotools.data.edbgeo.PostgisDataStore;
|
| | | import org.geotools.data.edbgeo.PostgisDataStoreFactory;
|
| | | import org.geotools.feature.IllegalAttributeException;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.quartz.JobDataMap;
|
| | | import org.quartz.JobDetail;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.quartz.JobExecutionException;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileFilter;
|
| | | import java.io.FileInputStream;
|
| | | import java.io.FileNotFoundException;
|
| | | import java.io.FilenameFilter;
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.nio.BufferOverflowException;
|
| | | import java.nio.ByteBuffer;
|
| | | import java.nio.ByteOrder;
|
| | | import java.nio.channels.FileChannel;
|
| | | import java.sql.Connection;
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.sql.Types;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.TreeMap;
|
| | |
|
| | | public class OracleConvertDgn2EdbGeoJob extends AbstractOracleDatabaseJob {
|
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2EdbGeoJob.class);
|
| | |
|
| | | private static final String EDBHOST = "EDBHOST";
|
| | | private static final String EDBDATBASE = "EDBDATBASE";
|
| | | private static final String EDBPORT = "EDBPORT";
|
| | | private static final String EDBSCHEMA = "EDBSCHEMA";
|
| | | private static final String EDBUSER = "EDBUSER";
|
| | | private static final String EDBPASS = "EDBPASS";
|
| | | private static final String USEWKB = "USEWKB";
|
| | |
|
| | | private static final boolean useTpclidText = false;
|
| | |
|
| | | private static final int FETCHSIZE = 30;
|
| | | private static final int COMMITSIZE = 100;
|
| | | private static final String INDEXPATHNAME = "index";
|
| | | private static final String OTHERPATHNAME = "other";
|
| | |
|
| | | protected static class Pair {
|
| | | Object first;
|
| | | Object second;
|
| | |
|
| | | public Pair(Object first, Object second) {
|
| | | this.first = first;
|
| | | this.second = second;
|
| | | }
|
| | | }
|
| | |
|
| | | protected static PostgisDataStoreFactory dataStoreFactory = new PostgisDataStoreFactory();
|
| | |
|
| | | protected String _edbHost;
|
| | | protected String _edbDatabase;
|
| | | protected String _edbPort;
|
| | | protected String _edbSchema;
|
| | | protected String _edbUsername;
|
| | | protected String _edbPassword;
|
| | | protected String _edbUseWKB;
|
| | |
|
| | | protected Map<String, String> edbProperties;
|
| | | protected PostgisDataStore targetDataStore;
|
| | | // protected OracleConvertEdbGeoJobContext oracleJobContext;
|
| | |
|
| | | private long queryTime = 0;
|
| | | private long queryTimeStart = 0;
|
| | |
|
| | | public Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | |
|
| | | protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath,
|
| | | boolean profileMode,
|
| | | boolean useTransform) {
|
| | | return new OracleConvertEdbGeoJobContext(getDataPath(),
|
| | | getTargetDataStore(), targetSchemaName, filterPath, profileMode, useTransform);
|
| | | }
|
| | |
|
| | | protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException {
|
| | | super.extractJobConfiguration(jobDetail);
|
| | | JobDataMap dataMap = jobDetail.getJobDataMap();
|
| | | _edbHost = dataMap.getString(EDBHOST);
|
| | | _edbDatabase = dataMap.getString(EDBDATBASE);
|
| | | _edbPort = dataMap.getString(EDBPORT);
|
| | | _edbSchema = dataMap.getString(EDBSCHEMA);
|
| | | _edbUsername = dataMap.getString(EDBUSER);
|
| | | _edbPassword = dataMap.getString(EDBPASS);
|
| | | _edbUseWKB = dataMap.getString(USEWKB);
|
| | |
|
| | | Log logger = getLogger();
|
| | | /*
|
| | | logger.info("EDBHOST=" + _myHost);
|
| | | logger.info("EDBDATBASE=" + _myDatabase);
|
| | | logger.info("EDBPORT=" + _myPort);
|
| | | logger.info("EDBSCHEMA=" + _mySchema);
|
| | | logger.info("EDBUSER=" + _myUsername);
|
| | | logger.info("EDBPASS=" + _myPassword);
|
| | | logger.info("USEWKB=" + _myUseWKB);
|
| | | */
|
| | |
|
| | | if (_edbHost == null) {
|
| | | logger.warn("EDBHOST is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial host.");
|
| | | }
|
| | | if (_edbDatabase == null) {
|
| | | logger.warn("PGDATABASE is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial database.");
|
| | | }
|
| | | if (_edbPort == null) {
|
| | | logger.warn("EDBPORT is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial port.");
|
| | | }
|
| | | if (_edbSchema == null) {
|
| | | logger.warn("EDBSCHEMA is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial schema.");
|
| | | }
|
| | | if (_edbUsername == null) {
|
| | | logger.warn("PGUSERNAME is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial username.");
|
| | | }
|
| | | if (_edbPassword == null) {
|
| | | logger.warn("PGPASSWORD is null");
|
| | | throw new JobExecutionException("Unknown EdbGeoSpatial password.");
|
| | | }
|
| | |
|
| | | Map<String, String> remote = new TreeMap<String, String>();
|
| | | remote.put("dbtype", "edbgeo");
|
| | | remote.put("charset", "UTF-8");
|
| | | remote.put("host", _edbHost);
|
| | | remote.put("port", _edbPort);
|
| | | remote.put("database", _edbDatabase);
|
| | | remote.put("user", _edbUsername);
|
| | | remote.put("passwd", _edbPassword);
|
| | | remote.put("namespace", null);
|
| | | edbProperties = remote;
|
| | | }
|
| | |
|
| | | public void execute(JobExecutionContext context) throws JobExecutionException {
|
| | | // Every job has its own job detail
|
| | | JobDetail jobDetail = context.getJobDetail();
|
| | |
|
| | | // The name is defined in the job definition
|
| | | String jobName = jobDetail.getName();
|
| | |
|
| | | // Log the time the job started
|
| | | logger.info(jobName + " fired at " + new Date());
|
| | | extractJobConfiguration(jobDetail);
|
| | | createSourceDataStore();
|
| | | createTargetDataStore();
|
| | | if (getSourceDataStore() == null) {
|
| | | logger.warn("Cannot connect source oracle database.");
|
| | | throw new JobExecutionException("Cannot connect source oracle database.");
|
| | | }
|
| | |
|
| | | if (getTargetDataStore() == null) {
|
| | | logger.warn("Cannot connect source postgreSQL database.");
|
| | | throw new JobExecutionException("Cannot connect source postgreSQL database.");
|
| | | }
|
| | |
|
| | | if (isProfileMode()) {
|
| | | queryTime = 0;
|
| | | }
|
| | |
|
| | | long t1 = System.currentTimeMillis();
|
| | | String targetSchemaName;
|
| | | try {
|
| | | logger.info("-- step:clearOutputDatabase --");
|
| | | clearOutputDatabase();
|
| | | targetSchemaName = determineTargetSchemaName();
|
| | |
|
| | | if (checkConvertFile()) {
|
| | | logger.info("-- step:convertIndexDesignFile --");
|
| | | long tStep = System.currentTimeMillis();
|
| | | convertIndexDesignFile(context, targetSchemaName);
|
| | | if (isProfileMode()) {
|
| | | long tStepEnd = System.currentTimeMillis();
|
| | | logTimeDiff("Profile-convertIndexDesignFile", tStep, tStepEnd);
|
| | | }
|
| | |
|
| | | logger.info("-- step:convertOtherDesignFile --");
|
| | | tStep = System.currentTimeMillis();
|
| | | convertOtherDesignFile(context, targetSchemaName);
|
| | | if (isProfileMode()) {
|
| | | long tStepEnd = System.currentTimeMillis();
|
| | | logTimeDiff("Profile-convertOtherDesignFile", tStep, tStepEnd);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | if (checkConvertDB()) {
|
| | | logger.info("-- step:convertOracleDB --");
|
| | |
|
| | | OracleConvertEdbGeoJobContext jobContext =
|
| | | (OracleConvertEdbGeoJobContext) prepareJobContext(targetSchemaName, _filterPath,
|
| | | isProfileMode(), isTransformed());
|
| | | jobContext.setSourceDataStore(getSourceDataStore());
|
| | | // jobContext.setConvertElementIn(_convertElementIn);
|
| | | jobContext.setElementLogging(checkElementLogging());
|
| | | jobContext.setExecutionContext(context);
|
| | |
|
| | | createHibernateSequence(jobContext);
|
| | |
|
| | | long tStep = System.currentTimeMillis();
|
| | |
|
| | | if (isCopyConnectivityMode())
|
| | | {
|
| | | copyConnectivity(jobContext);
|
| | | }
|
| | |
|
| | | if (isProfileMode()) {
|
| | | long tStepEnd = System.currentTimeMillis();
|
| | | logTimeDiff("Profile-Copy Connectivity", tStep, tStepEnd);
|
| | | }
|
| | |
|
| | | for (String orgSchema : _orgSchema) {
|
| | | logger.info("----- start schema:" + orgSchema + " -----");
|
| | | if (isProfileMode()) {
|
| | | jobContext.resetProcessTime();
|
| | | jobContext.resetUpdateTime();
|
| | | }
|
| | | tStep = System.currentTimeMillis();
|
| | | exetcuteConvert(jobContext, orgSchema, _dataPath);
|
| | |
|
| | | //close all open filewriter instance
|
| | | jobContext.closeFeatureWriter();
|
| | |
|
| | | if (isProfileMode()) {
|
| | | logger.warn("Profile-Current Query Oracle Cost-" +
|
| | | ((int) ((getQueryTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((getQueryTime()) % 60000.0)) / 1000) + " sec");
|
| | | long tStepEnd = System.currentTimeMillis();
|
| | | logger.warn("Profile-Current Process Cost-" +
|
| | | ((int) ((getProcessTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((getProcessTime()) % 60000.0)) / 1000) + " sec");
|
| | | logger.warn("Profile-Current Update Cost-" +
|
| | | ((int) ((getUpdateTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((getUpdateTime()) % 60000.0)) / 1000) + " sec");
|
| | | logger.warn("Profile-Current JobContext Process Cost-" +
|
| | | ((int) ((jobContext.getProcessTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((jobContext.getProcessTime()) % 60000.0)) / 1000) + " sec");
|
| | | logger.warn("Profile-Current JobContext Update Cost-" +
|
| | | ((int) ((jobContext.getUpdateTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((jobContext.getUpdateTime()) % 60000.0)) / 1000) + " sec");
|
| | | logTimeDiff("Profile-Convert[" + orgSchema + "]", tStep, tStepEnd);
|
| | |
|
| | | resetQueryTime();
|
| | | resetProcessTime();
|
| | | resetUpdateTime();
|
| | | }
|
| | | }
|
| | |
|
| | | jobContext.closeOracleConnection();
|
| | | }
|
| | |
|
| | | if (checkConvertElementIn()) {
|
| | | logger.info("-- step:convertFeatureDesignFile --");
|
| | | long tStep = System.currentTimeMillis();
|
| | | convertFeatureDesignFile(context, targetSchemaName);
|
| | | if (isProfileMode()) {
|
| | | long tStepEnd = System.currentTimeMillis();
|
| | | logTimeDiff("Profile-convertFeatureDesignFile", tStep, tStepEnd);
|
| | | }
|
| | | }
|
| | |
|
| | | if (checkCreateDummy()) {
|
| | | logger.info("-- step:createDummyFeatureFile --");
|
| | | createDummyFeatureFile(context);
|
| | | }
|
| | |
|
| | | long t2 = System.currentTimeMillis();
|
| | | // public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
|
| | | // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
|
| | | logTimeDiff("Total ", t1, t2);
|
| | |
|
| | | updateRepoStatusToReady(targetSchemaName);
|
| | |
|
| | | } catch (SQLException e) {
|
| | | disconnect();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException("Database error. " + e.getMessage(), e);
|
| | | } catch (IOException ex) {
|
| | | disconnect();
|
| | | logger.warn(ex.getMessage(), ex);
|
| | | throw new JobExecutionException("IO error. " + ex.getMessage(), ex);
|
| | | } finally {
|
| | | disconnect();
|
| | | }
|
| | | logger.warn(jobName + " end at " + new Date());
|
| | | }
|
| | |
|
| | | private void logTimeDiff(String message, long tBefore, long tCurrent) {
|
| | | logger.warn(message + ":use time = " + ((int) ((tCurrent - tBefore) / 60000.0)) + " min - " +
|
| | | (((int) ((tCurrent - tBefore) % 60000.0)) / 1000) + " sec");
|
| | | }
|
| | |
|
| | | /**
|
| | | * Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity)
|
| | | *
|
| | | * @param jobContext job context
|
| | | * @throws SQLException sql exception
|
| | | */
|
| | | private void copyConnectivity(OracleConvertEdbGeoJobContext jobContext) throws SQLException {
|
| | | Connection connection = jobContext.getOracleConnection();
|
| | | ResultSet rsMeta = connection.getMetaData().getTables(null, "BASEDB",
|
| | | AbstractOracleJobContext.CONNECTIVITY_WEBCHECK_NAME + "%",
|
| | | new String[]{"TABLE"});
|
| | |
|
| | | boolean found = false;
|
| | | try {
|
| | | while (rsMeta.next()) {
|
| | | String tablename = rsMeta.getString(3);
|
| | | if (AbstractOracleJobContext.CONNECTIVITY_WEBCHECK_NAME.equalsIgnoreCase(tablename)) {
|
| | | found = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | // } catch (SQLException e)
|
| | | } finally {
|
| | | if (rsMeta != null) {
|
| | | rsMeta.close();
|
| | | rsMeta = null;
|
| | | }
|
| | | }
|
| | | Statement stmt = connection.createStatement();
|
| | | if (found) {
|
| | | stmt.execute(AbstractOracleJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK);
|
| | | } else {
|
| | | logger.info("Create CONNECTIVITY_WEBCHECK table.");
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_1);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_2);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_3);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_4);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_5);
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_CONNECTIVITY_WEBCHECK_INDEX_6);
|
| | | stmt.execute(AbstractOracleJobContext.ALTER_CONNECTIVITY_WEBCHECK_1);
|
| | | stmt.execute(AbstractOracleJobContext.ALTER_CONNECTIVITY_WEBCHECK_2);
|
| | | }
|
| | |
|
| | | stmt.execute(AbstractOracleJobContext.COPY_CONNECTIVITY_TO_WEBCHECK);
|
| | | stmt.close();
|
| | | }
|
| | |
|
| | |
|
| | | private void createHibernateSequence(OracleConvertEdbGeoJobContext jobContext) throws SQLException {
|
| | | Connection connection = jobContext.getOracleConnection();
|
| | |
|
| | | try {
|
| | | Statement stmt = connection.createStatement();
|
| | | stmt.execute(AbstractOracleJobContext.CREATE_HIBERNATE_SEQUENCE);
|
| | | stmt.close();
|
| | | } catch (SQLException e)
|
| | | {
|
| | | logger.warn("HIBERNATE_SEQUENCE is already exist.");
|
| | | }
|
| | | }
|
| | |
|
| | | private void exetcuteConvert(OracleConvertEdbGeoJobContext jobContext,
|
| | | String querySchema, String targetSchemaName) throws SQLException {
|
| | | int order = 0;
|
| | | OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(),
|
| | | querySchema, "SD$SPACENODES", null);
|
| | |
|
| | | logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode);
|
| | |
|
| | | int total = map.size(); //spacenodes count
|
| | | int step = total / 100;
|
| | | int current = 0;
|
| | |
|
| | | if (total == 0) {
|
| | | logger.warn("SELECT COUNT FROM " + querySchema + ".SD$SPACENODES is zero.");
|
| | | return;
|
| | | }
|
| | | logger.warn("SELECT COUNT FROM " + querySchema + ".SD$SPACENODES is " + map.size() );
|
| | |
|
| | | //jobContext.startTransaction();
|
| | | jobContext.setCurrentSchema(querySchema);
|
| | | jobContext.getExecutionContext().put("ConvertDgn2EdbGeoJobProgress", 0);
|
| | | for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) {
|
| | | it.next();
|
| | |
|
| | | Pair pair = (Pair) it.getValue();
|
| | | String tableSrc = (String) pair.first;
|
| | |
|
| | | logger.info("begin convert:[" + order + "]-" + tableSrc);
|
| | | queryIgsetElement(jobContext, querySchema, tableSrc);
|
| | |
|
| | |
|
| | | order++;
|
| | |
|
| | | if (_testMode) {
|
| | | if ((_testCount < 0) || (order >= _testCount))
|
| | | break;
|
| | | }
|
| | |
|
| | | if ((order % COMMITSIZE) == 0) {
|
| | | // OracleConnection connection = jobContext.getOracleConnection();
|
| | | // connection.commitTransaction();
|
| | | jobContext.commitTransaction();
|
| | | //jobContext.startTransaction();
|
| | | System.gc();
|
| | | System.runFinalization();
|
| | | }
|
| | |
|
| | | if( step != 0)
|
| | | {
|
| | | int now = order % step;
|
| | | if (now != current) {
|
| | | current = now;
|
| | | jobContext.getExecutionContext().put("ConvertDgn2EdbGeoSpatialJob", current);
|
| | |
|
| | | }
|
| | | }else
|
| | | {
|
| | | jobContext.getExecutionContext().put("ConvertDgn2EdbGeoSpatialJob", current);
|
| | | current++;
|
| | | }
|
| | | }
|
| | | jobContext.getExecutionContext().put("ConvertDgn2EdbGeoSpatialJob", 100);
|
| | |
|
| | | jobContext.commitTransaction();
|
| | | jobContext.resetFeatureContext();
|
| | |
|
| | | if (isProfileMode()) {
|
| | |
|
| | | }
|
| | |
|
| | | logger.info("end convert job:[" + order + "]");
|
| | | System.gc();
|
| | | System.runFinalization();
|
| | | }
|
| | |
|
| | | protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc,
|
| | | OrderedMap orderedMap) throws SQLException {
|
| | | if (orderedMap == null)
|
| | | orderedMap = new LinkedMap(99);
|
| | | String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\"";
|
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt);
|
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc});
|
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
| | | ResultSet rs = null;
|
| | |
|
| | | stmt.setFetchSize(FETCHSIZE);
|
| | | try {
|
| | | rs = stmt.executeQuery(fetchStmt);
|
| | | int size = rs.getMetaData().getColumnCount();
|
| | |
|
| | | while (rs.next()) {
|
| | | Object[] values = new Object[size];
|
| | |
|
| | | for (int i = 0; i < size; i++) {
|
| | | values[i] = rs.getObject(i + 1);
|
| | | }
|
| | |
|
| | | Integer key = ((BigDecimal) values[0]).intValue();
|
| | | String name = (String) values[1];
|
| | |
|
| | | Pair pair = (Pair) orderedMap.get(key);
|
| | | if (pair == null)
|
| | | orderedMap.put(key, new Pair(name, null));
|
| | | else
|
| | | pair.first = name;
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | logger.error(e.toString(), e);
|
| | | logger.error("stmt=" + fetchStmt);
|
| | | throw e;
|
| | | } finally {
|
| | | JDBCUtils.close(rs);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | |
|
| | | return orderedMap;
|
| | | }
|
| | |
|
| | | protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc,
|
| | | OrderedMap orderedMap) throws SQLException {
|
| | | if (orderedMap == null)
|
| | | orderedMap = new LinkedMap(99);
|
| | | String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\"";
|
| | | PrintfFormat spf = new PrintfFormat(fetchStmtFmt);
|
| | | String fetchStmt = spf.sprintf(new Object[]{schemaSrc, tableSrc});
|
| | | Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
| | |
|
| | | stmt.setFetchSize(FETCHSIZE);
|
| | | ResultSet rs = stmt.executeQuery(fetchStmt);
|
| | | try {
|
| | | int size = rs.getMetaData().getColumnCount();
|
| | | while (rs.next()) {
|
| | | Object[] values = new Object[size];
|
| | |
|
| | | for (int i = 0; i < size; i++) {
|
| | | values[i] = rs.getObject(i + 1);
|
| | | }
|
| | |
|
| | | Integer key = ((BigDecimal) values[0]).intValue();
|
| | | String name = (String) values[1];
|
| | |
|
| | | Pair pair = (Pair) orderedMap.get(key);
|
| | | if (pair == null)
|
| | | orderedMap.put(key, new Pair(null, name));
|
| | | else
|
| | | pair.second = name;
|
| | | }
|
| | | } finally {
|
| | | JDBCUtils.close(rs);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | return orderedMap;
|
| | | }
|
| | |
|
| | | protected void queryIgsetElement(OracleConvertEdbGeoJobContext jobContext,
|
| | | String srcschema, String srctable) throws SQLException {
|
| | | Connection connection = jobContext.getOracleConnection();
|
| | | String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID";
|
| | | //String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" WHERE TAG_SFSC = 423 AND TAG_LUFID = 21612065 ORDER BY ROWID";
|
| | | PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt);
|
| | | String fetchSrcStmt = spf.sprintf(new Object[]{srcschema, srctable});
|
| | | Statement stmtSrc = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
| | |
|
| | | stmtSrc.setFetchSize(FETCHSIZE);
|
| | | ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt);
|
| | | int igdsMetaType = rsSrc.getMetaData().getColumnType(1);
|
| | | while (rsSrc.next()) {
|
| | | if (isProfileMode()) {
|
| | | markQueryTime();
|
| | | }
|
| | |
|
| | | byte[] raw = null;
|
| | | if (igdsMetaType == Types.BLOB) {
|
| | | BLOB blob = (BLOB) rsSrc.getBlob(1);
|
| | |
|
| | | try {
|
| | | raw = getBytesFromBLOB(blob);
|
| | | } catch (BufferOverflowException e) {
|
| | | logger.warn("Wrong Element Structure-", e);
|
| | | } finally {
|
| | | // blob.close();
|
| | | }
|
| | | } else {
|
| | | raw = rsSrc.getBytes(1);
|
| | | }
|
| | |
|
| | | try {
|
| | | if (raw != null) {
|
| | | Element element = fetchBinaryElement(raw);
|
| | | if (isProfileMode()) {
|
| | | accumulateQueryTime();
|
| | | }
|
| | | jobContext.putFeatureCollection(element);
|
| | | } else {
|
| | | if (isProfileMode()) {
|
| | | accumulateQueryTime();
|
| | | }
|
| | | }
|
| | | } catch (Dgn7fileException e) {
|
| | | logger.warn("Dgn7Exception", e);
|
| | | }
|
| | | }
|
| | |
|
| | | JDBCUtils.close(rsSrc);
|
| | | JDBCUtils.close(stmtSrc);
|
| | | }
|
| | |
|
| | | protected void queryRawElement(OracleConvertEdbGeoJobContext jobContext,
|
| | | String srcschema, String srctable) throws SQLException {
|
| | | Connection connection = jobContext.getOracleConnection();
|
| | | String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID";
|
| | | PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt);
|
| | | String fetchDestStmt = spf.sprintf(new Object[]{srcschema, srctable});
|
| | | Statement stmtDest = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
| | |
|
| | | stmtDest.setFetchSize(FETCHSIZE);
|
| | | ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt);
|
| | |
|
| | | try {
|
| | | while (rsDest.next()) {
|
| | | ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1);
|
| | | long[] rawData = rawsValue.getLongArray();
|
| | | byte[] comparessedValue;
|
| | |
|
| | | /*
|
| | | if (dataMode == TransferTask.DataMode.Normal)
|
| | | {
|
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true);
|
| | | } else
|
| | | {
|
| | | comparessedValue = BinConverter.unmarshalCompactByteArray(rawData);
|
| | | }
|
| | | */
|
| | | comparessedValue = BinConverter.unmarshalByteArray(rawData, true);
|
| | |
|
| | | byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue);
|
| | |
|
| | | try {
|
| | | Element element = fetchBinaryElement(rawDest);
|
| | | jobContext.putFeatureCollection(element);
|
| | | } catch (Dgn7fileException e) {
|
| | | logger.warn("Dgn7Exception:" + e.getMessage(), e);
|
| | | }
|
| | | }
|
| | | } finally {
|
| | | JDBCUtils.close(rsDest);
|
| | | JDBCUtils.close(stmtDest);
|
| | | }
|
| | | }
|
| | |
|
| | | // Binary to Element
|
| | | private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException {
|
| | | ByteBuffer buffer = ByteBuffer.wrap(raws);
|
| | | buffer.order(ByteOrder.LITTLE_ENDIAN);
|
| | | short signature = buffer.getShort();
|
| | |
|
| | | // byte type = (byte) (buffer.get() & 0x7f);
|
| | | byte type = (byte) ((signature >>> 8) & 0x007f);
|
| | |
|
| | | // silly Bentley say contentLength is in 2-byte words
|
| | | // and ByteByffer uses raws.
|
| | | // track the record location
|
| | | int elementLength = (buffer.getShort() * 2) + 4;
|
| | | ElementType recordType = ElementType.forID(type);
|
| | | IElementHandler handler;
|
| | |
|
| | | handler = recordType.getElementHandler();
|
| | |
|
| | | Element dgnElement = (Element) handler.read(buffer, signature, elementLength);
|
| | | if (recordType.isComplexElement() && (elementLength < raws.length)) {
|
| | | int offset = elementLength;
|
| | | while (offset < (raws.length - 4)) {
|
| | | buffer.position(offset);
|
| | | signature = buffer.getShort();
|
| | | type = (byte) ((signature >>> 8) & 0x007f);
|
| | | elementLength = (buffer.getShort() * 2) + 4;
|
| | | if (raws.length < (offset + elementLength)) {
|
| | | logger.debug("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit());
|
| | | break;
|
| | | }
|
| | | recordType = ElementType.forID(type);
|
| | | handler = recordType.getElementHandler();
|
| | | if (handler != null) {
|
| | | Element subElement = (Element) handler.read(buffer, signature, elementLength);
|
| | | ((ComplexElement) dgnElement).add(subElement);
|
| | | offset += elementLength;
|
| | | } else {
|
| | | byte[] remain = new byte[buffer.remaining()];
|
| | | System.arraycopy(raws, offset, remain, 0, buffer.remaining());
|
| | | for (int i = 0; i < remain.length; i++) {
|
| | | if (remain[i] != 0) {
|
| | | logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]);
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return dgnElement;
|
| | | }
|
| | |
|
| | | /**
|
| | | * �����ഫ�����ɪ��u�@
|
| | | *
|
| | | * @param context �u�@��������
|
| | | * @throws org.quartz.JobExecutionException
|
| | | * exception
|
| | | */
|
| | | private void convertIndexDesignFile(JobExecutionContext context, String targetSchemaName) throws JobExecutionException {
|
| | | File indexDir = new File(getDataPath(), INDEXPATHNAME);
|
| | | if (!indexDir.exists()) {
|
| | | logger.info("index dir=" + indexDir + " not exist.");
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!indexDir.isDirectory()) {
|
| | | logger.info("index dir=" + indexDir + " is not a directory.");
|
| | | }
|
| | |
|
| | | List<File> dgnFiles = FileUtils.recurseDir(indexDir, new FileFilter() {
|
| | | public boolean accept(File pathname) {
|
| | | return pathname.isDirectory() || pathname.getName().toLowerCase().endsWith("dgn");
|
| | | }
|
| | | });
|
| | |
|
| | | for (File dgnFile : dgnFiles) {
|
| | | if (dgnFile.isDirectory()) continue;
|
| | | IndexDgnConvertEdbGeoJobContext convertContext =
|
| | | new IndexDgnConvertEdbGeoJobContext(getDataPath(), getTargetDataStore(), targetSchemaName,
|
| | | isProfileMode(), isTransformed());
|
| | | logger.info("--- start index dgnfile-" + dgnFile.toString() + " ---");
|
| | | FileInputStream fs = null;
|
| | | FileChannel fc = null;
|
| | | Dgn7fileReader reader = null;
|
| | | try {
|
| | | convertContext.clearOutputDatabase();
|
| | | convertContext.setExecutionContext(context);
|
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator);
|
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]);
|
| | | convertContext.startTransaction();
|
| | |
|
| | | fs = new FileInputStream(dgnFile);
|
| | | fc = fs.getChannel();
|
| | | reader = new Dgn7fileReader(fc, new Lock());
|
| | | convertContext.setReader(reader);
|
| | |
|
| | | scanIndexDgnElement(convertContext);
|
| | |
|
| | | convertContext.commitTransaction();
|
| | | convertContext.closeFeatureWriter();
|
| | |
|
| | | System.gc();
|
| | | System.runFinalization();
|
| | | } catch (FileNotFoundException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (Dgn7fileException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IllegalAttributeException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (SchemaException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } finally {
|
| | | convertContext.closeFeatureWriter();
|
| | |
|
| | | if (reader != null)
|
| | | {
|
| | | try {
|
| | | reader.close();
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | if (fs != null) {
|
| | | try {
|
| | | fs.close();
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | if (isProfileMode()) {
|
| | | logger.warn("Profile-Current convertContext Process Cost-" +
|
| | | ((int) ((convertContext.getProcessTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((convertContext.getProcessTime()) % 60000.0)) / 1000) + " sec");
|
| | | logger.warn("Profile-Current convertContext Update Cost-" +
|
| | | ((int) ((convertContext.getUpdateTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((convertContext.getUpdateTime()) % 60000.0)) / 1000) + " sec");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | protected void scanIndexDgnElement(IndexDgnConvertEdbGeoJobContext convertContext)
|
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException {
|
| | | Dgn7fileReader reader = convertContext.getReader();
|
| | | int count = 0;
|
| | | Element lastComplex = null;
|
| | |
|
| | | while (reader.hasNext()) {
|
| | | if (isProfileMode()) markProcessTime();
|
| | | Element.FileRecord record = reader.nextElement();
|
| | | if (record.element() != null) {
|
| | | Element element = (Element) record.element();
|
| | | ElementType type = element.getElementType();
|
| | |
|
| | | if ((!type.isComplexElement()) && (!element.isComponentElement())) {
|
| | | if (lastComplex != null) {
|
| | | processIndexElement(lastComplex, convertContext);
|
| | | lastComplex = null;
|
| | | }
|
| | |
|
| | | processIndexElement(element, convertContext);
|
| | | } else if (element.isComponentElement()) {
|
| | | if (lastComplex != null) {
|
| | | ((ComplexElement) lastComplex).add(element);
|
| | | }
|
| | | } else if (type.isComplexElement()) {
|
| | | if (lastComplex != null) {
|
| | | processIndexElement(lastComplex, convertContext);
|
| | | }
|
| | | lastComplex = element;
|
| | | }
|
| | | }
|
| | | count++;
|
| | | }
|
| | |
|
| | | if (lastComplex != null) {
|
| | | processIndexElement(lastComplex, convertContext);
|
| | | }
|
| | | logger.debug("ElementRecord Count=" + count);
|
| | | }
|
| | |
|
| | | private void processIndexElement(Element element, IndexDgnConvertEdbGeoJobContext convertContext)
|
| | | throws IllegalAttributeException, SchemaException {
|
| | | //if (useTpclidText) {
|
| | | // if (element instanceof TextElement) {
|
| | | // convertContext.putFeatureCollection(element);
|
| | | // }
|
| | | //} else {
|
| | | // if (element instanceof ShapeElement) {
|
| | | convertContext.putFeatureCollection(element);
|
| | | // }
|
| | | //}
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * �����ഫ��L�]�p���ɪ��u�@
|
| | | *
|
| | | * @param context jobContext
|
| | | * @throws org.quartz.JobExecutionException
|
| | | * exception
|
| | | */
|
| | | private void convertOtherDesignFile(JobExecutionContext context, String targetSchemaName) throws JobExecutionException {
|
| | | File otherDir = new File(getDataPath(), OTHERPATHNAME);
|
| | | if (!otherDir.exists()) {
|
| | | logger.info("other dir=" + otherDir + " not exist.");
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!otherDir.isDirectory()) {
|
| | | logger.info("other dir=" + otherDir + " is not a directory.");
|
| | | }
|
| | |
|
| | | List<File> dgnFiles = FileUtils.recurseDir(otherDir, new FileFilter() {
|
| | | public boolean accept(File pathname) {
|
| | | return pathname.isDirectory() || pathname.getName().toLowerCase().endsWith("dgn");
|
| | | }
|
| | | });
|
| | |
|
| | | for (File dgnFile : dgnFiles) {
|
| | | if (dgnFile.isDirectory()) continue;
|
| | |
|
| | | GeneralDgnConvertEdbGeoJobContext convertContext =
|
| | | new GeneralDgnConvertEdbGeoJobContext(getDataPath(), getTargetDataStore(), targetSchemaName,
|
| | | isProfileMode(), isTransformed());
|
| | | logger.info("--- start other dgnfile-" + dgnFile.toString() + " ---");
|
| | | FileInputStream fs = null;
|
| | | FileChannel fc;
|
| | | Dgn7fileReader reader = null;
|
| | | try {
|
| | | convertContext.setExecutionContext(context);
|
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator);
|
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]);
|
| | | convertContext.startTransaction();
|
| | |
|
| | | fs = new FileInputStream(dgnFile);
|
| | | fc = fs.getChannel();
|
| | | reader = new Dgn7fileReader(fc, new Lock());
|
| | | convertContext.setReader(reader);
|
| | |
|
| | | scanOtherDgnElement(convertContext);
|
| | |
|
| | | convertContext.commitTransaction();
|
| | | convertContext.closeFeatureWriter();
|
| | |
|
| | | System.gc();
|
| | | System.runFinalization();
|
| | | } catch (FileNotFoundException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (Dgn7fileException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IllegalAttributeException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (SchemaException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } finally {
|
| | | convertContext.closeFeatureWriter();
|
| | |
|
| | | if (reader != null)
|
| | | {
|
| | | try {
|
| | | reader.close();
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | if (fs != null) {
|
| | | try {
|
| | | fs.close();
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | if (isProfileMode()) {
|
| | | logger.warn("Profile-Current convertContext Process Cost-" +
|
| | | ((int) ((convertContext.getProcessTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((convertContext.getProcessTime()) % 60000.0)) / 1000) + " sec");
|
| | | logger.warn("Profile-Current convertContext Update Cost-" +
|
| | | ((int) ((convertContext.getUpdateTime()) / 60000.0)) + " min - " +
|
| | | (((int) ((convertContext.getUpdateTime()) % 60000.0)) / 1000) + " sec");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void scanOtherDgnElement(GeneralDgnConvertEdbGeoJobContext convertContext)
|
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException {
|
| | | Dgn7fileReader reader = convertContext.getReader();
|
| | | int count = 0;
|
| | | Element lastComplex = null;
|
| | | while (reader.hasNext()) {
|
| | | Element.FileRecord record = reader.nextElement();
|
| | | if (record.element() != null) {
|
| | | Element element = (Element) record.element();
|
| | | ElementType type = element.getElementType();
|
| | |
|
| | | if ((!type.isComplexElement()) && (!element.isComponentElement())) {
|
| | | if (lastComplex != null) {
|
| | | processOtherElement(lastComplex, convertContext);
|
| | | lastComplex = null;
|
| | | }
|
| | |
|
| | | processOtherElement(element, convertContext);
|
| | | } else if (element.isComponentElement()) {
|
| | | if (lastComplex != null) {
|
| | | ((ComplexElement) lastComplex).add(element);
|
| | | }
|
| | | } else if (type.isComplexElement()) {
|
| | | if (lastComplex != null) {
|
| | | processOtherElement(lastComplex, convertContext);
|
| | | }
|
| | | lastComplex = element;
|
| | | }
|
| | | }
|
| | | count++;
|
| | | }
|
| | |
|
| | | if (lastComplex != null) {
|
| | | processOtherElement(lastComplex, convertContext);
|
| | | }
|
| | | logger.debug("ElementRecord Count=" + count);
|
| | | }
|
| | |
|
| | | private void processOtherElement(Element element, GeneralDgnConvertEdbGeoJobContext convertContext)
|
| | | throws IllegalAttributeException, SchemaException {
|
| | | convertContext.putFeatureCollection(element);
|
| | | }
|
| | |
|
| | | private void clearOutputDatabase() {
|
| | | /*
|
| | | File outDataPath = new File(getDataPath(), OracleConvertEdbGeoJobContext.SHPOUTPATH);
|
| | | if (outDataPath.exists() && outDataPath.isDirectory())
|
| | | {
|
| | | deleteFilesInPath(outDataPath);
|
| | | }
|
| | | outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH);
|
| | | if (outDataPath.exists() && outDataPath.isDirectory())
|
| | | {
|
| | | deleteFilesInPath(outDataPath);
|
| | | }
|
| | | outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH);
|
| | | if (outDataPath.exists() && outDataPath.isDirectory())
|
| | | {
|
| | | deleteFilesInPath(outDataPath);
|
| | | }
|
| | | */
|
| | | }
|
| | |
|
| | | private void deleteFilesInPath(File outDataPath) {
|
| | | deleteFilesInPath(outDataPath, true);
|
| | | }
|
| | |
|
| | | private void deleteFilesInPath(File outDataPath, boolean removeSubDir) {
|
| | | if (!outDataPath.isDirectory()) {
|
| | | return;
|
| | | }
|
| | | File[] files = outDataPath.listFiles();
|
| | | for (File file : files) {
|
| | | if (file.isFile()) {
|
| | | if (!file.delete()) {
|
| | | logger.info("Cannot delete file-" + file.toString());
|
| | | }
|
| | | } else if (file.isDirectory()) {
|
| | | deleteFilesInPath(file, removeSubDir);
|
| | | if (removeSubDir) {
|
| | | if (file.delete()) {
|
| | | logger.info("Cannot delete dir-" + file.toString());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void convertFeatureDesignFile(JobExecutionContext context, String targetSchemaName) throws JobExecutionException {
|
| | | File elminDir = new File(getDataPath(), "elmin");
|
| | | if (!elminDir.exists()) {
|
| | | logger.info("elmin dir=" + elminDir + " not exist.");
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!elminDir.isDirectory()) {
|
| | | logger.info("elmin dir=" + elminDir + " is not a directory.");
|
| | | }
|
| | |
|
| | | File[] dgnFiles = elminDir.listFiles(new FilenameFilter() {
|
| | | public boolean accept(File dir, String name) {
|
| | | return name.toLowerCase().endsWith(".dgn");
|
| | | }
|
| | | });
|
| | |
|
| | | for (File dgnFile : dgnFiles) {
|
| | | FeatureDgnConvertEdbGeoJobContext convertContext =
|
| | | new FeatureDgnConvertEdbGeoJobContext(getDataPath(), getTargetDataStore(), targetSchemaName, _filterPath,
|
| | | isProfileMode(), isTransformed());
|
| | | logger.info("--- start dgnfile-" + dgnFile.toString() + " ---");
|
| | | try {
|
| | | convertContext.setExecutionContext(context);
|
| | | String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator);
|
| | | convertContext.setFilename(dgnPaths[dgnPaths.length - 1]);
|
| | | convertContext.startTransaction();
|
| | |
|
| | | FileInputStream fs = new FileInputStream(dgnFile);
|
| | | FileChannel fc = fs.getChannel();
|
| | | Dgn7fileReader reader = new Dgn7fileReader(fc, new Lock());
|
| | | convertContext.setReader(reader);
|
| | |
|
| | | scanFeatureDgnElement(convertContext);
|
| | |
|
| | | convertContext.commitTransaction();
|
| | | convertContext.closeFeatureWriter();
|
| | | System.gc();
|
| | | System.runFinalization();
|
| | | } catch (FileNotFoundException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (Dgn7fileException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (IllegalAttributeException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } catch (SchemaException e) {
|
| | | convertContext.rollbackTransaction();
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | } finally {
|
| | | convertContext.closeFeatureWriter();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void scanFeatureDgnElement(FeatureDgnConvertEdbGeoJobContext convertContext)
|
| | | throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException {
|
| | | Dgn7fileReader reader = convertContext.getReader();
|
| | | int count = 0;
|
| | | Element lastComplex = null;
|
| | | while (reader.hasNext()) {
|
| | | Element.FileRecord record = reader.nextElement();
|
| | | if (record.element() != null) {
|
| | | Element element = (Element) record.element();
|
| | | ElementType type = element.getElementType();
|
| | |
|
| | | if ((!type.isComplexElement()) && (!element.isComponentElement())) {
|
| | | if (lastComplex != null) {
|
| | | processFeatureElement(lastComplex, convertContext);
|
| | | lastComplex = null;
|
| | | }
|
| | |
|
| | | processFeatureElement(element, convertContext);
|
| | | } else if (element.isComponentElement()) {
|
| | | if (lastComplex != null) {
|
| | | ((ComplexElement) lastComplex).add(element);
|
| | | }
|
| | | } else if (type.isComplexElement()) {
|
| | | if (lastComplex != null) {
|
| | | processFeatureElement(lastComplex, convertContext);
|
| | | }
|
| | | lastComplex = element;
|
| | | }
|
| | | }
|
| | | count++;
|
| | | }
|
| | |
|
| | | if (lastComplex != null) {
|
| | | processFeatureElement(lastComplex, convertContext);
|
| | | }
|
| | | logger.debug("ElementRecord Count=" + count);
|
| | | }
|
| | |
|
| | | private void processFeatureElement(Element element, FeatureDgnConvertEdbGeoJobContext convertContext)
|
| | | throws IllegalAttributeException, SchemaException {
|
| | | convertContext.putFeatureCollection(element);
|
| | | }
|
| | |
|
| | | private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException {
|
| | | /*
|
| | | DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath);
|
| | | try {
|
| | | convertContext.startTransaction();
|
| | | convertContext.commitTransaction();
|
| | | convertContext.closeFeatureWriter();
|
| | | } catch (IOException e)
|
| | | {
|
| | | logger.warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | }
|
| | | */
|
| | | }
|
| | |
|
| | | public DataStore getTargetDataStore() {
|
| | | return targetDataStore;
|
| | | }
|
| | |
|
| | | protected void createTargetDataStore() throws JobExecutionException {
|
| | | if (targetDataStore != null) {
|
| | | targetDataStore.dispose();
|
| | | targetDataStore = null;
|
| | | }
|
| | |
|
| | | /*
|
| | | if (!isDriverFound())
|
| | | {
|
| | | throw new JobExecutionException("Oracle JDBC Driver not found.-" + JDBC_DRIVER);
|
| | | }
|
| | | */
|
| | |
|
| | | if (!edbProperties.containsKey(PostgisDataStoreFactory.MAXCONN.key)) {
|
| | | edbProperties.put(PostgisDataStoreFactory.MAXCONN.key, "5");
|
| | | }
|
| | |
|
| | | if (!edbProperties.containsKey(PostgisDataStoreFactory.MINCONN.key)) {
|
| | | edbProperties.put(PostgisDataStoreFactory.MINCONN.key, "1");
|
| | | }
|
| | |
|
| | | if (!edbProperties.containsKey(PostgisDataStoreFactory.WKBENABLED.key)) {
|
| | | edbProperties.put(PostgisDataStoreFactory.WKBENABLED.key, "true");
|
| | | }
|
| | |
|
| | | if (!dataStoreFactory.canProcess(edbProperties)) {
|
| | | getLogger().warn("cannot process properties-");
|
| | | throw new JobExecutionException("cannot process properties-");
|
| | | }
|
| | | try {
|
| | | targetDataStore = (PostgisDataStore) dataStoreFactory.createDataStore(edbProperties);
|
| | | } catch (IOException e) {
|
| | | getLogger().warn(e.getMessage(), e);
|
| | | throw new JobExecutionException(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | protected void disconnect() {
|
| | | super.disconnect();
|
| | | if (targetDataStore != null) {
|
| | | targetDataStore.dispose();
|
| | | targetDataStore = null;
|
| | | }
|
| | | }
|
| | |
|
| | | private String determineTargetSchemaName() throws IOException {
|
| | | if (targetDataStore == null) return null;
|
| | | Connection connection = null;
|
| | | Statement stmt = null;
|
| | | ResultSet rs = null;
|
| | | String targetSchema = null;
|
| | | boolean needCreate = false;
|
| | | try {
|
| | | connection = targetDataStore.getConnection(Transaction.AUTO_COMMIT);
|
| | | rs = connection.getMetaData().getTables(null, _edbSchema, DataReposVersionManager.XGVERSIONTABLE_NAME, new String[]{"TABLE"});
|
| | | if (!rs.next()) needCreate = true;
|
| | | if (needCreate)
|
| | | createXGeosVersionTable(connection, _edbSchema);
|
| | | rs.close();
|
| | | rs = null;
|
| | |
|
| | | StringBuilder sbSQL = new StringBuilder("SELECT ");
|
| | | sbSQL.append("vsschema, vsstatus FROM ");
|
| | | sbSQL.append(encodeSchemaTableName(_edbSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' ');
|
| | | sbSQL.append("ORDER BY vsid");
|
| | | stmt = connection.createStatement();
|
| | | rs = stmt.executeQuery(sbSQL.toString());
|
| | | ArrayList<Object[]> tmpSchemas = new ArrayList<Object[]>();
|
| | | int i = 0;
|
| | | int current = -1;
|
| | | while (rs.next()) {
|
| | | Object[] values = new Object[2];
|
| | | values[0] = rs.getString("vsschema");
|
| | | values[1] = rs.getShort("vsstatus");
|
| | | tmpSchemas.add(values);
|
| | | if ((((Short) values[1]) & DataReposVersionManager.VSSTATUS_USING) != 0) {
|
| | | current = i;
|
| | | }
|
| | | i++;
|
| | | }
|
| | |
|
| | | if (current == -1) {
|
| | | Object[] values = tmpSchemas.get(0);
|
| | | targetSchema = (String) values[0];
|
| | | } else if (current < (tmpSchemas.size() - 1)) {
|
| | | Object[] values = tmpSchemas.get(current + 1);
|
| | | targetSchema = (String) values[0];
|
| | | } else {
|
| | | Object[] values = tmpSchemas.get(0);
|
| | | targetSchema = (String) values[0];
|
| | | }
|
| | |
|
| | | sbSQL = new StringBuilder("UPDATE ");
|
| | | sbSQL.append(encodeSchemaTableName(_edbSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' ');
|
| | | sbSQL.append(" SET vsstatus = ");
|
| | | sbSQL.append(DataReposVersionManager.VSSTATUS_COVERT);
|
| | | sbSQL.append(" WHERE vsschema = '");
|
| | | sbSQL.append(targetSchema).append("'");
|
| | | int count = stmt.executeUpdate(sbSQL.toString());
|
| | | if (count != 1) {
|
| | | logger.info("update status for " + targetSchema + " update result count="
|
| | | + count);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | } finally {
|
| | | JDBCUtils.close(rs);
|
| | | JDBCUtils.close(stmt);
|
| | | JDBCUtils.close(connection, Transaction.AUTO_COMMIT, null);
|
| | | }
|
| | | return targetSchema;
|
| | | }
|
| | |
|
| | | public String encodeSchemaTableName(String schemaName, String tableName) {
|
| | | return "\"" + schemaName + "\".\"" + tableName + "\"";
|
| | | }
|
| | |
|
| | | private void createXGeosVersionTable(Connection connection, String pgSchema) throws SQLException {
|
| | | Statement stmt = null;
|
| | | StringBuilder sql = new StringBuilder("CREATE TABLE ");
|
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME));
|
| | | sql.append(" ( vsid serial PRIMARY KEY, ");
|
| | | sql.append(" vsschema character varying(64) NOT NULL, ");
|
| | | sql.append(" vsstatus smallint NOT NULL, ");
|
| | | sql.append(" vstimestamp timestamp with time zone ) ");
|
| | | try {
|
| | | stmt = connection.createStatement();
|
| | | stmt.executeUpdate(sql.toString());
|
| | |
|
| | | sql = new StringBuilder("ALTER TABLE ");
|
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME));
|
| | | sql.append(" OWNER TO ").append(_edbUsername);
|
| | | stmt.executeUpdate(sql.toString());
|
| | |
|
| | | sql = new StringBuilder("GRANT ALL ON TABLE ");
|
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME));
|
| | | sql.append(" TO public");
|
| | | stmt.executeUpdate(sql.toString());
|
| | |
|
| | | for (String schemaName : DataReposVersionManager.DEFAULTXGVERSIONSCHEMA_NAMES) {
|
| | | sql = new StringBuilder("INSERT INTO ");
|
| | | sql.append(encodeSchemaTableName(pgSchema, DataReposVersionManager.XGVERSIONTABLE_NAME));
|
| | | sql.append(" (vsschema, vsstatus) VALUES ('");
|
| | | sql.append(schemaName).append("', ");
|
| | | sql.append(DataReposVersionManager.VSSTATUS_AVAILABLE).append(" )");
|
| | | stmt.executeUpdate(sql.toString());
|
| | |
|
| | | createIfNotExistNewSchema(connection, schemaName);
|
| | | }
|
| | |
|
| | | } finally {
|
| | | if (stmt != null) stmt.close();
|
| | | }
|
| | | }
|
| | |
|
| | | private void updateRepoStatusToReady(String targetSchema) {
|
| | | if (targetDataStore == null) return;
|
| | | Connection connection = null;
|
| | | Statement stmt = null;
|
| | | ResultSet rs = null;
|
| | | boolean needCreate = false;
|
| | | try {
|
| | | StringBuilder sbSQL = new StringBuilder("UPDATE ");
|
| | | sbSQL.append(encodeSchemaTableName(_edbSchema, DataReposVersionManager.XGVERSIONTABLE_NAME)).append(' ');
|
| | | sbSQL.append(" SET vsstatus = ");
|
| | | sbSQL.append(DataReposVersionManager.VSSTATUS_READY);
|
| | | sbSQL.append(" , vstimestamp = CURRENT_TIMESTAMP WHERE vsschema = '");
|
| | | sbSQL.append(targetSchema).append("'");
|
| | |
|
| | | connection = targetDataStore.getConnection(Transaction.AUTO_COMMIT);
|
| | | stmt = connection.createStatement();
|
| | | int count = stmt.executeUpdate(sbSQL.toString());
|
| | | if (count != 1) {
|
| | | logger.info("update status for " + targetSchema + " update result count="
|
| | | + count);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | } finally {
|
| | | JDBCUtils.close(rs);
|
| | | JDBCUtils.close(stmt);
|
| | | JDBCUtils.close(connection, Transaction.AUTO_COMMIT, null);
|
| | | }
|
| | | }
|
| | |
|
| | | private void createIfNotExistNewSchema(Connection connection, String s) throws SQLException {
|
| | | Statement stmt = null;
|
| | | ResultSet rs = null;
|
| | | try {
|
| | | /*
|
| | | rs = connection.getMetaData().getSchemas(null, s);
|
| | | if (rs.next()) return;
|
| | | rs.close();
|
| | | rs = null;
|
| | | */
|
| | |
|
| | | StringBuilder sbSQL = new StringBuilder("CREATE SCHEMA ");
|
| | | sbSQL.append(s).append(' ');
|
| | | sbSQL.append("AUTHORIZATION ").append(_edbUsername);
|
| | | stmt = connection.createStatement();
|
| | | stmt.executeUpdate(sbSQL.toString());
|
| | |
|
| | | sbSQL = new StringBuilder("GRANT ALL ON SCHEMA ");
|
| | | sbSQL.append(s).append(' ');
|
| | | sbSQL.append("TO public");
|
| | | stmt.executeUpdate(sbSQL.toString());
|
| | | } catch (SQLException e) {
|
| | | logger.info("create schema:" + s + " has exception.");
|
| | | logger.info(e.getMessage(), e);
|
| | | } finally {
|
| | | if (rs != null) rs.close();
|
| | | if (stmt != null) stmt.close();
|
| | | }
|
| | | }
|
| | |
|
| | | public final void accumulateQueryTime() {
|
| | | queryTime += System.currentTimeMillis() - queryTimeStart;
|
| | | }
|
| | |
|
| | | public long getQueryTime() {
|
| | | return queryTime;
|
| | | }
|
| | |
|
| | | public final void markQueryTime() {
|
| | | queryTimeStart = System.currentTimeMillis();
|
| | | }
|
| | |
|
| | | public final void resetQueryTime() {
|
| | | queryTime = 0;
|
| | | }
|
| | | }
|
| | |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | |
| | | import oracle.jdbc.OracleConnection; |
| | | import oracle.jdbc.OracleResultSet; |
| | | import oracle.sql.ARRAY; |
| | |
| | | |
| | | private void clearOutputDatabase() { |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertPostGISJobContext.SHPOUTPATH); |
| | | File outDataPath = new File(getDataPath(), OracleConvertEdbGeoJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
| | |
| | | final static Log logger = LogFactory.getLog(OracleConvertDgn2PostGISJob.class); |
| | | |
| | | private static final String PGHOST = "PGHOST"; |
| | | private static final String PGDDATBASE = "PGDDATBASE"; |
| | | private static final String PGDATBASE = "PGDATBASE"; |
| | | private static final String PGPORT = "PGPORT"; |
| | | private static final String PGSCHEMA = "PGSCHEMA"; |
| | | private static final String PGUSER = "PGUSER"; |
| | |
| | | |
| | | protected Map<String, String> pgProperties; |
| | | protected PostgisDataStore targetDataStore; |
| | | // protected OracleConvertPostGISJobContext oracleJobContext; |
| | | // protected OracleConvertEdbGeoJobContext oracleJobContext; |
| | | |
| | | private long queryTime = 0; |
| | | private long queryTimeStart = 0; |
| | |
| | | super.extractJobConfiguration(jobDetail); |
| | | JobDataMap dataMap = jobDetail.getJobDataMap(); |
| | | _pgHost = dataMap.getString(PGHOST); |
| | | _pgDatabase = dataMap.getString(PGDDATBASE); |
| | | _pgDatabase = dataMap.getString(PGDATBASE); |
| | | _pgPort = dataMap.getString(PGPORT); |
| | | _pgSchema = dataMap.getString(PGSCHEMA); |
| | | _pgUsername = dataMap.getString(PGUSER); |
| | |
| | | Log logger = getLogger(); |
| | | /* |
| | | logger.info("PGHOST=" + _myHost); |
| | | logger.info("PGDDATBASE=" + _myDatabase); |
| | | logger.info("PGDATBASE=" + _myDatabase); |
| | | logger.info("PGPORT=" + _myPort); |
| | | logger.info("PGSCHEMA=" + _mySchema); |
| | | logger.info("PGUSER=" + _myUsername); |
| | |
| | | |
| | | private void clearOutputDatabase() { |
| | | /* |
| | | File outDataPath = new File(getDataPath(), OracleConvertPostGISJobContext.SHPOUTPATH); |
| | | File outDataPath = new File(getDataPath(), OracleConvertEdbGeoJobContext.SHPOUTPATH); |
| | | if (outDataPath.exists() && outDataPath.isDirectory()) |
| | | { |
| | | deleteFilesInPath(outDataPath); |
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.sql.Connection;
|
| | | import java.sql.DatabaseMetaData;
|
| | | import java.sql.PreparedStatement;
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.*;
|
| | |
|
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil;
|
| | | 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.edbgeo.PostgisDataStore;
|
| | | import org.geotools.filter.LengthFunction;
|
| | | import org.geotools.referencing.NamedIdentifier;
|
| | | import org.geotools.referencing.crs.DefaultGeographicCRS;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import org.opengis.feature.type.AttributeDescriptor;
|
| | | import org.opengis.feature.type.AttributeType;
|
| | | import org.opengis.feature.type.GeometryDescriptor;
|
| | | import org.opengis.feature.type.GeometryType;
|
| | | import org.opengis.feature.type.PropertyType;
|
| | | import org.opengis.filter.BinaryComparisonOperator;
|
| | | import org.opengis.filter.Filter;
|
| | | import org.opengis.filter.PropertyIsLessThan;
|
| | | import org.opengis.filter.PropertyIsLessThanOrEqualTo;
|
| | | 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 AbstractDgnToEdbGeoJobContext 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>();
|
| | |
|
| | | static {
|
| | | GEOM_TYPE_MAP.put("GEOMETRY", Geometry.class);
|
| | | GEOM_TYPE_MAP.put("POINT", Point.class);
|
| | | GEOM_TYPE_MAP.put("LINESTRING", LineString.class);
|
| | | GEOM_TYPE_MAP.put("POLYGON", Polygon.class);
|
| | | GEOM_TYPE_MAP.put("MULTIPOINT", MultiPoint.class);
|
| | | GEOM_TYPE_MAP.put("MULTILINESTRING", MultiLineString.class);
|
| | | GEOM_TYPE_MAP.put("MULTIPOLYGON", MultiPolygon.class);
|
| | | GEOM_TYPE_MAP.put("GEOMETRYCOLLECTION", GeometryCollection.class);
|
| | |
|
| | | GEOM3D_TYPE_MAP.put("POINTM", Point.class);
|
| | | GEOM3D_TYPE_MAP.put("LINESTRINGM", LineString.class);
|
| | | GEOM3D_TYPE_MAP.put("POLYGONM", Polygon.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTIPOINTM", MultiPoint.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTILINESTRINGM", MultiLineString.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTIPOLYGONM", MultiPolygon.class);
|
| | | GEOM3D_TYPE_MAP.put("GEOMETRYCOLLECTIONM", GeometryCollection.class);
|
| | | }
|
| | |
|
| | | private static Map<Class, String> CLASS_MAPPINGS = new HashMap<Class, String>();
|
| | |
|
| | | static {
|
| | | CLASS_MAPPINGS.put(String.class, "VARCHAR");
|
| | |
|
| | | CLASS_MAPPINGS.put(Boolean.class, "BOOLEAN");
|
| | |
|
| | | CLASS_MAPPINGS.put(Short.class, "SMALLINT");
|
| | | CLASS_MAPPINGS.put(Integer.class, "INTEGER");
|
| | | CLASS_MAPPINGS.put(Long.class, "BIGINT");
|
| | |
|
| | | CLASS_MAPPINGS.put(Float.class, "REAL");
|
| | | CLASS_MAPPINGS.put(Double.class, "DOUBLE PRECISION");
|
| | |
|
| | | CLASS_MAPPINGS.put(BigDecimal.class, "DECIMAL");
|
| | |
|
| | | CLASS_MAPPINGS.put(java.sql.Date.class, "DATE");
|
| | | CLASS_MAPPINGS.put(java.util.Date.class, "DATE");
|
| | | CLASS_MAPPINGS.put(java.sql.Time.class, "TIME");
|
| | | CLASS_MAPPINGS.put(java.sql.Timestamp.class, "TIMESTAMP");
|
| | | }
|
| | |
|
| | | private static Map<Class, String> GEOM_CLASS_MAPPINGS = new HashMap<Class, String>();
|
| | |
|
| | | //why don't we just stick this in with the non-geom class mappings?
|
| | | static {
|
| | | // init the inverse map
|
| | | Set keys = GEOM_TYPE_MAP.keySet();
|
| | |
|
| | | for (Object key : keys) {
|
| | | String name = (String) key;
|
| | | Class geomClass = GEOM_TYPE_MAP.get(name);
|
| | | GEOM_CLASS_MAPPINGS.put(geomClass, name);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Maximum string size for postgres
|
| | | */
|
| | | private static final int MAX_ALLOWED_VALUE = 10485760;
|
| | |
|
| | | // protected static final int BATCHSIZE = 2048;
|
| | | protected static final int BATCHSIZE = 256;
|
| | |
|
| | | /**
|
| | | * Well Known Text writer (from JTS).
|
| | | */
|
| | | protected static WKTWriter geometryWriter = new WKTWriter();
|
| | | protected static JtsBinaryWriter binaryWriter = new JtsBinaryWriter();
|
| | |
|
| | | private PostgisDataStore targetDataStore;
|
| | | // protected Connection connection;
|
| | | protected String targetSchema = "public";
|
| | |
|
| | | protected boolean schemaEnabled = true;
|
| | |
|
| | | public AbstractDgnToEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | boolean profileMode, boolean useTransform) {
|
| | | super(dataPath, profileMode, useTransform);
|
| | | if ((targetDataStore != null) && (targetDataStore instanceof PostgisDataStore)) {
|
| | | this.targetDataStore = (PostgisDataStore) targetDataStore;
|
| | | } else {
|
| | | getLogger().info("targetDataStore has wrong.");
|
| | | }
|
| | | // this.connection = connection;
|
| | | setTargetSchema(targetSchema);
|
| | | }
|
| | |
|
| | | public PostgisDataStore getTargetDataStore() {
|
| | | return targetDataStore;
|
| | | }
|
| | |
|
| | | public void setTargetDataStore(PostgisDataStore targetDataStore) {
|
| | | this.targetDataStore = targetDataStore;
|
| | | }
|
| | |
|
| | | public String getTargetSchema() {
|
| | | return targetSchema;
|
| | | }
|
| | |
|
| | | public void setTargetSchema(String schemaName) {
|
| | | targetSchema = schemaName;
|
| | | }
|
| | |
|
| | | public Connection getConnection() {
|
| | | try {
|
| | | return targetDataStore.getConnection(Transaction.AUTO_COMMIT);
|
| | |
|
| | | } catch (IOException e)
|
| | | {
|
| | | getLogger().warn(e.getMessage(), e);
|
| | | return null;
|
| | | }
|
| | | // return connection;
|
| | | }
|
| | |
|
| | | protected boolean isExistFeature(SimpleFeatureType featureType) {
|
| | | try {
|
| | | SimpleFeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName());
|
| | | return existFeatureType != null; // && existFeatureType.equals(featureType);
|
| | | } catch (SchemaNotFoundException e) {
|
| | | return false;
|
| | | } catch (IOException e) {
|
| | | getLogger().info(e.getMessage(), e);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | protected void deleteTable(Connection conn, String tableName) throws SQLException {
|
| | | Statement stmt = conn.createStatement();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("DELETE FROM \"");
|
| | | sb.append(getTargetSchema());
|
| | | sb.append("\".\"");
|
| | | sb.append(tableName);
|
| | | sb.append('\"');
|
| | | stmt.execute(sb.toString());
|
| | | if (!conn.getAutoCommit())
|
| | | conn.commit();
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | |
|
| | | protected void dropTable(Connection conn, String tableName) throws SQLException {
|
| | | Statement stmt = conn.createStatement();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("DROP TABLE \"");
|
| | | sb.append(getTargetSchema());
|
| | | sb.append("\".\"");
|
| | | sb.append(tableName);
|
| | | sb.append("\"");
|
| | | // sb.append(" CASCADE");
|
| | | stmt.execute(sb.toString());
|
| | | if (!conn.getAutoCommit())
|
| | | conn.commit();
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | |
|
| | | protected void dropGeometryColumn(Connection conn, String tableName, String geomField) throws SQLException {
|
| | | Statement stmt = conn.createStatement();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("SELECT \"public\".DropGeometryColumn('','");
|
| | | sb.append(tableName);
|
| | | sb.append("','");
|
| | | sb.append(geomField);
|
| | | sb.append("')");
|
| | | stmt.execute(sb.toString());
|
| | | if (!conn.getAutoCommit())
|
| | | conn.commit();
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | |
|
| | | protected String dropGeometryColumn(String dbSchema, String tableName, String geomField) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("SELECT \"public\".DropGeometryColumn('");
|
| | | sb.append(dbSchema);
|
| | | sb.append("','");
|
| | | sb.append(tableName);
|
| | | sb.append("','");
|
| | | sb.append(geomField);
|
| | | sb.append("')");
|
| | | getLogger().info("Execute-" + sb.toString());
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | private String addGeometryColumn(String dbSchema, String tableName, GeometryDescriptor geometryDescriptor, int srid) {
|
| | | StringBuilder sql;
|
| | | String typeName = getGeometrySQLTypeName(((AttributeType) geometryDescriptor.getType()).getBinding());
|
| | | if (typeName == null) {
|
| | | getLogger().warn("Error: " + geometryDescriptor.getLocalName() + " unknown type!!!");
|
| | | throw new RuntimeException("Error: " + geometryDescriptor.getLocalName() + " unknown type!!!");
|
| | | }
|
| | |
|
| | | sql = new StringBuilder("SELECT \"public\".AddGeometryColumn('");
|
| | | sql.append(dbSchema);
|
| | | sql.append("','");
|
| | | sql.append(tableName);
|
| | | sql.append("','");
|
| | | sql.append(geometryDescriptor.getLocalName());
|
| | | sql.append("','");
|
| | | sql.append(srid);
|
| | | sql.append("','");
|
| | | sql.append(typeName);
|
| | | sql.append("', 2);");
|
| | |
|
| | | //prints statement for later reuse
|
| | | return sql.toString();
|
| | | }
|
| | |
|
| | | public ArrayList<String> createNewSchemaTexts(Connection conn, SimpleFeatureType featureType) throws IOException {
|
| | | String origintableName = featureType.getTypeName();
|
| | | String tableName = origintableName.toLowerCase();
|
| | |
|
| | | ArrayList<String> result = new ArrayList<String>();
|
| | |
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | |
|
| | | boolean shouldDrop = tablePresent(getTargetSchema(), tableName, conn);
|
| | |
|
| | | if (shouldDrop) {
|
| | | String sqlStr;
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | if (!(descriptor instanceof GeometryDescriptor)) {
|
| | | continue;
|
| | | }
|
| | | GeometryDescriptor geometryDescriptor = (GeometryDescriptor) descriptor;
|
| | | sqlStr = dropGeometryColumn(getTargetSchema(), tableName, geometryDescriptor.getLocalName());
|
| | | getLogger().info(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | | // sqlStr = "DROP TABLE " + encodeSchemaTableName(tableName) + " CASCADE;";
|
| | | sqlStr = "DROP TABLE " + encodeSchemaTableName(tableName) + " ;";
|
| | | getLogger().info(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | |
|
| | | StringBuilder sql = new StringBuilder("CREATE TABLE ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" ( gid serial PRIMARY KEY, ");
|
| | | sql.append(makeNonGeomSqlCreate(descriptors));
|
| | | sql.append(");");
|
| | |
|
| | | String sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | |
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | if (!(descriptor instanceof GeometryDescriptor)) {
|
| | | continue;
|
| | | }
|
| | | GeometryDescriptor geometryDescriptor = (GeometryDescriptor) descriptor;
|
| | |
|
| | | CoordinateReferenceSystem refSys = geometryDescriptor.getCoordinateReferenceSystem();
|
| | | int SRID = getSRID(refSys);
|
| | |
|
| | | sqlStr = addGeometryColumn(getTargetSchema(), tableName, geometryDescriptor, SRID);
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | |
|
| | |
|
| | | String indexName = tableName.replace('-', '_');
|
| | | //also build a spatial index on each geometry column.
|
| | | sql = new StringBuilder("CREATE INDEX \"spatial_");
|
| | | sql.append(indexName);
|
| | | sql.append("_");
|
| | | sql.append(descriptor.getLocalName().toLowerCase());
|
| | | sql.append("\" ON ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" USING GIST (");
|
| | | sql.append(encodeSchemaColumnName(descriptor.getLocalName()));
|
| | | sql.append(" gist_geometry_ops);");
|
| | |
|
| | | sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | |
|
| | | result.add(sqlStr);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | private int getSRID(CoordinateReferenceSystem refSys) {
|
| | | int SRID;
|
| | | if (refSys != null) {
|
| | | try {
|
| | | Set ident = refSys.getIdentifiers();
|
| | | if ((ident == null || ident.isEmpty()) && refSys == DefaultGeographicCRS.WGS84) {
|
| | | SRID = 4326;
|
| | | } else {
|
| | | assert ident != null;
|
| | | String code = ((NamedIdentifier) ident.toArray()[0]).getCode();
|
| | | SRID = Integer.parseInt(code);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | getLogger().warn("SRID could not be determined");
|
| | | SRID = -1;
|
| | | }
|
| | | } else {
|
| | | SRID = -1;
|
| | | }
|
| | | return SRID;
|
| | | }
|
| | |
|
| | | private boolean tablePresent(String schema, String table, Connection conn) throws IOException {
|
| | | final int TABLE_NAME_COL = 3;
|
| | |
|
| | | ResultSet tables = null;
|
| | | try {
|
| | | DatabaseMetaData meta = conn.getMetaData();
|
| | | String[] tableType = {"TABLE"};
|
| | | tables = meta.getTables(null, schema, "%", tableType);
|
| | |
|
| | | while (tables.next()) {
|
| | | String tableName = tables.getString(TABLE_NAME_COL);
|
| | |
|
| | | if (allowTable(tableName) && (tableName != null)
|
| | | && (tableName.equalsIgnoreCase(table))) {
|
| | | return (true);
|
| | | }
|
| | | }
|
| | |
|
| | | return false;
|
| | | } catch (SQLException sqlException) {
|
| | | String message = "Error querying database for list of tables:"
|
| | | + sqlException.getMessage();
|
| | | throw new DataSourceException(message, sqlException);
|
| | | } finally {
|
| | | if (tables != null)
|
| | | JDBCUtils.close(tables);
|
| | | }
|
| | | }
|
| | |
|
| | | protected boolean allowTable(String tablename) {
|
| | | if (tablename.equals("geometry_columns")) {
|
| | | return false;
|
| | | } else if (tablename.startsWith("spatial_ref_sys")) {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //others?
|
| | | return true;
|
| | | }
|
| | |
|
| | |
|
| | | private StringBuilder makeNonGeomSqlCreate(List<AttributeDescriptor> descriptors)
|
| | | throws IOException {
|
| | | StringBuilder buf = new StringBuilder("");
|
| | |
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | String typeName;
|
| | | typeName = CLASS_MAPPINGS.get(((AttributeType) descriptor.getType()).getBinding());
|
| | | if (typeName == null) {
|
| | | typeName = GEOM_CLASS_MAPPINGS.get(((AttributeType) descriptor.getType()).getBinding());
|
| | | if (typeName != null) continue;
|
| | | }
|
| | |
|
| | | if (typeName != null) {
|
| | | if (typeName.equals("VARCHAR")) {
|
| | | int length = -1;
|
| | | List<Filter> flist = ((PropertyType) descriptor.getType()).getRestrictions();
|
| | | for (Filter f : flist) {
|
| | | if (f != null && f != Filter.EXCLUDE && f != Filter.INCLUDE &&
|
| | | (f instanceof PropertyIsLessThan || f instanceof PropertyIsLessThanOrEqualTo)) {
|
| | | try {
|
| | | BinaryComparisonOperator cf = (BinaryComparisonOperator) f;
|
| | | if (cf.getExpression1() instanceof LengthFunction) {
|
| | | length = Integer.parseInt(((Literal) cf.getExpression2()).getValue().toString());
|
| | | } else {
|
| | | if (cf.getExpression2() instanceof LengthFunction) {
|
| | | length = Integer.parseInt(((Literal) cf.getExpression1()).getValue().toString());
|
| | | }
|
| | | }
|
| | | } catch (NumberFormatException e) {
|
| | | length = 256;
|
| | | }
|
| | | } else {
|
| | | length = 256;
|
| | | }
|
| | | break;
|
| | | }
|
| | | if (length < 1) {
|
| | | getLogger().warn("FeatureType did not specify string length; defaulted to 256");
|
| | | length = 256;
|
| | | } else if (length > MAX_ALLOWED_VALUE) {
|
| | | length = MAX_ALLOWED_VALUE;
|
| | | }
|
| | | typeName = typeName + "(" + length + ")";
|
| | | }
|
| | |
|
| | | if (!descriptor.isNillable()) {
|
| | | typeName = typeName + " NOT NULL";
|
| | | }
|
| | |
|
| | | //TODO review!!! Is toString() always OK???
|
| | | Object defaultValue = descriptor.getDefaultValue();
|
| | |
|
| | | if (defaultValue != null) {
|
| | | typeName = typeName + " DEFAULT '"
|
| | | + defaultValue.toString() + "'";
|
| | | }
|
| | |
|
| | | buf.append(" \"").append(descriptor.getLocalName()).append("\" ").append(typeName).append(",");
|
| | |
|
| | | } else {
|
| | | String msg;
|
| | | if (descriptor == null) {
|
| | | msg = "AttributeType was null!";
|
| | | } else {
|
| | | msg = "Type '" + ((AttributeType) descriptor.getType()).getBinding() + "' not supported!";
|
| | | }
|
| | | throw (new IOException(msg));
|
| | | }
|
| | | }
|
| | |
|
| | | return buf.deleteCharAt(buf.length() - 1);
|
| | | }
|
| | |
|
| | | private String getGeometrySQLTypeName(Class type) {
|
| | | String res = GEOM_CLASS_MAPPINGS.get(type);
|
| | |
|
| | | if (res == null) {
|
| | | throw new RuntimeException("Unknown type name for class " + type
|
| | | + " please update GEOMETRY_MAPPINGS");
|
| | | }
|
| | |
|
| | | return res;
|
| | | }
|
| | |
|
| | | protected String getGeometryInsertText(Geometry geom, int srid) // throws IOException
|
| | | {
|
| | | if (geom == null) {
|
| | | return "null";
|
| | | }
|
| | |
|
| | | if (targetDataStore.isWKBEnabled()) {
|
| | | //String wkb = WKBEncoder.encodeGeometryHex(geom);
|
| | | String wkb = WKBWriter.bytesToHex(new WKBWriter().write(geom));
|
| | |
|
| | | if (targetDataStore.isByteaWKB()) {
|
| | | return "setSRID('" + wkb + "'::geometry," + srid + ")";
|
| | | } else {
|
| | | return "GeomFromWKB('" + wkb + "', " + srid + ")";
|
| | | }
|
| | | }
|
| | |
|
| | | String geoText = geometryWriter.write(geom);
|
| | |
|
| | | return "GeometryFromText('" + geoText + "', " + srid + ")";
|
| | | }
|
| | |
|
| | | protected String makeInsertSql(SimpleFeature feature, int srid) // throws IOException
|
| | | {
|
| | | SimpleFeatureType featureType = feature.getFeatureType();
|
| | |
|
| | | String tableName = encodeSchemaTableName(featureType.getTypeName());
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | |
|
| | | String attrValue;
|
| | |
|
| | | StringBuilder statementSQL = new StringBuilder("INSERT INTO " + tableName + " (");
|
| | |
|
| | | // encode insertion for attributes, but remember to avoid auto-increment ones,
|
| | | // they may be included in the feature type as well
|
| | | for (AttributeDescriptor attributeType : descriptors) {
|
| | | String attName = attributeType.getLocalName();
|
| | |
|
| | | if (feature.getAttribute(attName) != null) {
|
| | | String colName = encodeSchemaColumnName(attName);
|
| | | statementSQL.append(colName).append(",");
|
| | | }
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | | statementSQL.append(" VALUES (");
|
| | |
|
| | | List<Object> attributes = feature.getAttributes();
|
| | |
|
| | | for (int i = 0; i < descriptors.size(); i++) {
|
| | | attrValue = null;
|
| | |
|
| | | if (descriptors.get(i) instanceof GeometryDescriptor) {
|
| | | // String geomName = descriptors[i].getLocalName();
|
| | | // int srid = ftInfo.getSRID(geomName);
|
| | | Geometry geometry = (Geometry) attributes.get(i);
|
| | | geometry.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID());
|
| | |
|
| | | if (geometry == null) {
|
| | | attrValue = "NULL";
|
| | | } else {
|
| | | attrValue = getGeometryInsertText(geometry, srid);
|
| | | }
|
| | | } else {
|
| | | if (attributes.get(i) != null) {
|
| | | attrValue = addQuotes(attributes.get(i));
|
| | | }
|
| | | }
|
| | |
|
| | | if (attrValue != null) {
|
| | | statementSQL.append(attrValue).append(",");
|
| | | }
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | |
|
| | | return (statementSQL.toString());
|
| | | }
|
| | |
|
| | | protected String makePrepareInsertSql(SimpleFeatureType featureType) {
|
| | | String tableName = encodeSchemaTableName(featureType.getTypeName());
|
| | | List<AttributeDescriptor> attributeTypes = featureType.getAttributeDescriptors();
|
| | |
|
| | | String attrValue;
|
| | |
|
| | | StringBuilder statementSQL = new StringBuilder("INSERT INTO " + tableName + " (");
|
| | |
|
| | | // encode insertion for attributes, but remember to avoid auto-increment ones,
|
| | | // they may be included in the feature type as well
|
| | | for (AttributeDescriptor descriptor : attributeTypes) {
|
| | | String attName = descriptor.getName().getLocalPart();
|
| | |
|
| | | String colName = encodeSchemaColumnName(attName);
|
| | | statementSQL.append(colName).append(",");
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | | statementSQL.append(" VALUES (");
|
| | |
|
| | | for (AttributeDescriptor attributeType : attributeTypes) {
|
| | | statementSQL.append(" ? ,");
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | |
|
| | | return (statementSQL.toString());
|
| | | }
|
| | |
|
| | | protected String addQuotes(Object value) {
|
| | | String retString;
|
| | |
|
| | | if (value != null) {
|
| | | if (value instanceof Number) {
|
| | | retString = value.toString();
|
| | | } else {
|
| | | retString = "'" + doubleQuote(value) + "'";
|
| | | }
|
| | | } else {
|
| | | retString = "null";
|
| | | }
|
| | |
|
| | | return retString;
|
| | | }
|
| | |
|
| | | String doubleQuote(Object obj) {
|
| | | return obj.toString().replaceAll("'", "''");
|
| | | }
|
| | |
|
| | | protected String encodeName(String tableName) {
|
| | | return tableName;
|
| | | }
|
| | |
|
| | | protected String encodeColumnName(String colName) {
|
| | | return encodeName(colName);
|
| | | }
|
| | |
|
| | | public String encodeSchemaTableName(String tableName) {
|
| | | return schemaEnabled ? ("\"" + getTargetSchema() + "\".\"" + tableName + "\"")
|
| | | : ("\"" + tableName + "\"");
|
| | | }
|
| | |
|
| | | public String encodeSchemaColumnName(String columnName) {
|
| | | return "\"" + columnName + "\"";
|
| | | }
|
| | |
|
| | | protected void bindFeatureParameters(PreparedStatement pstmt, SimpleFeature feature) throws SQLException {
|
| | | SimpleFeatureType featureType = feature.getFeatureType();
|
| | |
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | | List<Object> attributes = feature.getAttributes();
|
| | |
|
| | | for (int i = 0; i < descriptors.size(); i++) {
|
| | | if (descriptors.get(i) instanceof GeometryDescriptor) {
|
| | | pstmt.setBytes(i + 1, binaryWriter.writeBinary((Geometry) attributes.get(i)));
|
| | | } else {
|
| | | Class<?> bindingType = ((AttributeType) descriptors.get(i).getType()).getBinding();
|
| | | if (bindingType.equals(Short.class)) {
|
| | | pstmt.setShort(i + 1, (Short) attributes.get(i));
|
| | | } else if (bindingType.equals(Integer.class)) {
|
| | | pstmt.setInt(i + 1, (Short) attributes.get(i));
|
| | | } else if (bindingType.equals(Long.class)) {
|
| | | pstmt.setLong(i + 1, (Long) attributes.get(i));
|
| | | } else if (bindingType.equals(String.class)) {
|
| | | pstmt.setString(i + 1, (String) attributes.get(i));
|
| | | } else if (bindingType.equals(Float.class)) {
|
| | | pstmt.setFloat(i + 1, (Float) attributes.get(i));
|
| | | } else if (bindingType.equals(Double.class)) {
|
| | | pstmt.setDouble(i + 1, (Double) attributes.get(i));
|
| | | } else if (bindingType.equals(Boolean.class)) {
|
| | | pstmt.setBoolean(i + 1, (Boolean) attributes.get(i));
|
| | | } else if (bindingType.equals(BigDecimal.class)) {
|
| | | pstmt.setBigDecimal(i + 1, (BigDecimal) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Date.class)) {
|
| | | pstmt.setDate(i + 1, (java.sql.Date) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Time.class)) {
|
| | | pstmt.setTime(i + 1, (java.sql.Time) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Timestamp.class)) {
|
| | | pstmt.setTimestamp(i + 1, (java.sql.Timestamp) attributes.get(i));
|
| | | } else if (bindingType.equals(java.util.Date.class)) {
|
| | | java.sql.Date sDate = new java.sql.Date(((java.util.Date) attributes.get(i)).getTime());
|
| | | pstmt.setDate(i + 1, sDate);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.sql.Connection;
|
| | | import java.sql.DatabaseMetaData;
|
| | | import java.sql.PreparedStatement;
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.*;
|
| | |
|
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil;
|
| | | import org.geotools.data.DataSourceException;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.SchemaNotFoundException;
|
| | | import org.geotools.data.edbgeo.PostgisDataStore;
|
| | | import org.geotools.filter.LengthFunction;
|
| | | import org.geotools.referencing.NamedIdentifier;
|
| | | import org.geotools.referencing.crs.DefaultGeographicCRS;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import org.opengis.feature.type.AttributeDescriptor;
|
| | | import org.opengis.feature.type.AttributeType;
|
| | | import org.opengis.feature.type.GeometryDescriptor;
|
| | | import org.opengis.feature.type.PropertyType;
|
| | | import org.opengis.filter.BinaryComparisonOperator;
|
| | | import org.opengis.filter.Filter;
|
| | | import org.opengis.filter.PropertyIsLessThan;
|
| | | import org.opengis.filter.PropertyIsLessThanOrEqualTo;
|
| | | 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.AbstractOracleJobContext;
|
| | | import com.ximple.eofms.util.postjts.JtsBinaryWriter;
|
| | |
|
| | | public abstract class AbstractOracleToEdbGeoJobContext extends AbstractOracleJobContext {
|
| | | private static Map<String, Class> GEOM_TYPE_MAP = new HashMap<String, Class>();
|
| | | private static Map<String, Class> GEOM3D_TYPE_MAP = new HashMap<String, Class>();
|
| | |
|
| | | static {
|
| | | GEOM_TYPE_MAP.put("GEOMETRY", Geometry.class);
|
| | | GEOM_TYPE_MAP.put("POINT", Point.class);
|
| | | GEOM_TYPE_MAP.put("LINESTRING", LineString.class);
|
| | | GEOM_TYPE_MAP.put("POLYGON", Polygon.class);
|
| | | GEOM_TYPE_MAP.put("MULTIPOINT", MultiPoint.class);
|
| | | GEOM_TYPE_MAP.put("MULTILINESTRING", MultiLineString.class);
|
| | | GEOM_TYPE_MAP.put("MULTIPOLYGON", MultiPolygon.class);
|
| | | GEOM_TYPE_MAP.put("GEOMETRYCOLLECTION", GeometryCollection.class);
|
| | |
|
| | | GEOM3D_TYPE_MAP.put("POINTM", Point.class);
|
| | | GEOM3D_TYPE_MAP.put("LINESTRINGM", LineString.class);
|
| | | GEOM3D_TYPE_MAP.put("POLYGONM", Polygon.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTIPOINTM", MultiPoint.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTILINESTRINGM", MultiLineString.class);
|
| | | GEOM3D_TYPE_MAP.put("MULTIPOLYGONM", MultiPolygon.class);
|
| | | GEOM3D_TYPE_MAP.put("GEOMETRYCOLLECTIONM", GeometryCollection.class);
|
| | | }
|
| | |
|
| | | private static Map<Class, String> CLASS_MAPPINGS = new HashMap<Class, String>();
|
| | |
|
| | | static {
|
| | | CLASS_MAPPINGS.put(String.class, "VARCHAR");
|
| | |
|
| | | CLASS_MAPPINGS.put(Boolean.class, "BOOLEAN");
|
| | |
|
| | | CLASS_MAPPINGS.put(Short.class, "SMALLINT");
|
| | | CLASS_MAPPINGS.put(Integer.class, "INTEGER");
|
| | | CLASS_MAPPINGS.put(Long.class, "BIGINT");
|
| | |
|
| | | CLASS_MAPPINGS.put(Float.class, "REAL");
|
| | | CLASS_MAPPINGS.put(Double.class, "DOUBLE PRECISION");
|
| | |
|
| | | CLASS_MAPPINGS.put(BigDecimal.class, "DECIMAL");
|
| | |
|
| | | CLASS_MAPPINGS.put(java.sql.Date.class, "DATE");
|
| | | CLASS_MAPPINGS.put(java.util.Date.class, "DATE");
|
| | | CLASS_MAPPINGS.put(java.sql.Time.class, "TIME");
|
| | | CLASS_MAPPINGS.put(java.sql.Timestamp.class, "TIMESTAMP");
|
| | | }
|
| | |
|
| | | private static Map<Class, String> GEOM_CLASS_MAPPINGS = new HashMap<Class, String>();
|
| | |
|
| | | //why don't we just stick this in with the non-geom class mappings?
|
| | | static {
|
| | | // init the inverse map
|
| | | Set keys = GEOM_TYPE_MAP.keySet();
|
| | |
|
| | | for (Object key : keys) {
|
| | | String name = (String) key;
|
| | | Class geomClass = GEOM_TYPE_MAP.get(name);
|
| | | GEOM_CLASS_MAPPINGS.put(geomClass, name);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Maximum string size for postgres
|
| | | */
|
| | | private static final int MAX_ALLOWED_VALUE = 10485760;
|
| | |
|
| | | // protected static final int BATCHSIZE = 512;
|
| | | protected static final int BATCHSIZE = 128;
|
| | |
|
| | | /**
|
| | | * Well Known Text writer (from JTS).
|
| | | */
|
| | | protected static WKTWriter geometryWriter = new WKTWriter();
|
| | | protected static JtsBinaryWriter binaryWriter = new JtsBinaryWriter();
|
| | |
|
| | | protected boolean schemaEnabled = true;
|
| | |
|
| | | private PostgisDataStore targetDataStore;
|
| | | private String targetSchema = "public";
|
| | |
|
| | | public AbstractOracleToEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | boolean profileMode, boolean useTransform) {
|
| | | super(profileMode, useTransform);
|
| | | if ((targetDataStore != null) && (targetDataStore instanceof PostgisDataStore)) {
|
| | | this.targetDataStore = (PostgisDataStore) targetDataStore;
|
| | | } else {
|
| | | getLogger().info("targetDataStore has wrong.");
|
| | | }
|
| | | setDataPath(dataPath);
|
| | | setTargetSchema(targetSchema);
|
| | | }
|
| | |
|
| | | public PostgisDataStore getTargetDataStore() {
|
| | | return targetDataStore;
|
| | | }
|
| | |
|
| | | public void setTargetDataStore(PostgisDataStore targetDataStore) {
|
| | | this.targetDataStore = targetDataStore;
|
| | | }
|
| | |
|
| | | public String getTargetSchema() {
|
| | | return targetSchema;
|
| | | }
|
| | |
|
| | | public void setTargetSchema(String schemaName) {
|
| | | targetSchema = schemaName;
|
| | | }
|
| | |
|
| | | public Connection getConnection() {
|
| | | if (targetDataStore != null) {
|
| | | try {
|
| | | return targetDataStore.getDataSource().getConnection();
|
| | | } catch (SQLException e) {
|
| | | getLogger().warn(e.getMessage(), e);
|
| | | return null;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | protected boolean isExistFeature(SimpleFeatureType featureType) {
|
| | | try {
|
| | | SimpleFeatureType existFeatureType = targetDataStore.getSchema(featureType.getTypeName());
|
| | | return existFeatureType != null; // && existFeatureType.equals(featureType);
|
| | | } catch (SchemaNotFoundException e) {
|
| | | return false;
|
| | | } catch (IOException e) {
|
| | | getLogger().info(e.getMessage(), e);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | protected void deleteTable(Connection conn, String schemaName, String tableName) throws SQLException {
|
| | | Statement stmt = conn.createStatement();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("DELETE FROM \"");
|
| | | sb.append(schemaName);
|
| | | sb.append("\".\"");
|
| | | sb.append(tableName);
|
| | | sb.append('\"');
|
| | | stmt.execute(sb.toString());
|
| | | stmt.close();
|
| | | conn.commit();
|
| | | }
|
| | |
|
| | | protected void dropTable(Connection conn, String schemaName, String tableName) throws SQLException {
|
| | | Statement stmt = conn.createStatement();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("DROP TABLE \"");
|
| | | sb.append(schemaName);
|
| | | sb.append("\".\"");
|
| | | sb.append(tableName);
|
| | | sb.append("\"");
|
| | | // sb.append(" CASCADE");
|
| | | stmt.execute(sb.toString());
|
| | | stmt.close();
|
| | | conn.commit();
|
| | | }
|
| | |
|
| | | protected void 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(dbSchema);
|
| | | sb.append("','");
|
| | | sb.append(tableName);
|
| | | sb.append("','");
|
| | | sb.append(geomField);
|
| | | sb.append("')");
|
| | | stmt.execute(sb.toString());
|
| | | stmt.close();
|
| | | conn.commit();
|
| | | }
|
| | |
|
| | | protected String dropGeometryColumn(String dbSchema, String tableName, String geomField) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("SELECT \"public\".DropGeometryColumn('");
|
| | | sb.append(dbSchema);
|
| | | sb.append("','");
|
| | | sb.append(tableName);
|
| | | sb.append("','");
|
| | | sb.append(geomField);
|
| | | sb.append("')");
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | private String addGeometryColumn(String dbSchema, String tableName, GeometryDescriptor geometryDescriptor, int srid) {
|
| | | StringBuilder sql;
|
| | | String typeName = getGeometrySQLTypeName(((PropertyType)geometryDescriptor.getType()).getBinding());
|
| | | if (typeName == null) {
|
| | | getLogger().warn("Error: " + geometryDescriptor.getLocalName() + " unknown type!!!");
|
| | | throw new RuntimeException("Error: " + geometryDescriptor.getLocalName() + " unknown type!!!");
|
| | | }
|
| | |
|
| | | sql = new StringBuilder("SELECT \"public\".AddGeometryColumn('");
|
| | | sql.append(dbSchema);
|
| | | sql.append("','");
|
| | | sql.append(tableName);
|
| | | sql.append("','");
|
| | | sql.append(geometryDescriptor.getLocalName());
|
| | | sql.append("','");
|
| | | sql.append(srid);
|
| | | sql.append("','");
|
| | | sql.append(typeName);
|
| | | sql.append("', 2);");
|
| | |
|
| | | //prints statement for later reuse
|
| | | return sql.toString();
|
| | | }
|
| | |
|
| | | public ArrayList<String> createNewSchemaTexts(Connection conn, SimpleFeatureType featureType) throws IOException {
|
| | | String origintableName = featureType.getTypeName();
|
| | | String tableName = origintableName.toLowerCase();
|
| | |
|
| | | ArrayList<String> result = new ArrayList<String>();
|
| | |
|
| | | List<AttributeDescriptor> attributeType = featureType.getAttributeDescriptors();
|
| | | // String dbSchema = targetDataStore.getDatabaseSchemaName();
|
| | |
|
| | | boolean shouldDrop = tablePresent(getTargetSchema(), tableName, conn);
|
| | | if (shouldDrop) {
|
| | | String sqlStr;
|
| | | for (AttributeDescriptor descriptor : attributeType) {
|
| | | if (!(descriptor instanceof GeometryDescriptor)) {
|
| | | continue;
|
| | | }
|
| | | GeometryDescriptor geomAttribute = (GeometryDescriptor) descriptor;
|
| | | sqlStr = dropGeometryColumn(getTargetSchema(), tableName, geomAttribute.getLocalName());
|
| | | getLogger().info(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | | // sqlStr = "DROP TABLE " + encodeSchemaTableName(tableName) + " CASCADE;";
|
| | | sqlStr = "DROP TABLE " + encodeSchemaTableName(tableName) + " ;";
|
| | | getLogger().info(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | |
|
| | | StringBuilder sql = new StringBuilder("CREATE TABLE ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" ( gid serial PRIMARY KEY, ");
|
| | | sql.append(makeNonGeomSqlCreate(attributeType));
|
| | | sql.append(");");
|
| | |
|
| | | String sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | |
|
| | | String indexName = tableName.replace('-', '_');
|
| | |
|
| | | for (AttributeDescriptor descriptor : attributeType) {
|
| | | if (!(descriptor instanceof GeometryDescriptor)) {
|
| | | String fieldName = descriptor.getLocalName().toLowerCase();
|
| | | continue;
|
| | | }
|
| | | GeometryDescriptor geomDescriptor = (GeometryDescriptor) descriptor;
|
| | |
|
| | | CoordinateReferenceSystem refSys = geomDescriptor.getCoordinateReferenceSystem();
|
| | | int SRID = getSRID(refSys);
|
| | |
|
| | | sqlStr = addGeometryColumn(getTargetSchema(), tableName, geomDescriptor, SRID);
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | |
|
| | | //also build a spatial index on each geometry column.
|
| | | sql = new StringBuilder("CREATE INDEX \"");
|
| | | sql.append("spatial_");
|
| | | sql.append(indexName);
|
| | | sql.append("_");
|
| | | sql.append(descriptor.getLocalName().toLowerCase());
|
| | | sql.append("\" ON ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" USING GIST (");
|
| | | sql.append(encodeSchemaColumnName(descriptor.getLocalName()));
|
| | | sql.append(" gist_geometry_ops);");
|
| | |
|
| | | sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | |
|
| | | if (origintableName.startsWith("fsc")) {
|
| | | sql = new StringBuilder("CREATE INDEX \"");
|
| | | sql.append("oid_");
|
| | | sql.append(indexName);
|
| | | sql.append("\" ON ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" USING BTREE (\"tid\", \"oid\")");
|
| | | sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | |
|
| | | sql = new StringBuilder("CREATE INDEX \"");
|
| | | sql.append("lvwt_");
|
| | | sql.append(indexName);
|
| | | sql.append("\" ON ");
|
| | | sql.append(encodeSchemaTableName(tableName));
|
| | | sql.append(" USING BTREE (\"level\", \"symweight\")");
|
| | | sqlStr = sql.toString();
|
| | | getLogger().debug(sqlStr);
|
| | | result.add(sqlStr);
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | private int getSRID(CoordinateReferenceSystem refSys) {
|
| | | int SRID;
|
| | | if (refSys != null) {
|
| | | try {
|
| | | Set ident = refSys.getIdentifiers();
|
| | | if ((ident == null || ident.isEmpty()) && refSys == DefaultGeographicCRS.WGS84) {
|
| | | SRID = 4326;
|
| | | } else {
|
| | | String code = ((NamedIdentifier) ident.toArray()[0]).getCode();
|
| | | SRID = Integer.parseInt(code);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | getLogger().warn("SRID could not be determined");
|
| | | SRID = -1;
|
| | | }
|
| | | } else {
|
| | | SRID = -1;
|
| | | }
|
| | | return SRID;
|
| | | }
|
| | |
|
| | | private boolean tablePresent(String schema, String table, Connection conn) throws IOException {
|
| | | final int TABLE_NAME_COL = 3;
|
| | |
|
| | | ResultSet tables = null;
|
| | | try {
|
| | | DatabaseMetaData meta = conn.getMetaData();
|
| | | String[] tableType = {"TABLE"};
|
| | | tables = meta.getTables(null, schema, "%", tableType);
|
| | |
|
| | | while (tables.next()) {
|
| | | String tableName = tables.getString(TABLE_NAME_COL);
|
| | |
|
| | | if (allowTable(tableName) && (tableName != null)
|
| | | && (tableName.equalsIgnoreCase(table))) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | |
|
| | | return false;
|
| | | } catch (SQLException sqlException) {
|
| | | // JDBCUtils.close(conn, Transaction.AUTO_COMMIT, sqlException);
|
| | | String message = "Error querying database for list of tables:"
|
| | | + sqlException.getMessage();
|
| | | throw new DataSourceException(message, sqlException);
|
| | | } finally {
|
| | | if (tables != null) try {
|
| | | tables.close();
|
| | | } catch (SQLException e) {
|
| | | }
|
| | | // JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | }
|
| | | }
|
| | |
|
| | | protected boolean allowTable(String tablename) {
|
| | | if (tablename.equals("geometry_columns")) {
|
| | | return false;
|
| | | } else if (tablename.startsWith("spatial_ref_sys")) {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //others?
|
| | | return true;
|
| | | }
|
| | |
|
| | |
|
| | | private StringBuffer makeNonGeomSqlCreate(List<AttributeDescriptor> descriptors)
|
| | | throws IOException {
|
| | | StringBuffer buf = new StringBuffer("");
|
| | |
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | String typeName;
|
| | | typeName = CLASS_MAPPINGS.get(((PropertyType) descriptor.getType()).getBinding());
|
| | | if (typeName == null) {
|
| | | typeName = GEOM_CLASS_MAPPINGS.get(((PropertyType) descriptor.getType()).getBinding());
|
| | | if (typeName != null) continue;
|
| | | }
|
| | |
|
| | | if (typeName != null) {
|
| | | if (typeName.equals("VARCHAR")) {
|
| | | int length = -1;
|
| | | List<Filter> flist = ((PropertyType) descriptor.getType()).getRestrictions();
|
| | | for (Filter f : flist) {
|
| | | if (f != null && f != Filter.EXCLUDE && f != Filter.INCLUDE &&
|
| | | (f instanceof PropertyIsLessThan || f instanceof PropertyIsLessThanOrEqualTo)) {
|
| | | try {
|
| | | BinaryComparisonOperator cf = (BinaryComparisonOperator) f;
|
| | | if (cf.getExpression1() instanceof LengthFunction) {
|
| | | length = Integer.parseInt(((Literal) cf.getExpression2()).getValue().toString());
|
| | | } else {
|
| | | if (cf.getExpression2() instanceof LengthFunction) {
|
| | | length = Integer.parseInt(((Literal) cf.getExpression1()).getValue().toString());
|
| | | }
|
| | | }
|
| | | } catch (NumberFormatException e) {
|
| | | length = 512;
|
| | | }
|
| | | } else {
|
| | | length = 512;
|
| | | }
|
| | | break;
|
| | | }
|
| | |
|
| | | if (length < 1) {
|
| | | getLogger().info("FeatureType did not specify string length; defaulted to 512");
|
| | | length = 512;
|
| | | } else if (length > MAX_ALLOWED_VALUE) {
|
| | | length = MAX_ALLOWED_VALUE;
|
| | | }
|
| | | typeName = typeName + "(" + length + ")";
|
| | | }
|
| | |
|
| | | if (!descriptor.isNillable()) {
|
| | | typeName = typeName + " NOT NULL";
|
| | | }
|
| | |
|
| | | //TODO review!!! Is toString() always OK???
|
| | | Object defaultValue = descriptor.getDefaultValue();
|
| | |
|
| | | if (defaultValue != null) {
|
| | | typeName = typeName + " DEFAULT '"
|
| | | + defaultValue.toString() + "'";
|
| | | }
|
| | |
|
| | | buf.append(" \"").append(descriptor.getLocalName()).append("\" ").append(typeName).append(",");
|
| | |
|
| | | } else {
|
| | | String msg;
|
| | | if (descriptor == null) {
|
| | | msg = "AttributeType was null!";
|
| | | } else {
|
| | | msg = "Type '" + ((PropertyType) descriptor.getType()).getBinding() + "' not supported!";
|
| | | }
|
| | | throw (new IOException(msg));
|
| | | }
|
| | | }
|
| | |
|
| | | return buf.deleteCharAt(buf.length() - 1);
|
| | | }
|
| | |
|
| | | private String getGeometrySQLTypeName(Class type) {
|
| | | String res = GEOM_CLASS_MAPPINGS.get(type);
|
| | |
|
| | | if (res == null) {
|
| | | throw new RuntimeException("Unknown type name for class " + type
|
| | | + " please update GEOMETRY_MAPPINGS");
|
| | | }
|
| | |
|
| | | return res;
|
| | | }
|
| | |
|
| | | protected String getGeometryInsertText(Geometry geom, int srid) // throws IOException
|
| | | {
|
| | | if (geom == null) {
|
| | | return "null";
|
| | | }
|
| | |
|
| | | if (targetDataStore.isWKBEnabled()) {
|
| | | //String wkb = WKBEncoder.encodeGeometryHex(geom);
|
| | | String wkb = WKBWriter.bytesToHex(new WKBWriter().write(geom));
|
| | |
|
| | | if (targetDataStore.isByteaWKB()) {
|
| | | return "setSRID('" + wkb + "'::geometry," + srid + ")";
|
| | | } else {
|
| | | return "GeomFromWKB('" + wkb + "', " + srid + ")";
|
| | | }
|
| | | }
|
| | |
|
| | | String geoText = geometryWriter.write(geom);
|
| | |
|
| | | return "GeometryFromText('" + geoText + "', " + srid + ")";
|
| | | }
|
| | |
|
| | | protected String makeInsertSql(SimpleFeature feature, int srid) // throws IOException
|
| | | {
|
| | | SimpleFeatureType featureType = feature.getFeatureType();
|
| | |
|
| | | String tableName = encodeSchemaTableName(featureType.getTypeName());
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | |
|
| | | String attrValue;
|
| | |
|
| | | StringBuilder statementSQL = new StringBuilder(512);
|
| | | statementSQL.append("INSERT INTO ").append(tableName).append(" (");
|
| | |
|
| | | // encode insertion for attributes, but remember to avoid auto-increment ones,
|
| | | // they may be included in the feature type as well
|
| | | for (AttributeDescriptor attributeDescriptor : descriptors) {
|
| | | String attName = attributeDescriptor.getLocalName();
|
| | |
|
| | | if (feature.getAttribute(attName) != null) {
|
| | | String colName = encodeSchemaColumnName(attName);
|
| | | statementSQL.append(colName).append(",");
|
| | | }
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | | statementSQL.append(" VALUES (");
|
| | |
|
| | | List<Object> attributes = feature.getAttributes();
|
| | |
|
| | | for (int i = 0; i < descriptors.size(); i++) {
|
| | | attrValue = null;
|
| | |
|
| | | if (descriptors.get(i) instanceof GeometryDescriptor) {
|
| | | // String geomName = descriptors[i].getLocalName();
|
| | | // int srid = ftInfo.getSRID(geomName);
|
| | | Geometry geometry = (Geometry) attributes.get(i);
|
| | |
|
| | | if (geometry == null) {
|
| | | attrValue = "NULL";
|
| | | } else {
|
| | | attrValue = getGeometryInsertText(geometry, srid);
|
| | | }
|
| | | } else {
|
| | | if (attributes.get(i) != null) {
|
| | | attrValue = addQuotes(attributes.get(i));
|
| | | }
|
| | | }
|
| | |
|
| | | if (attrValue != null) {
|
| | | statementSQL.append(attrValue).append(",");
|
| | | }
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | |
|
| | | return (statementSQL.toString());
|
| | | }
|
| | |
|
| | | protected String makePrepareInsertSql(SimpleFeatureType featureType) {
|
| | | String tableName = encodeSchemaTableName(featureType.getTypeName());
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | |
|
| | | String attrValue;
|
| | |
|
| | | StringBuilder statementSQL = new StringBuilder("INSERT INTO " + tableName + " (");
|
| | |
|
| | | // encode insertion for attributes, but remember to avoid auto-increment ones,
|
| | | // they may be included in the feature type as well
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | String attName = descriptor.getLocalName();
|
| | |
|
| | | String colName = encodeSchemaColumnName(attName);
|
| | | statementSQL.append(colName).append(",");
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | | statementSQL.append(" VALUES (");
|
| | |
|
| | | for (AttributeDescriptor descriptor : descriptors) {
|
| | | statementSQL.append(" ? ,");
|
| | | }
|
| | |
|
| | | statementSQL.setCharAt(statementSQL.length() - 1, ')');
|
| | |
|
| | | return (statementSQL.toString());
|
| | | }
|
| | |
|
| | | protected String addQuotes(Object value) {
|
| | | String retString;
|
| | |
|
| | | if (value != null) {
|
| | | if (value instanceof Number) {
|
| | | retString = value.toString();
|
| | | } else {
|
| | | retString = "'" + doubleQuote(value) + "'";
|
| | | }
|
| | | } else {
|
| | | retString = "null";
|
| | | }
|
| | |
|
| | | return retString;
|
| | | }
|
| | |
|
| | | String doubleQuote(Object obj) {
|
| | | return obj.toString().replaceAll("'", "''");
|
| | | }
|
| | |
|
| | | protected String encodeName(String tableName) {
|
| | | return tableName;
|
| | | }
|
| | |
|
| | | protected String encodeColumnName(String colName) {
|
| | | return encodeName(colName);
|
| | | }
|
| | |
|
| | | public String encodeSchemaTableName(String tableName) {
|
| | | return schemaEnabled ? ("\"" + getTargetSchema() + "\".\"" + tableName + "\"")
|
| | | : ("\"" + tableName + "\"");
|
| | | }
|
| | |
|
| | | public String encodeSchemaColumnName(String columnName) {
|
| | | return "\"" + columnName + "\"";
|
| | | }
|
| | |
|
| | | protected void bindFeatureParameters(PreparedStatement pstmt, SimpleFeature feature) throws SQLException {
|
| | | SimpleFeatureType featureType = feature.getFeatureType();
|
| | |
|
| | | List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
|
| | | List<Object> attributes = feature.getAttributes();
|
| | |
|
| | | for (int i = 0; i < descriptors.size(); i++) {
|
| | | if (descriptors.get(i) instanceof GeometryDescriptor) {
|
| | | // String wktTest = geometryWriter.write((Geometry) attributes.get(i));
|
| | | Geometry geom = (Geometry) attributes.get(i);
|
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID());
|
| | | pstmt.setBytes(i + 1, binaryWriter.writeBinary((Geometry) attributes.get(i)));
|
| | | } else {
|
| | | Class<?> bindingType = ((AttributeType)descriptors.get(i).getType()).getBinding();
|
| | | if (bindingType.equals(Short.class)) {
|
| | | pstmt.setShort(i + 1, (Short) attributes.get(i));
|
| | | } else if (bindingType.equals(Integer.class)) {
|
| | | pstmt.setInt(i + 1, (Short) attributes.get(i));
|
| | | } else if (bindingType.equals(Long.class)) {
|
| | | pstmt.setLong(i + 1, (Long) attributes.get(i));
|
| | | } else if (bindingType.equals(String.class)) {
|
| | | pstmt.setString(i + 1, (String) attributes.get(i));
|
| | | } else if (bindingType.equals(Float.class)) {
|
| | | pstmt.setFloat(i + 1, (Float) attributes.get(i));
|
| | | } else if (bindingType.equals(Double.class)) {
|
| | | pstmt.setDouble(i + 1, (Double) attributes.get(i));
|
| | | } else if (bindingType.equals(Boolean.class)) {
|
| | | pstmt.setBoolean(i + 1, (Boolean) attributes.get(i));
|
| | | } else if (bindingType.equals(BigDecimal.class)) {
|
| | | pstmt.setBigDecimal(i + 1, (BigDecimal) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Date.class)) {
|
| | | pstmt.setDate(i + 1, (java.sql.Date) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Time.class)) {
|
| | | pstmt.setTime(i + 1, (java.sql.Time) attributes.get(i));
|
| | | } else if (bindingType.equals(java.sql.Timestamp.class)) {
|
| | | pstmt.setTimestamp(i + 1, (java.sql.Timestamp) attributes.get(i));
|
| | | } else if (bindingType.equals(java.util.Date.class)) {
|
| | | java.sql.Date sDate = new java.sql.Date(((java.util.Date) attributes.get(i)).getTime());
|
| | | pstmt.setDate(i + 1, sDate);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.net.MalformedURLException;
|
| | | import java.net.URL;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.commons.digester.Digester;
|
| | | import org.apache.commons.digester.xmlrules.DigesterLoader;
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper;
|
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger;
|
| | | import org.apache.commons.transaction.util.LoggerFacade;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.FeatureWriter;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.feature.IllegalAttributeException;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import org.xml.sax.SAXException;
|
| | |
|
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter;
|
| | | import com.ximple.eofms.filter.ElementDispatchableFilter;
|
| | | import com.ximple.eofms.filter.ElementDispatcher;
|
| | | import com.ximple.eofms.filter.TypeCompIdDispatchableFilter;
|
| | | import com.ximple.eofms.filter.TypeCompLevelIdDispatchableFilter;
|
| | | import com.ximple.eofms.filter.TypeIdDispatchableFilter;
|
| | | import com.ximple.io.dgn7.ComplexElement;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.FrammeAttributeData;
|
| | | import com.ximple.io.dgn7.UserAttributeData;
|
| | |
|
| | | public class DummyFeatureConvertEdbGeoJobContext extends AbstractDgnToEdbGeoJobContext {
|
| | | static final Log logger = LogFactory.getLog(DummyFeatureConvertEdbGeoJobContext.class);
|
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
|
| | |
|
| | | private String dataOut = null;
|
| | |
|
| | | private HashMap<String, ArrayList<SimpleFeature>> featuresContext = new HashMap<String, ArrayList<SimpleFeature>>();
|
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>();
|
| | |
|
| | | private PessimisticMapWrapper txFeaturesContext;
|
| | |
|
| | | private ElementDispatcher elementDispatcher;
|
| | | private String _filterConfig;
|
| | | private boolean withIndex = false;
|
| | |
|
| | | public DummyFeatureConvertEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | String filterConfig, boolean profileMode,
|
| | | boolean useTransform) {
|
| | | super(dataPath, targetDataStore, targetSchema, profileMode, useTransform);
|
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger);
|
| | | _filterConfig = filterConfig;
|
| | | elementDispatcher = createElementDispatcher();
|
| | | }
|
| | |
|
| | | private ElementDispatcher createElementDispatcher() {
|
| | | try {
|
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml");
|
| | | assert rulesURL != null;
|
| | | Digester digester = DigesterLoader.createDigester(rulesURL);
|
| | | URL filterURL = null;
|
| | | if (_filterConfig != null) {
|
| | | File config = new File(_filterConfig);
|
| | | if (config.exists()) {
|
| | | filterURL = config.toURI().toURL();
|
| | | }
|
| | | }
|
| | | if (filterURL == null) {
|
| | | // config = new File("conf/DefaultConvertShpFilter.xml");
|
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml");
|
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml");
|
| | | }
|
| | | assert filterURL != null;
|
| | | return (ElementDispatcher) digester.parse(filterURL);
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (MalformedURLException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (SAXException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException {
|
| | | assert elementDispatcher != null;
|
| | |
|
| | | if (element == null) {
|
| | | logger.warn("Unknown Element:" + null);
|
| | | return;
|
| | | }
|
| | |
|
| | | // �P�_�O�_�ũM���
|
| | | SimpleFeature feature = elementDispatcher.execute(element, isTransformed());
|
| | | if (feature == null) {
|
| | | FrammeAttributeData linkage =
|
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element);
|
| | | logger.warn("Unknown Element:" + element.getElementType().toString() +
|
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" +
|
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID())));
|
| | | if (element instanceof ComplexElement) {
|
| | | ComplexElement complex = (ComplexElement) element;
|
| | | logger.warn("----Complex Element size=" + complex.size());
|
| | | }
|
| | |
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList());
|
| | | }
|
| | | ArrayList arrayList = (ArrayList) txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | | }
|
| | |
|
| | | public void startTransaction() {
|
| | | assert elementDispatcher != null;
|
| | | for (ElementDispatchableFilter filter : elementDispatcher.getRules()) {
|
| | | if (filter instanceof TypeCompIdDispatchableFilter) {
|
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy();
|
| | | } else if (filter instanceof TypeCompLevelIdDispatchableFilter) {
|
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy();
|
| | | } else if (filter instanceof TypeIdDispatchableFilter) {
|
| | | ((TypeCompIdDispatchableFilter) filter).getCreateStrategy();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void commitTransaction() {
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | logger.debug("Transaction size = " + txFeaturesContext.size());
|
| | | //txFeaturesContext.commitTransaction();
|
| | | } else {
|
| | | logger.debug("Transaction is empty.");
|
| | | }
|
| | |
|
| | | if (!featuresContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | public void rollbackTransaction() {
|
| | | //txFeaturesContext.rollbackTransaction();
|
| | | if (!featuresContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | private void updateDataStore() {
|
| | | Iterator it = featuresContext.keySet().iterator();
|
| | |
|
| | | try {
|
| | | while (it.hasNext()) {
|
| | | SimpleFeatureType featureType = (SimpleFeatureType) it.next();
|
| | | logger.debug("Begin Save EdbGeo:" + featureType.getTypeName());
|
| | |
|
| | | FeatureWriter writer;
|
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) {
|
| | | writer = featuresWriterContext.get(featureType.getTypeName());
|
| | | } else {
|
| | | if (!isExistFeature(featureType)) {
|
| | | getTargetDataStore().createSchema(featureType);
|
| | | writer = getTargetDataStore().getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT);
|
| | | } else {
|
| | | writer = getTargetDataStore().getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT);
|
| | | }
|
| | | featuresWriterContext.put(featureType.getTypeName(), writer);
|
| | | }
|
| | |
|
| | | ArrayList<SimpleFeature> features = featuresContext.get(featureType);
|
| | | Iterator itFeature = features.iterator();
|
| | | while (itFeature.hasNext()) {
|
| | | SimpleFeature feature = (SimpleFeature) itFeature.next();
|
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes());
|
| | | }
|
| | | //writer.close();
|
| | | logger.debug("End Save EdbGeo:" + featureType.getTypeName());
|
| | | }
|
| | | featuresContext.clear();
|
| | | } catch (MalformedURLException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (IllegalAttributeException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | public void closeFeatureWriter() throws IOException {
|
| | |
|
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) {
|
| | | featureWriter.close();
|
| | | }
|
| | |
|
| | | this.featuresWriterContext.clear();
|
| | | }
|
| | |
|
| | | protected FrammeAttributeData getFeatureLinkage(Element element) {
|
| | | if (!element.hasUserAttributeData())
|
| | | return null;
|
| | |
|
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData();
|
| | | for (UserAttributeData anUsrData : usrDatas) {
|
| | | if (anUsrData instanceof FrammeAttributeData) {
|
| | | return (FrammeAttributeData) anUsrData;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | public boolean isWithIndex() {
|
| | | return withIndex;
|
| | | }
|
| | |
|
| | | public void setWithIndex(boolean withIndex) {
|
| | | this.withIndex = withIndex;
|
| | | }
|
| | |
|
| | | public Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.net.MalformedURLException;
|
| | | import java.net.URL;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.commons.digester.Digester;
|
| | | import org.apache.commons.digester.xmlrules.DigesterLoader;
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.apache.commons.transaction.memory.PessimisticMapWrapper;
|
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger;
|
| | | import org.apache.commons.transaction.util.LoggerFacade;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.FeatureWriter;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.feature.IllegalAttributeException;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import org.xml.sax.SAXException;
|
| | |
|
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter;
|
| | | import com.ximple.eofms.filter.ElementDispatcher;
|
| | | import com.ximple.io.dgn7.ComplexElement;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.FrammeAttributeData;
|
| | | import com.ximple.io.dgn7.UserAttributeData;
|
| | |
|
| | | public class FeatureDgnConvertEdbGeoJobContext extends AbstractDgnToEdbGeoJobContext {
|
| | | static final Log logger = LogFactory.getLog(FeatureDgnConvertEdbGeoJobContext.class);
|
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
|
| | |
|
| | | private HashMap<String, ArrayList<SimpleFeature>> featuresContext = new HashMap<String, ArrayList<SimpleFeature>>();
|
| | | private HashMap<String, FeatureWriter> featuresWriterContext = new HashMap<String, FeatureWriter>();
|
| | |
|
| | | private PessimisticMapWrapper txFeaturesContext;
|
| | |
|
| | | private ElementDispatcher elementDispatcher;
|
| | | private String _filterConfig;
|
| | | private boolean withIndex = false;
|
| | |
|
| | | public FeatureDgnConvertEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | String filterConfig, boolean profileMode,
|
| | | boolean useTransform) {
|
| | | super(dataPath, targetDataStore, targetSchema, profileMode, useTransform);
|
| | | txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger);
|
| | | _filterConfig = filterConfig;
|
| | | elementDispatcher = createElementDispatcher();
|
| | | }
|
| | |
|
| | | private ElementDispatcher createElementDispatcher() {
|
| | | try {
|
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml");
|
| | | assert rulesURL != null;
|
| | | Digester digester = DigesterLoader.createDigester(rulesURL);
|
| | | URL filterURL = null;
|
| | | if (_filterConfig != null) {
|
| | | File config = new File(_filterConfig);
|
| | | if (config.exists()) {
|
| | | filterURL = config.toURI().toURL();
|
| | | }
|
| | | }
|
| | | if (filterURL == null) {
|
| | | // config = new File("conf/DefaultConvertShpFilter.xml");
|
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml");
|
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml");
|
| | | }
|
| | | assert filterURL != null;
|
| | | return (ElementDispatcher) digester.parse(filterURL);
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (MalformedURLException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (SAXException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException {
|
| | | assert elementDispatcher != null;
|
| | |
|
| | | if (element == null) {
|
| | | logger.warn("Unknown Element:" + null);
|
| | | return;
|
| | | }
|
| | |
|
| | | // �P�_�O�_�ũM���
|
| | | SimpleFeature feature = elementDispatcher.execute(element, isTransformed());
|
| | | if (feature == null) {
|
| | | FrammeAttributeData linkage =
|
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element);
|
| | | logger.warn("Unknown Element:" + element.getElementType().toString() +
|
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" +
|
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID())));
|
| | | if (element instanceof ComplexElement) {
|
| | | ComplexElement complex = (ComplexElement) element;
|
| | | logger.warn("----Complex Element size=" + complex.size());
|
| | | }
|
| | |
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList());
|
| | | }
|
| | | ArrayList<SimpleFeature> arrayList = (ArrayList<SimpleFeature>) txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | | }
|
| | |
|
| | | public void startTransaction() {
|
| | | }
|
| | |
|
| | | public void commitTransaction() {
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | logger.debug("Transaction size = " + txFeaturesContext.size());
|
| | | //txFeaturesContext.commitTransaction();
|
| | | } else {
|
| | | logger.debug("Transaction is empty.");
|
| | | }
|
| | |
|
| | | if (!featuresContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | public void rollbackTransaction() {
|
| | | //txFeaturesContext.rollbackTransaction();
|
| | | if (!featuresContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | private void updateDataStore() {
|
| | | Iterator it = featuresContext.keySet().iterator();
|
| | |
|
| | | try {
|
| | | while (it.hasNext()) {
|
| | | SimpleFeatureType featureType = (SimpleFeatureType) it.next();
|
| | | logger.debug("Begin Save EdbGeo:" + featureType.getTypeName());
|
| | |
|
| | | FeatureWriter writer;
|
| | | if (featuresWriterContext.containsKey(featureType.getTypeName())) {
|
| | | writer = featuresWriterContext.get(featureType.getTypeName());
|
| | | } else {
|
| | | if (!isExistFeature(featureType)) {
|
| | | getTargetDataStore().createSchema(featureType);
|
| | | writer = getTargetDataStore().getFeatureWriter(featureType.getTypeName(),
|
| | | Transaction.AUTO_COMMIT);
|
| | | } else {
|
| | | writer = getTargetDataStore().getFeatureWriterAppend(featureType.getTypeName(),
|
| | | Transaction.AUTO_COMMIT);
|
| | | }
|
| | | featuresWriterContext.put(featureType.getTypeName(), writer);
|
| | | }
|
| | |
|
| | | ArrayList<SimpleFeature> features = featuresContext.get(featureType);
|
| | | Iterator itFeature = features.iterator();
|
| | | while (itFeature.hasNext()) {
|
| | | SimpleFeature feature = (SimpleFeature) itFeature.next();
|
| | | ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes());
|
| | | }
|
| | | //writer.close();
|
| | | logger.debug("End Save EdbGeo:" + featureType.getTypeName());
|
| | | }
|
| | | featuresContext.clear();
|
| | | } catch (MalformedURLException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (IllegalAttributeException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.error(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | public void closeFeatureWriter() {
|
| | | this.featuresWriterContext.clear();
|
| | |
|
| | | try {
|
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values()) {
|
| | | featureWriter.close();
|
| | | }
|
| | | } catch (IOException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | |
|
| | | this.featuresWriterContext.clear();
|
| | | }
|
| | |
|
| | | protected FrammeAttributeData getFeatureLinkage(Element element) {
|
| | | if (!element.hasUserAttributeData())
|
| | | return null;
|
| | |
|
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData();
|
| | | for (UserAttributeData anUsrData : usrDatas) {
|
| | | if (anUsrData instanceof FrammeAttributeData) {
|
| | | return (FrammeAttributeData) anUsrData;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | public boolean isWithIndex() {
|
| | | return withIndex;
|
| | | }
|
| | |
|
| | | public void setWithIndex(boolean withIndex) {
|
| | | this.withIndex = withIndex;
|
| | | }
|
| | |
|
| | | public Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.sql.Connection;
|
| | | import java.sql.PreparedStatement;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.TreeMap;
|
| | |
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger;
|
| | | import org.apache.commons.transaction.util.LoggerFacade;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.data.jdbc.JDBCUtils;
|
| | | import org.geotools.feature.IllegalAttributeException;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.geotools.feature.simple.SimpleFeatureBuilder;
|
| | | import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
| | | import org.geotools.feature.type.FeatureTypeImpl;
|
| | | import org.geotools.geometry.jts.JTSFactoryFinder;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import com.edb.util.PSQLException;
|
| | |
|
| | | import com.vividsolutions.jts.geom.Geometry;
|
| | | import com.vividsolutions.jts.geom.GeometryFactory;
|
| | |
|
| | | import com.ximple.eofms.util.DefaultColorTable;
|
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil;
|
| | | import com.ximple.eofms.util.GeometryConverterDecorator;
|
| | | import com.ximple.io.dgn7.ArcElement;
|
| | | import com.ximple.io.dgn7.ComplexChainElement;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.EllipseElement;
|
| | | import com.ximple.io.dgn7.FrammeAttributeData;
|
| | | import com.ximple.io.dgn7.LineElement;
|
| | | import com.ximple.io.dgn7.LineStringElement;
|
| | | import com.ximple.io.dgn7.ShapeElement;
|
| | | import com.ximple.io.dgn7.TextElement;
|
| | | import com.ximple.io.dgn7.TextNodeElement;
|
| | | import com.ximple.io.dgn7.UserAttributeData;
|
| | |
|
| | | public class GeneralDgnConvertEdbGeoJobContext extends AbstractDgnToEdbGeoJobContext {
|
| | | static final Log logger = LogFactory.getLog(GeneralDgnConvertEdbGeoJobContext.class);
|
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
|
| | | static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
|
| | |
|
| | | private HashMap<SimpleFeatureType, ArrayList<SimpleFeature>> txFeaturesContext = new HashMap<SimpleFeatureType, ArrayList<SimpleFeature>>();
|
| | |
|
| | | private TreeMap<String, SimpleFeatureType> featureTypes = new TreeMap<String, SimpleFeatureType>();
|
| | |
|
| | | private GeometryConverterDecorator convertDecorator = null;
|
| | | private String featureBaseName = null;
|
| | | private boolean dropTableMode = true;
|
| | |
|
| | | private int accumulate = 0;
|
| | |
|
| | | public GeneralDgnConvertEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | boolean profileMode, boolean useTransform) {
|
| | | super(dataPath, targetDataStore, targetSchema, profileMode, useTransform);
|
| | | }
|
| | |
|
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException {
|
| | | SimpleFeatureType ft = lookupFeatureType(element);
|
| | | if (ft != null) {
|
| | | boolean canLog = true;
|
| | | SimpleFeature feature = null;
|
| | | try {
|
| | | feature = createFeature(ft, element);
|
| | | } catch (ArrayIndexOutOfBoundsException e) {
|
| | | getLogger().warn(e.getMessage(), e);
|
| | | canLog = false;
|
| | | } catch (ClassCastException e) {
|
| | | getLogger().warn(e.getMessage(), e);
|
| | | }
|
| | |
|
| | | if (feature == null) {
|
| | | if (!canLog) return;
|
| | |
|
| | | if (element instanceof TextElement)
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | ((TextElement) element).getText() + "'");
|
| | | else if (element instanceof ShapeElement)
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | ((ShapeElement) element).getVerticeSize() + "'" +
|
| | | ((ShapeElement) element).getStartPoint());
|
| | | else if (element instanceof LineStringElement)
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | ((LineStringElement) element).getVerticeSize() + "'" +
|
| | | ((LineStringElement) element).getStartPoint());
|
| | | else if (element instanceof ArcElement)
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | ((ArcElement) element).getOrigin().toString() + "'" +
|
| | | ((ArcElement) element).getRotationAngle());
|
| | |
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | ArrayList<SimpleFeature> arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | if (feature.getDefaultGeometry() != null && !((Geometry)feature.getDefaultGeometry()).isEmpty()) {
|
| | | arrayList.add(feature);
|
| | | accumulate++;
|
| | | }
|
| | | } else {
|
| | | logger.info("Unknown Element :" + element.getType() + ", lv=" + element.getLevelIndex());
|
| | | }
|
| | |
|
| | | if (accumulate > BATCHSIZE) {
|
| | | commitTransaction();
|
| | | }
|
| | | }
|
| | |
|
| | | // private Transaction transaction;
|
| | |
|
| | | public void startTransaction() {
|
| | | }
|
| | |
|
| | | public void commitTransaction() {
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | logger.debug("Transaction size = " + txFeaturesContext.size());
|
| | | //txFeaturesContext.commitTransaction();
|
| | | } else {
|
| | | logger.debug("Transaction is empty.");
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | public void rollbackTransaction() {
|
| | | }
|
| | |
|
| | | private void updateDataStore() {
|
| | | if (isProfileMode()) markUpdateTime();
|
| | | Iterator<SimpleFeatureType> it = txFeaturesContext.keySet().iterator();
|
| | | Connection conn = null;
|
| | | try {
|
| | | conn = getConnection();
|
| | | boolean autoCommit = conn.getAutoCommit();
|
| | | conn.setAutoCommit(false);
|
| | |
|
| | | while (it.hasNext()) {
|
| | | SimpleFeatureType featureType = it.next();
|
| | | logger.debug("Begin Save into EdbGeo:" + featureType.getTypeName());
|
| | |
|
| | | String bindingStmt = makePrepareInsertSql(featureType);
|
| | | ArrayList<SimpleFeature> features = txFeaturesContext.get(featureType);
|
| | | PreparedStatement pstmt = conn.prepareStatement(bindingStmt);
|
| | |
|
| | | for (SimpleFeature feature : features) {
|
| | | // currentStmt = feature;
|
| | | // Statement stmt = conn.createStatement();
|
| | | try {
|
| | | // stmt.execute(feature);
|
| | | bindFeatureParameters(pstmt, feature);
|
| | | // pstmt.execute();
|
| | | pstmt.addBatch();
|
| | | } catch (PSQLException e) {
|
| | | if (bindingStmt != null) {
|
| | | logger.error("Execute:" + bindingStmt);
|
| | | }
|
| | | logger.error(e.getServerErrorMessage());
|
| | | logger.error(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | int[] numUpdates = pstmt.executeBatch();
|
| | | for (int i = 0; i < numUpdates.length; i++) {
|
| | | if (numUpdates[i] == -2)
|
| | | logger.warn("Execution " + i + ": unknown number of rows updated");
|
| | | }
|
| | | conn.commit();
|
| | |
|
| | | JDBCUtils.close(pstmt);
|
| | | features.clear();
|
| | | logger.debug("End Save into EdbGeo:" + featureType.getTypeName());
|
| | | }
|
| | | conn.setAutoCommit(autoCommit);
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | accumulate = 0;
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.error(e.getMessage(), e);
|
| | | } finally {
|
| | | if (isProfileMode()) accumulateUpdateTime();
|
| | | }
|
| | | }
|
| | |
|
| | | public void closeFeatureWriter() {
|
| | | txFeaturesContext.clear();
|
| | | /*
|
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values())
|
| | | {
|
| | | featureWriter.close();
|
| | | }
|
| | |
|
| | | this.featuresWriterContext.clear();
|
| | | */
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createPointFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalPointFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createPolygonFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalPolygonFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createLineFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalLineFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createMultiLineFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalMultiLineFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createArcFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalArcFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createEllipseFeatureElement(String featureName) throws SchemaException {
|
| | | if (!featureTypes.containsKey(featureName)) {
|
| | | SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalEllipseFeatureTypeBuilder(featureName);
|
| | | SimpleFeatureType featureType = typeBuilder.buildFeatureType();
|
| | | featureTypes.put(featureName, featureType);
|
| | | clearFeatureData(typeBuilder);
|
| | | }
|
| | | return featureTypes.get(featureName);
|
| | | }
|
| | |
|
| | | public SimpleFeature createFeature(SimpleFeatureType featureType, Element element) throws IllegalAttributeException {
|
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
|
| | | if (element instanceof TextElement) {
|
| | | TextElement textElement = (TextElement) element;
|
| | | convertDecorator.setConverter(textElement);
|
| | |
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | double angle = textElement.getRotationAngle();
|
| | | String content = textElement.getText();
|
| | | content = content.replace('\u0000', ' ');
|
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue();
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(textElement.getColorIndex()),
|
| | | textElement.getFontIndex(),
|
| | | textElement.getJustification(),
|
| | | textElement.getTextHeight(),
|
| | | textElement.getTextWidth(),
|
| | | angle,
|
| | | content
|
| | | }, null);
|
| | | } else {
|
| | | logger.info("geometry is null." + element.toString());
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof TextNodeElement) {
|
| | | TextNodeElement textNodeElement = (TextNodeElement) element;
|
| | | convertDecorator.setConverter(textNodeElement);
|
| | |
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | double angle = textNodeElement.getRotationAngle();
|
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue();
|
| | | String[] texts = textNodeElement.getTextArray();
|
| | | StringBuilder sb = new StringBuilder();
|
| | | for (String text : texts) {
|
| | | if (sb.length() != 0)
|
| | | sb.append("\n");
|
| | | String content = text.replace('\u0000', ' ');
|
| | | sb.append(content);
|
| | | }
|
| | |
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(textNodeElement.getColorIndex()),
|
| | | textNodeElement.getFontIndex(),
|
| | | textNodeElement.getJustification(),
|
| | | textNodeElement.getTextNodeHeight(),
|
| | | textNodeElement.getTextNodeLength(),
|
| | | angle,
|
| | | sb.toString()
|
| | | }, null);
|
| | | } else {
|
| | | logger.info("geometry is null." + element.toString());
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof ShapeElement) {
|
| | | ShapeElement shapeElement = (ShapeElement) element;
|
| | | convertDecorator.setConverter(shapeElement);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(shapeElement.getColorIndex()),
|
| | | shapeElement.getWeight(),
|
| | | shapeElement.getLineStyle()
|
| | | }, null);
|
| | | } else {
|
| | | logger.info("geometry is null." + element.toString());
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof LineStringElement) {
|
| | | LineStringElement linestring = (LineStringElement) element;
|
| | | convertDecorator.setConverter(linestring);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(linestring.getColorIndex()),
|
| | | linestring.getWeight(),
|
| | | linestring.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof LineElement) {
|
| | | LineElement line = (LineElement) element;
|
| | | convertDecorator.setConverter(line);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(line.getColorIndex()),
|
| | | line.getWeight(),
|
| | | line.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof ArcElement) {
|
| | | ArcElement arcElement = (ArcElement) element;
|
| | | /*
|
| | | logger.fatal("" + arcElement.getPrimary() + ":" + arcElement.getSecondary() +
|
| | | "-" + arcElement.getStartAngle() + ":" + arcElement.getSweepAngle() + ":" +
|
| | | arcElement.getRotationAngle() + ":" + arcElement.getOrigin());
|
| | | */
|
| | | convertDecorator.setConverter(arcElement);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(arcElement.getColorIndex()),
|
| | | arcElement.getWeight(),
|
| | | arcElement.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof EllipseElement) {
|
| | | EllipseElement arcElement = (EllipseElement) element;
|
| | | convertDecorator.setConverter(arcElement);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(arcElement.getColorIndex()),
|
| | | arcElement.getWeight(),
|
| | | arcElement.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | | return null;
|
| | | } else if (element instanceof ComplexChainElement) {
|
| | | ComplexChainElement complexChainElement = (ComplexChainElement) element;
|
| | | convertDecorator.setConverter(complexChainElement);
|
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory);
|
| | | if (geom != null) {
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | colorTable.getColorCode(complexChainElement.getColorIndex()),
|
| | | complexChainElement.getWeight(),
|
| | | complexChainElement.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | | return null;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | private String getFeatureBaseName() {
|
| | | if (featureBaseName == null) {
|
| | | String dgnname = getFilename().toLowerCase();
|
| | | int i = dgnname.lastIndexOf(".");
|
| | | if (i != -1) {
|
| | | dgnname = dgnname.substring(0, i);
|
| | | }
|
| | | featureBaseName = dgnname;
|
| | | }
|
| | | return featureBaseName;
|
| | | }
|
| | |
|
| | | private SimpleFeatureType lookupFeatureType(Element element) throws SchemaException, IllegalAttributeException {
|
| | | String typeName;
|
| | | if (element instanceof TextElement) {
|
| | | typeName = getFeatureBaseName() + "_P";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createPointFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else if (element instanceof TextNodeElement) {
|
| | | typeName = getFeatureBaseName() + "_P";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createPointFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else if (element instanceof LineStringElement) {
|
| | | if (element instanceof ShapeElement) {
|
| | | typeName = getFeatureBaseName() + "_R";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createPolygonFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else {
|
| | | typeName = getFeatureBaseName() + "_L";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createLineFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | }
|
| | | } else if (element instanceof LineElement) {
|
| | | typeName = getFeatureBaseName() + "_L";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createLineFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else if (element instanceof ComplexChainElement) {
|
| | | typeName = getFeatureBaseName() + "_ML";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createMultiLineFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else if (element instanceof ArcElement) {
|
| | | typeName = getFeatureBaseName() + "_A";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createArcFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | } else if (element instanceof EllipseElement) {
|
| | | typeName = getFeatureBaseName() + "_R";
|
| | | typeName = typeName.toLowerCase();
|
| | | if (!featureTypes.containsKey(typeName)) {
|
| | | featureTypes.put(typeName, createEllipseFeatureElement(typeName));
|
| | | }
|
| | | return featureTypes.get(typeName);
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | protected FrammeAttributeData getFeatureLinkage(Element element) {
|
| | | if (!element.hasUserAttributeData())
|
| | | return null;
|
| | |
|
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData();
|
| | | for (UserAttributeData anUsrData : usrDatas) {
|
| | | if (anUsrData instanceof FrammeAttributeData) {
|
| | | return (FrammeAttributeData) anUsrData;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | |
|
| | | public boolean isDropTableMode() {
|
| | | return dropTableMode;
|
| | | }
|
| | |
|
| | | public void setDropTableMode(boolean dropTableMode) {
|
| | | this.dropTableMode = dropTableMode;
|
| | | }
|
| | |
|
| | | protected void clearFeatureData(SimpleFeatureTypeBuilder typeBuilder) throws SchemaException {
|
| | | if (isProfileMode()) markUpdateTime();
|
| | |
|
| | | String featureName = typeBuilder.getName();
|
| | | Connection conn = null;
|
| | | if (isExistFeature(typeBuilder.buildFeatureType())) {
|
| | | try {
|
| | | conn = getConnection();
|
| | | if (dropTableMode) {
|
| | | dropGeometryColumn(conn, featureName,
|
| | | ((FeatureTypeImpl)typeBuilder.buildFeatureType()).getGeometryDescriptor().getLocalName());
|
| | | dropTable(conn, featureName);
|
| | |
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, typeBuilder.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | 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);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } finally {
|
| | | if (isProfileMode()) accumulateUpdateTime();
|
| | | }
|
| | | } else {
|
| | | try {
|
| | | conn = getConnection();
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, typeBuilder.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | stmt.execute(stmtText);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | 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 {
|
| | | if (isProfileMode()) accumulateUpdateTime();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.sql.Connection;
|
| | | import java.sql.PreparedStatement;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger;
|
| | | import org.apache.commons.transaction.util.LoggerFacade;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.data.jdbc.JDBCUtils;
|
| | | import org.geotools.feature.IllegalAttributeException;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.geotools.feature.simple.SimpleFeatureBuilder;
|
| | | import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
| | | import org.geotools.feature.type.FeatureTypeImpl;
|
| | | import org.geotools.geometry.jts.JTSFactoryFinder;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import com.edb.util.PSQLException;
|
| | |
|
| | | import com.vividsolutions.jts.geom.Coordinate;
|
| | | import com.vividsolutions.jts.geom.Envelope;
|
| | | import com.vividsolutions.jts.geom.Geometry;
|
| | | import com.vividsolutions.jts.geom.GeometryFactory;
|
| | | import com.vividsolutions.jts.geom.Polygon;
|
| | |
|
| | | import com.ximple.eofms.util.DefaultColorTable;
|
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil;
|
| | | import com.ximple.eofms.util.GeometryConverterDecorator;
|
| | | import com.ximple.eofms.util.TPCLIDConverter;
|
| | | import com.ximple.eofms.util.TWDDatumConverter;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.FrammeAttributeData;
|
| | | import com.ximple.io.dgn7.ShapeElement;
|
| | | import com.ximple.io.dgn7.TextElement;
|
| | | import com.ximple.io.dgn7.UserAttributeData;
|
| | |
|
| | | public class IndexDgnConvertEdbGeoJobContext extends AbstractDgnToEdbGeoJobContext {
|
| | | static final Log logger = LogFactory.getLog(IndexDgnConvertEdbGeoJobContext.class);
|
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
|
| | | static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
|
| | |
|
| | | private HashMap<SimpleFeatureType, ArrayList<SimpleFeature>> txFeaturesContext =
|
| | | new HashMap<SimpleFeatureType, ArrayList<SimpleFeature>>();
|
| | |
|
| | | private SimpleFeatureTypeBuilder typeBuilderPnt = null;
|
| | | private SimpleFeatureTypeBuilder typeBuilderRect = null;
|
| | | private SimpleFeatureTypeBuilder typeBuilderSmallRect = null;
|
| | |
|
| | | private SimpleFeatureType featureType = null;
|
| | | private SimpleFeatureType featureType2 = null;
|
| | | private SimpleFeatureType featureType3 = null;
|
| | |
|
| | | private boolean dropTableMode = true;
|
| | | private int accumulate = 0;
|
| | |
|
| | | public IndexDgnConvertEdbGeoJobContext(String dataPath, DataStore targetDataStore, String targetSchema,
|
| | | boolean profileMode, boolean useTransform) {
|
| | | super(dataPath, targetDataStore, targetSchema, profileMode, useTransform);
|
| | | }
|
| | |
|
| | | public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException {
|
| | | if ((!(element instanceof TextElement)) && (!(element instanceof ShapeElement))) {
|
| | | return;
|
| | | }
|
| | |
|
| | | if ((element instanceof TextElement)) {
|
| | | putTextFeatureCollection((TextElement) element);
|
| | | }
|
| | |
|
| | | if ((element instanceof ShapeElement)) {
|
| | | putShapeFeatureCollection((ShapeElement) element);
|
| | | }
|
| | | }
|
| | |
|
| | | protected void putTextFeatureCollection(TextElement element) throws SchemaException, IllegalAttributeException {
|
| | | SimpleFeature feature = createFeature(element);
|
| | | if (feature == null) {
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | element.getText() + "'");
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | ArrayList<SimpleFeature> arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | |
|
| | | feature = createFeature2(element);
|
| | | if (feature == null) {
|
| | | logger.info("cannot craete feature2." + element.toString() + "'" +
|
| | | element.getText() + "'");
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | |
|
| | | SimpleFeature[] features = createFeature3(element);
|
| | | if (features == null) {
|
| | | logger.info("cannot craete feature3." + element.toString() + "'" +
|
| | | element.getText() + "'");
|
| | | return;
|
| | | }
|
| | | if (!txFeaturesContext.containsKey(features[0].getFeatureType())) {
|
| | | txFeaturesContext.put(features[0].getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | arrayList = txFeaturesContext.get(features[0].getFeatureType());
|
| | | arrayList.addAll(Arrays.asList(features));
|
| | |
|
| | | accumulate++;
|
| | |
|
| | | if (accumulate > BATCHSIZE) {
|
| | | commitTransaction();
|
| | | }
|
| | | }
|
| | |
|
| | | protected void putShapeFeatureCollection(ShapeElement element) throws SchemaException, IllegalAttributeException {
|
| | | SimpleFeature feature = createFeature(element);
|
| | | if (feature == null) {
|
| | | Polygon polygon = (Polygon) element.toGeometry(geometryFactory);
|
| | | if (polygon == null) {
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | "linear is null" + "'");
|
| | | } else {
|
| | | Coordinate pt = polygon.getEnvelopeInternal().centre();
|
| | | String id = TPCLIDConverter.CoordinateToTpclId(pt);
|
| | | logger.info("cannot craete feature." + element.toString() + "'" +
|
| | | id + "'- from pt=" + pt);
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | ArrayList<SimpleFeature> arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | |
|
| | | feature = createFeature2(element);
|
| | | if (feature == null) {
|
| | | Polygon polygon = (Polygon) element.toGeometry(geometryFactory);
|
| | | if (polygon == null) {
|
| | | logger.info("cannot craete feature2." + element.toString() + "'" +
|
| | | "linear is null" + "'");
|
| | | } else {
|
| | | Coordinate pt = polygon.getEnvelopeInternal().centre();
|
| | | String id = TPCLIDConverter.CoordinateToTpclId(pt);
|
| | | logger.info("cannot craete feature2." + element.toString() + "'" +
|
| | | id + "'- from pt=" + pt);
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | |
|
| | | SimpleFeature[] features = createFeature3(element);
|
| | | if (features == null) {
|
| | | Polygon polygon = (Polygon) element.toGeometry(geometryFactory);
|
| | | if (polygon == null) {
|
| | | logger.info("cannot craete feature3." + element.toString() + "'" +
|
| | | "linear is null" + "'");
|
| | | } else {
|
| | | Coordinate pt = polygon.getEnvelopeInternal().centre();
|
| | | String id = TPCLIDConverter.CoordinateToTpclId(pt);
|
| | | logger.info("cannot craete feature3." + element.toString() + "'" +
|
| | | id + "'- from pt=" + pt);
|
| | | }
|
| | | return;
|
| | | }
|
| | | if (!txFeaturesContext.containsKey(features[0].getFeatureType())) {
|
| | | txFeaturesContext.put(features[0].getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | arrayList = txFeaturesContext.get(features[0].getFeatureType());
|
| | | arrayList.addAll(Arrays.asList(features));
|
| | |
|
| | | accumulate++;
|
| | |
|
| | | if (accumulate > BATCHSIZE) {
|
| | | commitTransaction();
|
| | | }
|
| | | }
|
| | |
|
| | | public void startTransaction() {
|
| | | }
|
| | |
|
| | | public void commitTransaction() {
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | logger.debug("Transaction size = " + txFeaturesContext.size());
|
| | | } else {
|
| | | logger.debug("Transaction is empty.");
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | | }
|
| | |
|
| | | public void rollbackTransaction() {
|
| | | }
|
| | |
|
| | | private void updateDataStore() {
|
| | | if (isProfileMode()) markUpdateTime();
|
| | |
|
| | | Iterator<SimpleFeatureType> it = txFeaturesContext.keySet().iterator();
|
| | | Connection conn = null;
|
| | | try {
|
| | | conn = getConnection();
|
| | | boolean autoCommit = conn.getAutoCommit();
|
| | | conn.setAutoCommit(false);
|
| | |
|
| | | while (it.hasNext()) {
|
| | | SimpleFeatureType featureType = it.next();
|
| | | logger.debug("Begin Save EdbGeo:" + featureType.getTypeName());
|
| | |
|
| | | String bindingStmt = makePrepareInsertSql(featureType);
|
| | | ArrayList<SimpleFeature> features = txFeaturesContext.get(featureType);
|
| | | PreparedStatement pstmt = conn.prepareStatement(bindingStmt);
|
| | |
|
| | | for (SimpleFeature feature : features) {
|
| | | // currentStmt = feature;
|
| | | // Statement stmt = conn.createStatement();
|
| | | try {
|
| | | // stmt.execute(feature);
|
| | | bindFeatureParameters(pstmt, feature);
|
| | | // pstmt.execute();
|
| | | pstmt.addBatch();
|
| | | } catch (PSQLException e) {
|
| | | if (bindingStmt != null) {
|
| | | logger.error("Execute:" + bindingStmt);
|
| | | }
|
| | | logger.error(e.getServerErrorMessage());
|
| | | logger.error(e.getMessage(), e);
|
| | | /*
|
| | | } finally {
|
| | | stmt.close();
|
| | | */
|
| | | }
|
| | | }
|
| | | /*
|
| | | if ((i % BATCHSIZE) != 0)
|
| | | {
|
| | | stmt.executeBatch();
|
| | | }
|
| | | stmt.close();
|
| | | */
|
| | | int[] numUpdates = pstmt.executeBatch();
|
| | | for (int i = 0; i < numUpdates.length; i++) {
|
| | | if (numUpdates[i] == -2)
|
| | | logger.warn("Execution " + i + ": unknown number of rows updated");
|
| | | }
|
| | | conn.commit();
|
| | |
|
| | | pstmt.close();
|
| | | features.clear();
|
| | |
|
| | | logger.debug("End Save EdbGeo:" + featureType.getTypeName());
|
| | | }
|
| | | accumulate = 0;
|
| | | conn.setAutoCommit(autoCommit);
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | } catch (PSQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.error(e.getServerErrorMessage());
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.error(e.getMessage(), e);
|
| | | } finally {
|
| | | if (isProfileMode()) this.accumulateUpdateTime();
|
| | | }
|
| | | }
|
| | |
|
| | | public void closeFeatureWriter() {
|
| | | txFeaturesContext.clear();
|
| | | /*
|
| | | for (FeatureWriter featureWriter : this.featuresWriterContext.values())
|
| | | {
|
| | | featureWriter.close();
|
| | | }
|
| | |
|
| | | this.featuresWriterContext.clear();
|
| | | */
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createFeatureElement(String featureName) throws SchemaException {
|
| | | if (typeBuilderRect == null) {
|
| | | Connection conn = null;
|
| | | typeBuilderRect = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName);
|
| | | if (isExistFeature(typeBuilderRect.buildFeatureType())) {
|
| | | try {
|
| | | conn = getConnection();
|
| | | if (dropTableMode) {
|
| | | try {
|
| | | dropGeometryColumn(conn, featureName,
|
| | | ((FeatureTypeImpl)typeBuilderRect.buildFeatureType()).getGeometryDescriptor().getLocalName());
|
| | | } catch (PSQLException e) {
|
| | | logger.debug(e.getMessage(), e);
|
| | | }
|
| | | try {
|
| | | dropTable(conn, featureName);
|
| | | } catch (PSQLException e) {
|
| | | logger.debug(e.getMessage(), e);
|
| | | }
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn,
|
| | | typeBuilderRect.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | 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);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | } else {
|
| | | try {
|
| | | conn = getConnection();
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn,
|
| | | typeBuilderRect.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | stmt.execute(stmtText);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | return typeBuilderRect.buildFeatureType();
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createFeatureElement2(String featureName) throws SchemaException {
|
| | | if (typeBuilderPnt == null) {
|
| | | Connection conn = null;
|
| | | typeBuilderPnt = FeatureTypeBuilderUtil.createNormalIndexTextFeatureTypeBuilder(featureName);
|
| | | if (isExistFeature(typeBuilderPnt.buildFeatureType())) {
|
| | | try {
|
| | | conn = getConnection();
|
| | | if (dropTableMode) {
|
| | | dropGeometryColumn(conn, featureName,
|
| | | ((FeatureTypeImpl)typeBuilderPnt.buildFeatureType()).getGeometryDescriptor().getLocalName());
|
| | | dropTable(conn, featureName);
|
| | |
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn,
|
| | | typeBuilderPnt.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | 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);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | } else {
|
| | | try {
|
| | | conn = getConnection();
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn,
|
| | | typeBuilderPnt.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | stmt.execute(stmtText);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | return typeBuilderPnt.buildFeatureType();
|
| | | }
|
| | |
|
| | | public SimpleFeatureType createFeatureElement3(String featureName) throws SchemaException {
|
| | | if (typeBuilderSmallRect == null) {
|
| | | Connection conn = null;
|
| | | typeBuilderSmallRect = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName);
|
| | | if (isExistFeature(typeBuilderSmallRect.buildFeatureType())) {
|
| | | try {
|
| | | conn = getConnection();
|
| | | if (dropTableMode) {
|
| | | try {
|
| | | dropGeometryColumn(conn, featureName,
|
| | | ((FeatureTypeImpl)typeBuilderSmallRect.buildFeatureType()).getGeometryDescriptor().getLocalName());
|
| | | } catch (PSQLException e) {
|
| | | logger.debug(e.getMessage(), e);
|
| | | }
|
| | | try {
|
| | | dropTable(conn, featureName);
|
| | | } catch (PSQLException e) {
|
| | | logger.debug(e.getMessage(), e);
|
| | | }
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, typeBuilderSmallRect.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | 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);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | } else {
|
| | | try {
|
| | | conn = getConnection();
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn,
|
| | | typeBuilderSmallRect.buildFeatureType());
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | stmt.execute(stmtText);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | return typeBuilderSmallRect.buildFeatureType();
|
| | | }
|
| | |
|
| | | public SimpleFeature createFeature(SimpleFeatureType featureType, Element element) throws IllegalAttributeException {
|
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
|
| | | if (element instanceof TextElement) {
|
| | | TextElement textElement = (TextElement) element;
|
| | | String tpclid = textElement.getText();
|
| | |
|
| | | if(tpclid.trim().endsWith(""))
|
| | | {
|
| | | return null; |
| | | }
|
| | |
|
| | | Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid);
|
| | | Geometry geom;
|
| | | if (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826) {
|
| | | geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | }), null);
|
| | | } else {
|
| | | geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | }), null);
|
| | | }
|
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | extent.getMinX(),
|
| | | extent.getMinY(),
|
| | | extent.getMaxX(),
|
| | | extent.getMaxY(),
|
| | | tpclid,
|
| | | colorTable.getColorCode(textElement.getColorIndex()),
|
| | | textElement.getWeight(),
|
| | | textElement.getLineStyle()
|
| | | }, null);
|
| | | } else if (element instanceof ShapeElement) {
|
| | | ShapeElement shapeElement = (ShapeElement) element;
|
| | | Geometry geomShape = shapeElement.toGeometry(geometryFactory);
|
| | | Polygon polygon = (Polygon) geomShape;
|
| | | if (polygon.isRectangle()) {
|
| | | Envelope bounds = polygon.getEnvelopeInternal();
|
| | | if (bounds.getWidth() == TPCLIDConverter.SX1200) {
|
| | | Coordinate center = bounds.centre();
|
| | | String tpclid = TPCLIDConverter.CoordinateToTpclId(center);
|
| | | if ((tpclid == null) || (tpclid.length() == 0)) {
|
| | | logger.warn("Cannot convert coordinate to tpclid-[" + center.toString() + "]");
|
| | | return null;
|
| | | }
|
| | | if (tpclid.length() > 5) {
|
| | | tpclid = tpclid.substring(0, 5);
|
| | | }
|
| | | Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid);
|
| | | Geometry geom = null;
|
| | | try {
|
| | | geom = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ?
|
| | | geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | }), null) :
|
| | | geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMinY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMaxY())),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())),
|
| | | }), null));
|
| | | } catch (NullPointerException e) {
|
| | | logger.warn("TPCLIDConverter has error at [" + tpclid + "]");
|
| | | logger.warn(e.getMessage(), e);
|
| | | return null;
|
| | | }
|
| | |
|
| | | return (geom == null ? null :
|
| | | SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | extent.getMinX(),
|
| | | extent.getMinY(),
|
| | | extent.getMaxX(),
|
| | | extent.getMaxY(),
|
| | | tpclid,
|
| | | colorTable.getColorCode(shapeElement.getColorIndex()),
|
| | | shapeElement.getWeight(),
|
| | | shapeElement.getLineStyle()
|
| | | }, null));
|
| | | }
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public SimpleFeature createFeature2(SimpleFeatureType featureType, Element element) throws IllegalAttributeException {
|
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
|
| | | if (element instanceof TextElement) {
|
| | | SimpleFeature feature = null;
|
| | | TextElement txtElement = (TextElement) element;
|
| | | double angle = txtElement.getRotationAngle();
|
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue();
|
| | | GeometryConverterDecorator convertDecorator = FeatureTypeBuilderUtil.lookupDefaultGeometryConverter();
|
| | | convertDecorator.setConverter(txtElement);
|
| | | Geometry gobj = convertDecorator.toGeometry(geometryFactory);
|
| | | if (gobj != null)
|
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | gobj,
|
| | | colorTable.getColorCode(txtElement.getColorIndex()),
|
| | | txtElement.getWeight(),
|
| | | txtElement.getLineStyle(),
|
| | | txtElement.getJustification(),
|
| | | txtElement.getTextHeight(),
|
| | | txtElement.getTextWidth(),
|
| | | angle,
|
| | | txtElement.getText()
|
| | | }, null);
|
| | | return feature;
|
| | | } else if (element instanceof ShapeElement) {
|
| | | SimpleFeature feature = null;
|
| | | ShapeElement shapeElement = (ShapeElement) element;
|
| | | double angle = 0.0;
|
| | | Geometry geomShape = shapeElement.toGeometry(geometryFactory);
|
| | | Polygon polygon = (Polygon) geomShape;
|
| | | if (polygon.isRectangle()) {
|
| | | Envelope bounds = polygon.getEnvelopeInternal();
|
| | | if (bounds.getWidth() == TPCLIDConverter.SX1200) {
|
| | | Coordinate center = bounds.centre();
|
| | | String tpclid = TPCLIDConverter.CoordinateToTpclId(center);
|
| | | if (tpclid.length() > 5) {
|
| | | tpclid = tpclid.substring(0, 5);
|
| | | Coordinate pos = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ?
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(center.x, center.y)) :
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(center.x, center.y)));
|
| | | Geometry gobj = geometryFactory.createPoint(pos);
|
| | |
|
| | | if (gobj != null)
|
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | gobj,
|
| | | colorTable.getColorCode(shapeElement.getColorIndex()),
|
| | | shapeElement.getWeight(),
|
| | | shapeElement.getLineStyle(),
|
| | | 0,
|
| | | 15.0,
|
| | | 15 * 5,
|
| | | angle,
|
| | | tpclid
|
| | | }, null);
|
| | | return feature;
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public SimpleFeature[] createFeature3(SimpleFeatureType featureType, Element element) throws IllegalAttributeException {
|
| | | DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
|
| | | if (element instanceof TextElement) {
|
| | | TextElement textElement = (TextElement) element;
|
| | | String tpclid = textElement.getText();
|
| | | SimpleFeature[] result = new SimpleFeature[4];
|
| | |
|
| | | Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid);
|
| | |
|
| | | for (int i = 0; i < 4; i++) {
|
| | | char mapSubId = TPCLIDConverter.intToAscii(65 + i);
|
| | | int dx = (i % 2) * TPCLIDConverter.SX600;
|
| | | int dy = (i / 2) * TPCLIDConverter.SY600;
|
| | |
|
| | | Geometry geom;
|
| | |
|
| | | if (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826) {
|
| | | geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | }), null);
|
| | | } else {
|
| | | geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | }), null);
|
| | | }
|
| | | Envelope innerExtent = geom.getEnvelopeInternal();
|
| | |
|
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | innerExtent.getMinX(),
|
| | | innerExtent.getMinY(),
|
| | | innerExtent.getMaxX(),
|
| | | innerExtent.getMaxY(),
|
| | | tpclid + mapSubId,
|
| | | colorTable.getColorCode(textElement.getColorIndex()),
|
| | | textElement.getWeight(),
|
| | | textElement.getLineStyle()
|
| | | }, null);
|
| | |
|
| | | }
|
| | | return result;
|
| | | } else if (element instanceof ShapeElement) {
|
| | | ShapeElement shapeElement = (ShapeElement) element;
|
| | | Geometry geomShape = shapeElement.toGeometry(geometryFactory);
|
| | | Polygon polygon = (Polygon) geomShape;
|
| | | if (polygon.isRectangle()) {
|
| | | Envelope extent = polygon.getEnvelopeInternal();
|
| | | if (extent.getWidth() == TPCLIDConverter.SX1200) {
|
| | | SimpleFeature[] result = new SimpleFeature[4];
|
| | | Coordinate center = extent.centre();
|
| | | String tpclid = TPCLIDConverter.CoordinateToTpclId(center);
|
| | | if (tpclid.length() > 5) {
|
| | | tpclid = tpclid.substring(0, 5);
|
| | | }
|
| | | for (int i = 0; i < 4; i++) {
|
| | | char mapSubId = TPCLIDConverter.intToAscii(65 + i);
|
| | | int dx = (i % 2) * TPCLIDConverter.SX600;
|
| | | int dy = (i / 2) * TPCLIDConverter.SY600;
|
| | |
|
| | | Geometry geom = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ?
|
| | | geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | }), null) :
|
| | | geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[]
|
| | | {
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - dy)),
|
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(
|
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)),
|
| | | }), null));
|
| | |
|
| | | Envelope innerExtent = geom.getEnvelopeInternal();
|
| | |
|
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{
|
| | | geom,
|
| | | innerExtent.getMinX(),
|
| | | innerExtent.getMinY(),
|
| | | innerExtent.getMaxX(),
|
| | | innerExtent.getMaxY(),
|
| | | tpclid + mapSubId,
|
| | | colorTable.getColorCode(shapeElement.getColorIndex()),
|
| | | shapeElement.getWeight(),
|
| | | shapeElement.getLineStyle()
|
| | | }, null);
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | private SimpleFeature createFeature(Element element) throws SchemaException, IllegalAttributeException {
|
| | | if (featureType == null) {
|
| | | String dgnname = getFilename().toLowerCase();
|
| | | int i = dgnname.lastIndexOf(".");
|
| | | if (i != -1) {
|
| | | dgnname = dgnname.substring(0, i);
|
| | | }
|
| | | featureType = createFeatureElement(dgnname.toLowerCase());
|
| | | }
|
| | | return createFeature(featureType, element);
|
| | | }
|
| | |
|
| | | private SimpleFeature createFeature2(Element element) throws SchemaException, IllegalAttributeException {
|
| | | if (featureType2 == null) {
|
| | | String dgnname = getFilename().toLowerCase();
|
| | | int i = dgnname.lastIndexOf(".");
|
| | | if (i != -1) {
|
| | | dgnname = dgnname.substring(0, i);
|
| | | }
|
| | | dgnname = dgnname + "_p";
|
| | | featureType2 = createFeatureElement2(dgnname.toLowerCase());
|
| | | }
|
| | | return createFeature2(featureType2, element);
|
| | | }
|
| | |
|
| | | private SimpleFeature[] createFeature3(Element element) throws SchemaException, IllegalAttributeException {
|
| | | if (featureType3 == null) {
|
| | | String dgnname = getFilename().toLowerCase();
|
| | | int i = dgnname.lastIndexOf(".");
|
| | | if (i != -1) {
|
| | | dgnname = dgnname.substring(0, i);
|
| | | }
|
| | | dgnname = dgnname + "_s";
|
| | | featureType3 = createFeatureElement3(dgnname.toLowerCase());
|
| | | }
|
| | | return createFeature3(featureType3, element);
|
| | | }
|
| | |
|
| | | protected FrammeAttributeData getFeatureLinkage(Element element) {
|
| | | if (!element.hasUserAttributeData())
|
| | | return null;
|
| | |
|
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData();
|
| | | for (UserAttributeData anUsrData : usrDatas) {
|
| | | if (anUsrData instanceof FrammeAttributeData) {
|
| | | return (FrammeAttributeData) anUsrData;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | |
|
| | | public boolean isDropTableMode() {
|
| | | return dropTableMode;
|
| | | }
|
| | |
|
| | | public void setDropTableMode(boolean dropTableMode) {
|
| | | this.dropTableMode = dropTableMode;
|
| | | }
|
| | |
|
| | | public void clearOutputDatabase() {
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.ximple.eofms.jobs.context.edbgeo;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.net.MalformedURLException;
|
| | | import java.net.URL;
|
| | | import java.sql.BatchUpdateException;
|
| | | import java.sql.Connection;
|
| | | import java.sql.DriverManager;
|
| | | import java.sql.PreparedStatement;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | |
|
| | | import com.vividsolutions.jts.geom.Geometry;
|
| | | import org.apache.commons.digester.Digester;
|
| | | import org.apache.commons.digester.xmlrules.DigesterLoader;
|
| | | import org.apache.commons.logging.Log;
|
| | | import org.apache.commons.logging.LogFactory;
|
| | | import org.apache.commons.transaction.util.CommonsLoggingLogger;
|
| | | import org.apache.commons.transaction.util.LoggerFacade;
|
| | | import org.geotools.data.DataStore;
|
| | | import org.geotools.data.Transaction;
|
| | | import org.geotools.data.jdbc.JDBCUtils;
|
| | | import org.geotools.data.edbgeo.PostgisDataStoreFactory;
|
| | | import org.geotools.feature.SchemaException;
|
| | | import org.geotools.feature.type.FeatureTypeImpl;
|
| | | import org.opengis.feature.simple.SimpleFeature;
|
| | | import org.opengis.feature.simple.SimpleFeatureType;
|
| | | import com.edb.util.PSQLException;
|
| | | import org.quartz.JobExecutionContext;
|
| | | import org.xml.sax.SAXException;
|
| | |
|
| | | import com.vividsolutions.jts.util.Assert;
|
| | |
|
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter;
|
| | | import com.ximple.eofms.filter.CreateFeatureTypeEventListener;
|
| | | import com.ximple.eofms.filter.ElementDispatcher;
|
| | | import com.ximple.eofms.filter.FeatureTypeEvent;
|
| | | import com.ximple.eofms.jobs.OracleElementLogger;
|
| | | import com.ximple.io.dgn7.ComplexElement;
|
| | | import com.ximple.io.dgn7.Element;
|
| | | import com.ximple.io.dgn7.FrammeAttributeData;
|
| | |
|
| | | public class OracleConvertEdbGeoJobContext extends AbstractOracleToEdbGeoJobContext
|
| | | implements CreateFeatureTypeEventListener {
|
| | | static Log logger = LogFactory.getLog(OracleConvertEdbGeoJobContext.class);
|
| | | static final LoggerFacade sLogger = new CommonsLoggingLogger(logger);
|
| | |
|
| | | static PostgisDataStoreFactory dataStoreFactory = new PostgisDataStoreFactory();
|
| | |
|
| | | private OracleElementLogger elmLogger = null;
|
| | |
|
| | | static {
|
| | | try {
|
| | | DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
|
| | | } catch (SQLException e) {
|
| | | Assert.shouldNeverReachHere(e.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | private String _filterConfig;
|
| | |
|
| | | private ElementDispatcher elementDispatcher;
|
| | |
|
| | | private HashMap<SimpleFeatureType, ArrayList<SimpleFeature>> txFeaturesContext = new HashMap<SimpleFeatureType, ArrayList<SimpleFeature>>();
|
| | |
|
| | | private JobExecutionContext executionContext;
|
| | |
|
| | | private String currentSchema = null;
|
| | | private boolean schemaChanged = false;
|
| | | private boolean dropTableMode = true;
|
| | | private int accumulate = 0;
|
| | |
|
| | | public OracleConvertEdbGeoJobContext(String dataPath, DataStore pgDS, String targetSchema, String filterConfig,
|
| | | boolean profileMode, boolean useTransform) {
|
| | | super(dataPath, pgDS, targetSchema, profileMode, useTransform);
|
| | | _filterConfig = filterConfig;
|
| | | elementDispatcher = createElementDispatcher();
|
| | | elementDispatcher.addCreateFeatureTypeEventListener(this);
|
| | | // txFeaturesContext = new PessimisticMapWrapper(featuresContext, sLogger);
|
| | | }
|
| | |
|
| | | private ElementDispatcher createElementDispatcher() {
|
| | | try {
|
| | | URL rulesURL = ElementDispatcher.class.getResource("ElementDispatcherRules.xml");
|
| | | assert rulesURL != null;
|
| | | Digester digester = DigesterLoader.createDigester(rulesURL);
|
| | | URL filterURL = null;
|
| | | if (_filterConfig != null) {
|
| | | File config = new File(_filterConfig);
|
| | | if (config.exists()) {
|
| | | filterURL = config.toURI().toURL();
|
| | | }
|
| | | }
|
| | | if (filterURL == null) {
|
| | | // config = new File("conf/DefaultConvertShpFilter.xml");
|
| | | filterURL = this.getClass().getResource("/conf/DefaultConvertShpFilter.xml");
|
| | | // filterURL = this.getClass().getResource("/conf/ConvertShpFilterForLevel.xml");
|
| | | }
|
| | | assert filterURL != null;
|
| | | return (ElementDispatcher) digester.parse(filterURL);
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (MalformedURLException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (IOException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | } catch (SAXException e) {
|
| | | logger.info(e.getMessage(), e);
|
| | | throw new RuntimeException(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | public void putFeatureCollection(Element element) {
|
| | | assert elementDispatcher != null;
|
| | | // 判斷是否符和條件
|
| | | SimpleFeature feature = elementDispatcher.execute(element, isTransformed());
|
| | | if (feature == null) {
|
| | | boolean isEmptySize = false;
|
| | | FrammeAttributeData linkage =
|
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element);
|
| | | logger.warn("Unknown Element:" + element.getElementType().toString() +
|
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" +
|
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID())));
|
| | |
|
| | | if (element instanceof ComplexElement) {
|
| | | ComplexElement complex = (ComplexElement) element;
|
| | | logger.warn("----Complex Element size=" + complex.size() + ":" +
|
| | | (linkage == null ? "NULL" : (linkage.getUfid())));
|
| | | if (complex.size() == 0)
|
| | | isEmptySize = true;
|
| | | }
|
| | |
|
| | | if (getElementLogging() && (!isEmptySize)) {
|
| | | getElementLogger().logElement(element, getCurrentSchema());
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (((Geometry)feature.getDefaultGeometry()).isEmpty()) {
|
| | | boolean isEmptySize = false;
|
| | | FrammeAttributeData linkage =
|
| | | AbstractFLinkageDispatchableFilter.getFeatureLinkage(element);
|
| | | logger.warn("Empty Geom Element:" + element.getElementType().toString() +
|
| | | ":type=" + element.getType() + ":lv=" + element.getLevelIndex() + ":id=" +
|
| | | (linkage == null ? "NULL" : (linkage.getFsc() + "|" + linkage.getComponentID())));
|
| | |
|
| | | if (element instanceof ComplexElement) {
|
| | | ComplexElement complex = (ComplexElement) element;
|
| | | logger.warn("----Complex Element size=" + complex.size() + ":" +
|
| | | (linkage == null ? "NULL" : (linkage.getUfid())));
|
| | | if (complex.size() == 0)
|
| | | isEmptySize = true;
|
| | | }
|
| | |
|
| | | if (getElementLogging() && (!isEmptySize)) {
|
| | | getElementLogger().logElement(element, getCurrentSchema());
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.containsKey(feature.getFeatureType())) {
|
| | | txFeaturesContext.put(feature.getFeatureType(), new ArrayList<SimpleFeature>());
|
| | | }
|
| | | ArrayList<SimpleFeature> arrayList = txFeaturesContext.get(feature.getFeatureType());
|
| | | arrayList.add(feature);
|
| | | accumulate++;
|
| | | if (accumulate > BATCHSIZE) {
|
| | | commitTransaction();
|
| | | }
|
| | | }
|
| | |
|
| | | public void startTransaction() {
|
| | | }
|
| | |
|
| | | public void commitTransaction() {
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | logger.debug("Transaction size = " + txFeaturesContext.size());
|
| | | //txFeaturesContext.commitTransaction();
|
| | | } else {
|
| | | logger.debug("Transaction is empty.");
|
| | | }
|
| | |
|
| | | if (!txFeaturesContext.isEmpty()) {
|
| | | updateDataStore();
|
| | | }
|
| | |
|
| | | if (this.getElementLogger() != null)
|
| | | this.getElementLogger().flashLogging();
|
| | | }
|
| | |
|
| | | public void rollbackTransaction() {
|
| | | }
|
| | |
|
| | | public void resetFeatureContext() {
|
| | | txFeaturesContext.clear();
|
| | | }
|
| | |
|
| | | private void updateDataStore() {
|
| | | if (isProfileMode()) markUpdateTime();
|
| | | Iterator<SimpleFeatureType> it = txFeaturesContext.keySet().iterator();
|
| | | Connection conn = null;
|
| | | try {
|
| | | conn = getConnection();
|
| | | boolean autoCommit = conn.getAutoCommit();
|
| | | conn.setAutoCommit(false);
|
| | |
|
| | | while (it.hasNext()) {
|
| | | SimpleFeatureType featureType = it.next();
|
| | | logger.debug("Begin Save into EdbGeo:" + featureType.getTypeName());
|
| | |
|
| | | int batchCount = 0;
|
| | | String bindingStmt = makePrepareInsertSql(featureType);
|
| | | ArrayList<SimpleFeature> features = txFeaturesContext.get(featureType);
|
| | | PreparedStatement pstmt = conn.prepareStatement(bindingStmt);
|
| | |
|
| | | for (SimpleFeature feature : features) {
|
| | | try {
|
| | | // stmt.execute(feature);
|
| | | bindFeatureParameters(pstmt, feature);
|
| | | // pstmt.executeUpdate();
|
| | | pstmt.addBatch();
|
| | | } catch (PSQLException e) {
|
| | | if (bindingStmt != null) {
|
| | | logger.error("Execute:" + bindingStmt);
|
| | | }
|
| | | logger.error(e.getServerErrorMessage());
|
| | | logger.error(e.getMessage(), e);
|
| | | } catch (ClassCastException e) {
|
| | | if (bindingStmt != null) {
|
| | | logger.error("Execute:" + bindingStmt);
|
| | | }
|
| | | for (int i = 0; i < feature.getAttributeCount(); i++) {
|
| | | logger.info("attr[" + i + "]-" + ((feature.getAttribute(i) == null) ? " NULL" :
|
| | | feature.getAttribute(i).toString()));
|
| | | }
|
| | | logger.error(e.getMessage(), e);
|
| | | }
|
| | | batchCount++;
|
| | | }
|
| | |
|
| | | int[] numUpdates = pstmt.executeBatch();
|
| | | for (int i = 0; i < numUpdates.length; i++) {
|
| | | if (numUpdates[i] == -2)
|
| | | logger.warn("Execution " + i + ": unknown number of rows updated");
|
| | | }
|
| | | conn.commit();
|
| | |
|
| | | pstmt.close();
|
| | | features.clear();
|
| | | logger.debug("End Save into EdbGeo:" + featureType.getTypeName());
|
| | | }
|
| | | conn.setAutoCommit(autoCommit);
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | accumulate = 0;
|
| | | } catch (BatchUpdateException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.error(e.getMessage(), e);
|
| | | SQLException ex;
|
| | | while ((ex = e.getNextException()) != null) {
|
| | | // logger.warn(ex.getMessage(), ex);
|
| | | logger.warn(ex.getMessage());
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.error(e.getMessage(), e);
|
| | | } finally {
|
| | | if (isProfileMode()) accumulateUpdateTime();
|
| | | }
|
| | | }
|
| | |
|
| | | public JobExecutionContext getExecutionContext() {
|
| | | return executionContext;
|
| | | }
|
| | |
|
| | | public void setExecutionContext(JobExecutionContext context) {
|
| | | executionContext = context;
|
| | | }
|
| | |
|
| | | /**
|
| | | * �����]�Ƽg�J��
|
| | | *
|
| | | * @throws IOException IO�o�Ϳ�~
|
| | | */
|
| | | public void closeFeatureWriter() throws IOException {
|
| | | }
|
| | |
|
| | | protected OracleElementLogger getElementLogger() {
|
| | | if (elmLogger == null) {
|
| | | elmLogger = new OracleElementLogger(getOracleConnection());
|
| | | elmLogger.setDataPath(this.getDataPath());
|
| | | }
|
| | | return elmLogger;
|
| | | }
|
| | |
|
| | | public String getCurrentSchema() {
|
| | | return currentSchema;
|
| | | }
|
| | |
|
| | | public void setCurrentSchema(String querySchema) {
|
| | | this.currentSchema = querySchema;
|
| | | this.schemaChanged = true;
|
| | | }
|
| | |
|
| | | protected Log getLogger() {
|
| | | return logger;
|
| | | }
|
| | |
|
| | | public boolean isDropTableMode() {
|
| | | return dropTableMode;
|
| | | }
|
| | |
|
| | | public void setDropTableMode(boolean dropTableMode) {
|
| | | this.dropTableMode = dropTableMode;
|
| | | }
|
| | |
|
| | | public void createFeatureTypeOccurred(FeatureTypeEvent evt) {
|
| | | try {
|
| | | createOrClearFeatureDataTable(evt.getFeatureType());
|
| | | } catch (SchemaException e) {
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | |
|
| | | protected void createOrClearFeatureDataTable(SimpleFeatureType featureType) throws SchemaException {
|
| | | String featureName = featureType.getTypeName();
|
| | | Connection conn = null;
|
| | | if (isExistFeature(featureType)) {
|
| | | try {
|
| | | conn = getConnection();
|
| | | if (dropTableMode) {
|
| | | dropGeometryColumn(conn, getTargetSchema(), featureName,
|
| | | ((FeatureTypeImpl)featureType).getGeometryDescriptor().getName().getLocalPart());
|
| | | dropTable(conn, getTargetSchema(), featureName);
|
| | |
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType);
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | stmt.execute(stmtText);
|
| | | JDBCUtils.close(stmt);
|
| | | }
|
| | | } 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);
|
| | | }
|
| | | } else {
|
| | | String tempStmt = null;
|
| | | try {
|
| | | conn = getConnection();
|
| | | ArrayList<String> schemaTexts = createNewSchemaTexts(conn, featureType);
|
| | | for (String stmtText : schemaTexts) {
|
| | | Statement stmt = conn.createStatement();
|
| | | tempStmt = stmtText;
|
| | | stmt.execute(stmtText);
|
| | | stmt.close();
|
| | | }
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | } catch (IOException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null);
|
| | | logger.warn("RUN--" + tempStmt);
|
| | | logger.warn(e.getMessage(), e);
|
| | | } catch (SQLException e) {
|
| | | JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e);
|
| | | logger.warn("RUN--" + tempStmt);
|
| | | logger.warn(e.getMessage(), e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public boolean isSchemaChanged() {
|
| | | return schemaChanged;
|
| | | }
|
| | | }
|
| | |
| | | String content = textElement.getText(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | |
| | | } |
| | | |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textNodeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(shapeElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(linestring); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(linestring.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(line); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(line.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(complexChainElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(complexChainElement.getColorIndex()), |
| | |
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | })); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | GeometryConverterDecorator convertDecorator = FeatureTypeBuilderUtil.lookupDefaultGeometryConverter(); |
| | | convertDecorator.setConverter(txtElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | SimpleFeature feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | |
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | }), null)); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | String content = textElement.getText(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | |
| | | } |
| | | |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textNodeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(shapeElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(linestring); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(linestring.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(line); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(line.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(complexChainElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(complexChainElement.getColorIndex()), |
| | |
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | })); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | convertDecorator.setConverter(txtElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | SimpleFeature feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | |
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | }), null)); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | import java.sql.Statement; |
| | | import java.util.*; |
| | | |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import org.geotools.data.DataSourceException; |
| | | import org.geotools.data.DataStore; |
| | | import org.geotools.data.SchemaNotFoundException; |
| | |
| | | // String geomName = descriptors[i].getLocalName(); |
| | | // int srid = ftInfo.getSRID(geomName); |
| | | Geometry geometry = (Geometry) attributes.get(i); |
| | | geometry.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | |
| | | if (geometry == null) { |
| | | attrValue = "NULL"; |
| | |
| | | content = content.replace('\u0000', ' '); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | |
| | | } |
| | | |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textNodeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(shapeElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(linestring); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(linestring.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(line); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(line.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(complexChainElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(complexChainElement.getColorIndex()), |
| | |
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | }), null); |
| | | } |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | return null; |
| | | } |
| | | |
| | | if (geom != null) geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | |
| | | return (geom == null ? null : |
| | | SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | |
| | | convertDecorator.setConverter(txtElement); |
| | | Geometry gobj = convertDecorator.toGeometry(geometryFactory); |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | |
| | | Geometry gobj = geometryFactory.createPoint(pos); |
| | | |
| | | if (gobj != null) |
| | | gobj.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | gobj, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | |
| | | } |
| | | Envelope innerExtent = geom.getEnvelopeInternal(); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | innerExtent.getMinX(), |
| | |
| | | |
| | | Envelope innerExtent = geom.getEnvelopeInternal(); |
| | | |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | innerExtent.getMinX(), |
| | |
| | | String content = textElement.getText(); |
| | | angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textElement.getColorIndex()), |
| | |
| | | } |
| | | |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(textNodeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(shapeElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(shapeElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(linestring); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(linestring.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(line); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(line.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(arcElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(arcElement.getColorIndex()), |
| | |
| | | convertDecorator.setConverter(complexChainElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | if (geom != null) { |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(complexChainElement.getColorIndex()), |
| | |
| | | TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), |
| | | }); |
| | | } |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | return SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |
| | |
| | | GeometryConverterDecorator convertDecorator = FeatureTypeBuilderUtil.lookupDefaultGeometryConverter(); |
| | | convertDecorator.setConverter(txtElement); |
| | | Geometry geom = convertDecorator.toGeometry(geometryFactory); |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | SimpleFeature feature = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | colorTable.getColorCode(txtElement.getColorIndex()), |
| | |
| | | extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), |
| | | }), null); |
| | | } |
| | | geom.setSRID(FeatureTypeBuilderUtil.getDefaultFeatureSRID()); |
| | | result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ |
| | | geom, |
| | | extent.getMinX(), |