Revision: 5765
          http://sourceforge.net/p/jump-pilot/code/5765
Author:   michaudm
Date:     2018-04-12 06:31:49 +0000 (Thu, 12 Apr 2018)
Log Message:
-----------
Fix #470 : fix transaction manager management (more tests needed)

Modified Paths:
--------------
    core/trunk/ChangeLog
    core/trunk/src/org/openjump/OpenJumpConfiguration.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/SaveToPostGIS2PlugIn.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManager.java
    
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManagerPlugIn.java
    core/trunk/src/org/openjump/core/ui/plugin/file/SaveWizardPlugIn.java

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2018-04-11 22:31:31 UTC (rev 5764)
+++ core/trunk/ChangeLog        2018-04-12 06:31:49 UTC (rev 5765)
@@ -8,6 +8,7 @@
 2018-04-12 mmichaud <m.michael.mich...@orange.fr>
   * Fix #473 : shapefile driver no more limited to 4G files
   * Fix #471 : small bug in PostGIS (new) driver UI
+  * Fix #470 : fix transaction manager management (more tests needed)
 
 2018-04-07 Giuseppe Aruta
 

Modified: core/trunk/src/org/openjump/OpenJumpConfiguration.java
===================================================================
--- core/trunk/src/org/openjump/OpenJumpConfiguration.java      2018-04-11 
22:31:31 UTC (rev 5764)
+++ core/trunk/src/org/openjump/OpenJumpConfiguration.java      2018-04-12 
06:31:49 UTC (rev 5765)
@@ -148,7 +148,8 @@
     // [mmichaud 2013-11-08] add new AddWritableDataStoreLayerWizard
       AddWritableDataStoreLayerWizard addWritableDataStoreLayerWizard =
               new AddWritableDataStoreLayerWizard(
-              workbenchContext, 
DataStoreTransactionManager.getTransactionManager());
+              workbenchContext, DataStoreTransactionManager.getTxInstance(
+                      
"org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager"));
       OpenWizardPlugIn.addWizard(workbenchContext, 
addWritableDataStoreLayerWizard);
     
     // [mmichaud 2012-09-01] changed how RasterImageLayerRendererFactory is 
initialized to fix bug 3526653

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
   2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
   2018-04-12 06:31:49 UTC (rev 5765)
@@ -138,7 +138,8 @@
                 DataStoreDataSourceFactory.createWritableDataStoreDataSource(
                         connectionDescriptor, datasetName, 
geometryAttributeName,
                         identifierAttributeName, true,
-                        txManager, workbenchContext);
+                        
"org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager",
+                        workbenchContext);
         ds.setMaxFeature(limit);
         ds.setWhereClause(whereClause);
         ds.setLimitedToView(limitedToView);

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java
        2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java
        2018-04-12 06:31:49 UTC (rev 5765)
@@ -21,7 +21,7 @@
             String geometryAttributeName,
             String externalPKName,
             boolean tableAlreadyCreated,
-            DataStoreTransactionManager txManager,
+            String txManagerClass,
             WorkbenchContext context)  throws Exception {
         WritableDataStoreDataSource source;
         String driverName = connectionDescriptor.getDataStoreDriverClassName();
@@ -28,12 +28,14 @@
         if 
(driverName.equals(com.vividsolutions.jump.datastore.postgis.PostgisDataStoreDriver.class.getName()))
 {
             source = new PostGISDataStoreDataSource(
                     connectionDescriptor, datasetName, geometryAttributeName, 
externalPKName,
-                    txManager, context);
+                    txManagerClass,
+                    context);
             source.setTableAlreadyCreated(tableAlreadyCreated);
         } else if 
(driverName.equals(com.vividsolutions.jump.datastore.h2.H2DataStoreDriver.class.getName()))
 {
             source = new H2DataStoreDataSource(
                     connectionDescriptor, datasetName, geometryAttributeName, 
externalPKName,
-                    txManager, context);
+                    txManagerClass,
+                    context);
             source.setTableAlreadyCreated(tableAlreadyCreated);
         } else {
             throw new Exception(I18N.getMessage(KEY + 
".no-writable-datastore-datasource", driverName));

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java 
    2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java 
    2018-04-12 06:31:49 UTC (rev 5765)
@@ -68,7 +68,7 @@
             geometryAttributeName,
             WritableDataStoreDataSource.DEFAULT_PK_NAME,
             false,
-            txManager,
+            
"org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager",
             context.getWorkbenchContext());
 
     
writableDS.getProperties().put(WritableDataStoreDataSource.CONNECTION_DESCRIPTOR_KEY,

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
       2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
       2018-04-12 06:31:49 UTC (rev 5765)
@@ -60,15 +60,14 @@
     public static final String CONVERT_TO_MULTIGEOMETRY_KEY = "Convert to 
multigeometry";
     public static final String CREATE_PK                    = "Create PK";
     public static final String NORMALIZED_COLUMN_NAMES      = "Normalized 
Column Names";
+    public static final String TX_MANAGER_KEY               = "TxManager";
 
     public static final String DEFAULT_PK_NAME   = "gid";
 
     // Ordered Map of evolutions
     // Map is indexed by FID in order to merge successive evolutions of a 
feature efficiently
-    final private LinkedHashMap<Integer,Evolution> evolutions = new 
LinkedHashMap<>();
+    final protected LinkedHashMap<Integer,Evolution> evolutions = new 
LinkedHashMap<>();
 
-    private DataStoreTransactionManager txManager;
-
     // See setTableAlreadyCreated()
     private boolean tableAlreadyCreated = true;
 
@@ -79,6 +78,8 @@
     // primary key name
     protected String primaryKeyName = DEFAULT_PK_NAME;
 
+    private String txManagerClass;
+
     public WritableDataStoreDataSource() {
         // Called by Java2XML [Jon Aquino 2005-03-16]
     }
@@ -94,7 +95,7 @@
                                        String datasetName,
                                        String geometryAttributeName,
                                        String externalPKName,
-                                       DataStoreTransactionManager txManager,
+                                       String txManager,
                                        WorkbenchContext context) {
         setProperties(CollectionUtil.createMap(new Object[]{
                 CONNECTION_DESCRIPTOR_KEY, connectionDescriptor,
@@ -101,6 +102,7 @@
                 DATASET_NAME_KEY, datasetName,
                 GEOMETRY_ATTRIBUTE_NAME_KEY, geometryAttributeName,
                 EXTERNAL_PK_KEY, externalPKName,
+                TX_MANAGER_KEY, txManager
 
         }));
         // default options
@@ -112,7 +114,6 @@
         //getProperties().put(CREATE_TABLE, false);
         getProperties().put(CREATE_PK, false);
         getProperties().put(SRID_KEY, 0);
-        this.txManager = txManager;
         this.context = context;
     }
 
@@ -585,6 +586,9 @@
                 // We connect to a new table : the transaction manager must 
listen to it
                 if (!tableAlreadyCreated) {
                     
//DataStoreTransactionManager.getTransactionManager().registerLayer(selectedLayers[0],
+                    DataStoreTransactionManager txManager =
+                            DataStoreTransactionManager.getTxInstance(
+                                    
"org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager");
                     txManager.registerLayer(selectedLayers[0],
                             
JUMPWorkbench.getInstance().getContext().getTask());
                     tableAlreadyCreated = true;
@@ -599,7 +603,7 @@
      * Return 3 if coll contains at least one 3d geometry, 2 if coll contains
      * only 2d geometries and defaultDim if coll is empty.
      */
-    private static int getGeometryDimension(FeatureCollection coll, int 
defaultDim) {
+    protected static int getGeometryDimension(FeatureCollection coll, int 
defaultDim) {
         if (coll.size() > 0) {
             // will explore up to 1000 features regularly distributed in the 
dataset
             // if none of these feature has dim = 3, return 2, else return 3
@@ -635,7 +639,7 @@
      *   type (multi) for geometries of same dimension (single or multi)</li>
      * </ul>
      */
-    private static Class getGeometryType(FeatureCollection coll, boolean 
narrow, boolean multi) {
+    protected static Class getGeometryType(FeatureCollection coll, boolean 
narrow, boolean multi) {
         if (!narrow && !multi) return Geometry.class;
         Class[] classes = new Class[]{
                 Point.class,

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
  2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
  2018-04-12 06:31:49 UTC (rev 5765)
@@ -41,11 +41,14 @@
             String datasetName,
             String geometryAttributeName,
             String identifierAttributeName,
-            DataStoreTransactionManager txManager,
+            String txManagerClass,
             WorkbenchContext context) {
         super(connectionDescriptor,
-                datasetName, geometryAttributeName, identifierAttributeName,
-                txManager, context);
+                datasetName,
+                geometryAttributeName,
+                identifierAttributeName,
+                txManagerClass,
+                context);
     }
 
     /**

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
       2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
       2018-04-12 06:31:49 UTC (rev 5765)
@@ -43,11 +43,14 @@
             String datasetName,
             String geometryAttributeName,
             String identifierAttributeName,
-            DataStoreTransactionManager txManager,
+            String txManagerClass,
             WorkbenchContext context) {
         super(connectionDescriptor,
-                datasetName, geometryAttributeName, identifierAttributeName,
-                txManager, context);
+                datasetName,
+                geometryAttributeName,
+                identifierAttributeName,
+                txManagerClass,
+                context);
     }
 
     /**

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/SaveToPostGIS2PlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/SaveToPostGIS2PlugIn.java
     2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/SaveToPostGIS2PlugIn.java
     2018-04-12 06:31:49 UTC (rev 5765)
@@ -1,6 +1,8 @@
 package org.openjump.core.ui.plugin.datastore.postgis2;
 
+import com.vividsolutions.jump.workbench.WorkbenchContext;
 import 
com.vividsolutions.jump.workbench.datasource.DataSourceQueryChooserManager;
+import com.vividsolutions.jump.workbench.datastore.ConnectionDescriptor;
 import com.vividsolutions.jump.workbench.plugin.PlugIn;
 import com.vividsolutions.jump.workbench.plugin.PlugInContext;
 import org.openjump.core.ui.plugin.datastore.WritableDataStoreDataSource;
@@ -21,7 +23,6 @@
      */
     public void initialize(PlugInContext context) {
         WritableDataStoreDataSource dataSource = new 
PostGISDataStoreDataSource();
-
         saveChooser = new PostGISSaveDataSourceQueryChooser(dataSource, 
context);
 
         DataSourceQueryChooserManager.get(

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManager.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManager.java
   2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManager.java
   2018-04-12 06:31:49 UTC (rev 5765)
@@ -1,11 +1,6 @@
 package org.openjump.core.ui.plugin.datastore.transaction;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.*;
 
 import org.openjump.core.ui.plugin.datastore.WritableDataStoreDataSource;
 
@@ -39,7 +34,9 @@
 
     final String KEY = DataStoreTransactionManager.class.getName();
 
-    private static DataStoreTransactionManager TXMANAGER;
+    private final static Map<String, DataStoreTransactionManager> 
transactionManagers = new HashMap();
+
+    //private static DataStoreTransactionManager TXMANAGER;
     private WeakHashMap<Layer,Task> registeredLayers = new WeakHashMap<>();
     private WeakHashMap<Task,LayerListener> registeredListeners = new 
WeakHashMap<>();
 
@@ -49,17 +46,38 @@
      */
     protected DataStoreTransactionManager() {}
 
+    public static <T extends DataStoreTransactionManager> T 
getTxInstance(String clazz) {
+        try {
+            synchronized( transactionManagers ) {
+                DataStoreTransactionManager tx = 
transactionManagers.get(clazz);
+                if(null == tx) {
+                    tx = 
(DataStoreTransactionManager)Class.forName(clazz).newInstance();
+                    transactionManagers.put(clazz, tx);
+                }
+                @SuppressWarnings("unchecked")
+                T tmp = (T) tx;
+                return tmp;
+            }
+
+        } catch (Exception e) {
+            Logger.info( "Unable to create DataStoreTransactionManager for " + 
clazz );
+            throw new RuntimeException(e);
+        }
+    }
+
     /**
      * Get the unique DataStoreTransactionManager.
      * @return JUMPWorkbench's DataStoreTransactionManager
      */
-    public static DataStoreTransactionManager getTransactionManager() {
-        if (TXMANAGER == null) {
-          TXMANAGER = new DataStoreTransactionManager();
-        }
-        return TXMANAGER;
-    }
+    //public static DataStoreTransactionManager getTransactionManager() {
+    //    if (TXMANAGER == null) {
+    //      TXMANAGER = new DataStoreTransactionManager();
+    //    }
+    //    return TXMANAGER;
+    //}
 
+
+
     /**
      * Register a new Layer in the DataStoreTransactionManager.
      * Edits happening in this Layer will be recorded in the associated

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManagerPlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManagerPlugIn.java
     2018-04-11 22:31:31 UTC (rev 5764)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/datastore/transaction/DataStoreTransactionManagerPlugIn.java
     2018-04-12 06:31:49 UTC (rev 5765)
@@ -92,7 +92,8 @@
     }
 
     protected DataStoreTransactionManager getTransactionManager() {
-      return DataStoreTransactionManager.getTransactionManager();
+      //return DataStoreTransactionManager.getTransactionManager();
+        return 
DataStoreTransactionManager.getTxInstance("org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager");
     }
 
     protected void initializeToolbox(final ToolboxDialog toolbox) {

Modified: core/trunk/src/org/openjump/core/ui/plugin/file/SaveWizardPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/file/SaveWizardPlugIn.java       
2018-04-11 22:31:31 UTC (rev 5764)
+++ core/trunk/src/org/openjump/core/ui/plugin/file/SaveWizardPlugIn.java       
2018-04-12 06:31:49 UTC (rev 5765)
@@ -69,7 +69,7 @@
     if (!JUMPVersion.getRelease().equalsIgnoreCase("release"))
       addWizard(context.getWorkbenchContext(),
               new SaveToDataStoreWizard(context,
-                      DataStoreTransactionManager.getTransactionManager()));
+                      
DataStoreTransactionManager.getTxInstance("org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager")));
   }
 
   public boolean execute(PlugInContext pluginContext) throws Exception {


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to