You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/12/03 00:30:25 UTC

svn commit: r1547238 - in /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources: InstanceKeyDataSource.java InstanceKeyObjectFactory.java PerUserPoolDataSource.java PerUserPoolDataSourceFactory.java SharedPoolDataSource.java

Author: markt
Date: Mon Dec  2 23:30:25 2013
New Revision: 1547238

URL: http://svn.apache.org/r1547238
Log:
Fix DBCP-404 for the o.a.c.dbcp2.datasources package

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSourceFactory.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java?rev=1547238&r1=1547237&r2=1547238&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java Mon Dec  2 23:30:25 2013
@@ -114,7 +114,7 @@ public abstract class InstanceKeyDataSou
     private String description = null;
 
     /** Environment that may be used to set up a jndi initial context. */
-    Properties jndiEnvironment = null;
+    private Properties jndiEnvironment = null;
 
     /** Login TimeOut in seconds */
     private int loginTimeout = 0;
@@ -146,7 +146,7 @@ public abstract class InstanceKeyDataSou
     private boolean testPositionSet = false;
 
     /** Instance key */
-    protected String instanceKey = null; // TODO make packge protected?
+    private String instanceKey = null; // TODO make packge protected?
 
     /**
      * Default no-arg constructor for Serialization
@@ -366,6 +366,10 @@ public abstract class InstanceKeyDataSou
         this.description = v;
     }
 
+    protected String getInstanceKey() {
+        return instanceKey;
+    }
+    
     /**
      * Get the value of jndiEnvironment which is used when instantiating
      * a jndi InitialContext.  This InitialContext is used to locate the
@@ -395,6 +399,23 @@ public abstract class InstanceKeyDataSou
         }
         jndiEnvironment.setProperty(key, value);
     }
+    
+    /**
+     * Sets the JNDI environment to be used when instantiating a JNDI
+     * InitialContext. This InitialContext is used to locate the backend
+     * ConnectionPoolDataSource.
+     *
+     * @param properties the JNDI environment property to set which will
+     *                   overwrite any current settings
+     */
+    void setJndiEnvironment(Properties properties) {
+        if (jndiEnvironment == null) {
+            jndiEnvironment = new Properties();
+        } else {
+            jndiEnvironment.clear();
+        }
+        jndiEnvironment.putAll(properties);
+    }
 
     /**
      * Get the value of loginTimeout.

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java?rev=1547238&r1=1547237&r2=1547238&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java Mon Dec  2 23:30:25 2013
@@ -160,8 +160,7 @@ abstract class InstanceKeyObjectFactory
         ra = ref.get("jndiEnvironment");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            ikds.jndiEnvironment =
-                (Properties) deserialize(serialized);
+            ikds.setJndiEnvironment((Properties) deserialize(serialized));
         }
 
         ra = ref.get("loginTimeout");

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1547238&r1=1547237&r2=1547238&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java Mon Dec  2 23:30:25 2013
@@ -69,12 +69,12 @@ public class PerUserPoolDataSource exten
     private int defaultMaxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
     private int defaultMaxWaitMillis = (int)Math.min(Integer.MAX_VALUE,
             GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS);
-    Map<String,Boolean> perUserDefaultAutoCommit = null;
-    Map<String,Integer> perUserDefaultTransactionIsolation = null;
-    Map<String,Integer> perUserMaxTotal = null;
-    Map<String,Integer> perUserMaxIdle = null;
-    Map<String,Integer> perUserMaxWaitMillis = null;
-    Map<String,Boolean> perUserDefaultReadOnly = null;
+    private Map<String,Boolean> perUserDefaultAutoCommit = null;
+    private Map<String,Integer> perUserDefaultTransactionIsolation = null;
+    private Map<String,Integer> perUserMaxTotal = null;
+    private Map<String,Integer> perUserMaxIdle = null;
+    private Map<String,Integer> perUserMaxWaitMillis = null;
+    private Map<String,Boolean> perUserDefaultReadOnly = null;
 
     /**
      * Map to keep track of Pools for a given user
@@ -100,7 +100,7 @@ public class PerUserPoolDataSource exten
                     //ignore and try to close others.
             }
         }
-        InstanceKeyObjectFactory.removeInstance(instanceKey);
+        InstanceKeyObjectFactory.removeInstance(getInstanceKey());
     }
 
     // -------------------------------------------------------------------
@@ -198,6 +198,16 @@ public class PerUserPoolDataSource exten
         perUserDefaultAutoCommit.put(username, value);
     }
 
+    void setPerUserDefaultAutoCommit(Map<String,Boolean> userDefaultAutoCommit) {
+        assertInitializationAllowed();
+        if (perUserDefaultAutoCommit == null) {
+            perUserDefaultAutoCommit = new HashMap<>();
+        } else {
+            perUserDefaultAutoCommit.clear();
+        }
+        perUserDefaultAutoCommit.putAll(userDefaultAutoCommit);
+    }
+
     /**
      * The isolation level of connections when returned from getConnection.
      * If null, the username will use the value of defaultTransactionIsolation.
@@ -223,6 +233,17 @@ public class PerUserPoolDataSource exten
         perUserDefaultTransactionIsolation.put(username, value);
     }
 
+    void setPerUserDefaultTransactionIsolation(
+            Map<String,Integer> userDefaultTransationIsolation) {
+        assertInitializationAllowed();
+        if (perUserDefaultTransactionIsolation == null) {
+            perUserDefaultTransactionIsolation = new HashMap<>();
+        } else {
+            perUserDefaultTransactionIsolation.clear();
+        }
+        perUserDefaultTransactionIsolation.putAll(userDefaultTransationIsolation);
+    }
+
     /**
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or non-positive for no limit.
@@ -251,6 +272,15 @@ public class PerUserPoolDataSource exten
         perUserMaxTotal.put(username, value);
     }
 
+    void setPerUserMaxTotal(Map<String,Integer> userMaxTotal) {
+        assertInitializationAllowed();
+        if (perUserMaxTotal == null) {
+            perUserMaxTotal = new HashMap<>();
+        } else {
+            perUserMaxTotal.clear();
+        }
+        perUserMaxTotal.putAll(userMaxTotal);
+    }
 
     /**
      * The maximum number of active connections that can remain idle in the
@@ -280,6 +310,16 @@ public class PerUserPoolDataSource exten
         perUserMaxIdle.put(username, value);
     }
 
+    void setPerUserMaxIdle(Map<String,Integer> userMaxIdle) {
+        assertInitializationAllowed();
+        if (perUserMaxIdle == null) {
+            perUserMaxIdle = new HashMap<>();
+        } else {
+            perUserMaxIdle.clear();
+        }
+        perUserMaxIdle.putAll(userMaxIdle);
+    }
+
     /**
      * The maximum number of milliseconds that the pool will wait (when there
      * are no available connections) for a connection to be returned before
@@ -312,6 +352,16 @@ public class PerUserPoolDataSource exten
         perUserMaxWaitMillis.put(username, value);
     }
 
+    void setPerUserMaxWaitMillis(Map<String,Integer> userMaxWaitMillis) {
+        assertInitializationAllowed();
+        if (perUserMaxWaitMillis == null) {
+            perUserMaxWaitMillis = new HashMap<>();
+        } else {
+            perUserMaxWaitMillis.clear();
+        }
+        perUserMaxWaitMillis.putAll(userMaxWaitMillis);
+    }
+
     /**
      * The keys are usernames and the value is the --.  Any
      * username specified here will override the value of defaultReadOnly.
@@ -336,6 +386,16 @@ public class PerUserPoolDataSource exten
         perUserDefaultReadOnly.put(username, value);
     }
 
+    void setPerUserDefaultReadOnly(Map<String,Boolean> userDefaultReadOnly) {
+        assertInitializationAllowed();
+        if (perUserDefaultReadOnly == null) {
+            perUserDefaultReadOnly = new HashMap<>();
+        } else {
+            perUserDefaultReadOnly.clear();
+        }
+        perUserDefaultReadOnly.putAll(userDefaultReadOnly);
+    }
+
     // ----------------------------------------------------------------------
     // Instrumentation Methods
 
@@ -488,7 +548,7 @@ public class PerUserPoolDataSource exten
     public Reference getReference() throws NamingException {
         Reference ref = new Reference(getClass().getName(),
                 PerUserPoolDataSourceFactory.class.getName(), null);
-        ref.add(new StringRefAddr("instanceKey", instanceKey));
+        ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
         return ref;
     }
 

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSourceFactory.java?rev=1547238&r1=1547237&r2=1547238&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSourceFactory.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSourceFactory.java Mon Dec  2 23:30:25 2013
@@ -65,43 +65,43 @@ public class PerUserPoolDataSourceFactor
         ra = ref.get("perUserDefaultAutoCommit");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserDefaultAutoCommit =
-                (Map<String,Boolean>) deserialize(serialized);
+            pupds.setPerUserDefaultAutoCommit(
+                    (Map<String,Boolean>) deserialize(serialized));
         }
 
         ra = ref.get("perUserDefaultTransactionIsolation");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserDefaultTransactionIsolation = 
-                (Map<String,Integer>) deserialize(serialized);
+            pupds.setPerUserDefaultTransactionIsolation( 
+                    (Map<String,Integer>) deserialize(serialized));
         }
 
         ra = ref.get("perUserMaxTotal");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserMaxTotal =
-                (Map<String,Integer>) deserialize(serialized);
+            pupds.setPerUserMaxTotal(
+                    (Map<String,Integer>) deserialize(serialized));
         }
         
         ra = ref.get("perUserMaxIdle");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserMaxIdle =
-                (Map<String,Integer>) deserialize(serialized);
+            pupds.setPerUserMaxIdle(
+                    (Map<String,Integer>) deserialize(serialized));
         }
         
         ra = ref.get("perUserMaxWaitMillis");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserMaxWaitMillis =
-                (Map<String,Integer>) deserialize(serialized);
+            pupds.setPerUserMaxWaitMillis(
+                    (Map<String,Integer>) deserialize(serialized));
         }
                 
         ra = ref.get("perUserDefaultReadOnly");
         if (ra != null  && ra.getContent() != null) {
             byte[] serialized = (byte[]) ra.getContent();
-            pupds.perUserDefaultReadOnly =
-                (Map<String,Boolean>) deserialize(serialized);
+            pupds.setPerUserDefaultReadOnly(
+                    (Map<String,Boolean>) deserialize(serialized));
         }
         return pupds;
     }            

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java?rev=1547238&r1=1547237&r2=1547238&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java Mon Dec  2 23:30:25 2013
@@ -75,7 +75,7 @@ public class SharedPoolDataSource
         if (pool != null) {
             pool.close();
         }
-        InstanceKeyObjectFactory.removeInstance(instanceKey);
+        InstanceKeyObjectFactory.removeInstance(getInstanceKey());
     }
 
     // -------------------------------------------------------------------
@@ -203,7 +203,7 @@ public class SharedPoolDataSource
     public Reference getReference() throws NamingException {
         Reference ref = new Reference(getClass().getName(),
             SharedPoolDataSourceFactory.class.getName(), null);
-        ref.add(new StringRefAddr("instanceKey", instanceKey));
+        ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
         return ref;
     }