From 6de5086ab3e8e7fa852b1e5d9a31aabade25e017 Mon Sep 17 00:00:00 2001
From: ?? ? <neonhuang@hotmail.com>
Date: Thu, 27 Mar 2008 17:20:12 +0800
Subject: [PATCH] 

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java |   50 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java
index 9906d61..a9b627b 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java
@@ -38,6 +38,7 @@
 import com.ximple.io.dgn7.Element;
 import com.ximple.io.dgn7.FrammeAttributeData;
 
+
 public class OracleConvertJobContext extends AbstractOracleJobContext
 {
     static Log logger = LogFactory.getLog(OracleConvertJobContext.class);
@@ -59,6 +60,7 @@
     private ElementDispatcher elementDispatcher;
 
     private HashMap featuresContext = new HashMap();
+    private HashMap featuresWriterContext = new HashMap();
     private PessimisticMapWrapper txFeaturesContext;
 
     private JobExecutionContext executionContext;
@@ -137,17 +139,19 @@
 
     public void startTransaction()
     {
-        txFeaturesContext.startTransaction();
+       //txFeaturesContext.startTransaction();
     }
 
     public void commitTransaction()
     {
-        if (!txFeaturesContext.isEmpty())
-        {
+       if (!txFeaturesContext.isEmpty())
+       {
             logger.debug("Transaction size = " + txFeaturesContext.size());
-            txFeaturesContext.commitTransaction();
+           //txFeaturesContext.commitTransaction();
         } else
+        {
             logger.debug("Transaction is empty.");
+        }
 
         if (!featuresContext.isEmpty())
         {
@@ -157,7 +161,7 @@
 
     public void rollbackTransaction()
     {
-        txFeaturesContext.rollbackTransaction();
+       //txFeaturesContext.rollbackTransaction();
         if (!featuresContext.isEmpty())
         {
             updateDataStore();
@@ -167,7 +171,7 @@
     private void updateDataStore()
     {
         // todo:
-        Iterator it = featuresContext.keySet().iterator();
+        Iterator it = featuresContext.keySet().iterator();  
 
         try
         {
@@ -177,9 +181,23 @@
                 File sfile = new File(_dataPath + "\\" + featureType.getTypeName());
                 logger.debug("Begin Save shapefile:" + sfile.toURI());
 
-                ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL());
-                shapefileDataStore.createSchema(featureType);
-                FeatureWriter writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT);
+                FeatureWriter writer = null;
+                if(featuresWriterContext.containsKey( featureType.getTypeName()))
+                {
+                    writer = (FeatureWriter) featuresWriterContext.get(featureType.getTypeName()) ;
+                }
+                else
+                {
+                  ShapefileDataStore shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL());
+                  shapefileDataStore.createSchema(featureType);
+                  writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT);
+                  if(this.featuresWriterContext == null)
+                  {
+                     this.featuresWriterContext =  new HashMap();
+                  }
+                  featuresWriterContext.put(featureType.getTypeName() , writer);
+                }
+
                 ArrayList features = (ArrayList) featuresContext.get(featureType);
                 Iterator itFeature = features.iterator();
                 while (itFeature.hasNext())
@@ -187,7 +205,7 @@
                     Feature feature = (Feature) itFeature.next();
                     ((SimpleFeature) writer.next()).setAttributes(feature.getAttributes(null));
                 }
-                writer.close();
+                //writer.close();
                 logger.debug("End Save shapefile:" + sfile.toURI());
             }
             featuresContext.clear();
@@ -213,4 +231,16 @@
     {
         executionContext = context;
     }
+
+    public void closeFeatureWrite() throws IOException {
+       Iterator iter =   this.featuresWriterContext.values().iterator();
+
+        while(iter.hasNext())
+        {
+           FeatureWriter writer = (FeatureWriter) iter.next();
+           writer.close();
+        }
+
+        this.featuresWriterContext = null;
+    }
 }

--
Gitblit v0.0.0-SNAPSHOT