From 993934b807b954712892378a7b787322d4244026 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Mon, 17 Mar 2008 19:52:32 +0800 Subject: [PATCH] update for EOFM-18 --- ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java b/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java index fe44141..344dd76 100644 --- a/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java +++ b/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java @@ -1,9 +1,13 @@ package com.ximple.eofms.jobs; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.Properties; import org.apache.commons.logging.Log; @@ -11,7 +15,13 @@ 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.FeatureWriter; +import org.geotools.data.Transaction; +import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.feature.Feature; +import org.geotools.feature.FeatureType; +import org.geotools.feature.IllegalAttributeException; +import org.geotools.feature.SimpleFeature; import com.vividsolutions.jts.util.Assert; @@ -241,6 +251,7 @@ private String _oracleHost; private String _oracleInstance; private String _oraclePort; + private String _dataPath; private OracleConnection oracleConnection = null; private Properties properties; @@ -269,6 +280,11 @@ { properties.put(PROPUsrKey, userName); properties.put(PROPPassKey, password); + } + + public void setShapeData(String dataPath) + { + _dataPath = dataPath; } public OracleConnection getOracleConnection() @@ -355,6 +371,38 @@ private void updateDataStore() { // todo: + Iterator it = featuresContext.keySet().iterator(); + + try + { + while (it.hasNext()) + { + FeatureType featureType = (FeatureType) it.next(); + File sfile = new File(_dataPath + "\\" + featureType.getTypeName()); + ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURL()); + shapefileDataStore.createSchema(featureType); + FeatureWriter writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); + ArrayList features = (ArrayList) featuresContext.get(featureType); + Iterator itFeature = features.iterator(); + while (itFeature.hasNext()) + { + Feature feature = (Feature) itFeature.next(); + ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null)); + } + writer.close(); + } + 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); + } + } } -- Gitblit v0.0.0-SNAPSHOT