commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r447204 - in /jakarta/commons/proper/dbcp/trunk: src/java/org/apache/commons/dbcp/datasources/ xdocs/
Date Mon, 18 Sep 2006 02:55:50 GMT
Author: psteitz
Date: Sun Sep 17 19:55:50 2006
New Revision: 447204

URL: http://svn.apache.org/viewvc?view=rev&rev=447204
Log:
Added rollbackAfterValidation property and code to issue a rollback on a
connection after validation when this property is set to true to eliminate
Oracle driver exceptions. Default property value is false.
JIRA: DBCP-116
Reported and patched by Thomas Fischer

Modified:
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
    jakarta/commons/proper/dbcp/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java
Sun Sep 17 19:55:50 2006
@@ -49,6 +49,7 @@
 
     protected ConnectionPoolDataSource _cpds = null;
     protected String _validationQuery = null;
+    protected boolean _rollbackAfterValidation = false;
     protected ObjectPool _pool = null;
     protected String _username = null;
     protected String _password = null;
@@ -57,13 +58,14 @@
 
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
+     * 
      * @param cpds the ConnectionPoolDataSource from which to obtain
-     *        PooledConnection's
-     * @param pool the {*link ObjectPool} in which to pool those
-     *        {*link Connection}s
-     * @param validationQuery a query to use to {*link #validateObject validate}
-     *        {*link Connection}s. Should return at least one row.
-     *        May be <tt>null</tt>
+     * PooledConnection's
+     * @param pool the {@link ObjectPool} in which to pool those
+     * {@link Connection}s
+     * @param validationQuery a query to use to {@link #validateObject validate}
+     * {@link Connection}s. Should return at least one row. May be 
+     * <tt>null</tt>
      * @param username
      * @param password
      */
@@ -79,6 +81,32 @@
         _username = username;
         _password = password;
     }
+    
+    /**
+     * Create a new <tt>PoolableConnectionFactory</tt>.
+     * 
+     * @param cpds the ConnectionPoolDataSource from which to obtain
+     * PooledConnection's
+     * @param pool the {@link ObjectPool} in which to pool those {@link
+     * Connection}s
+     * @param validationQuery a query to use to {@link #validateObject
+     * validate} {@link Connection}s. Should return at least one row.
+     * May be <tt>null</tt>
+     * @param rollbackAfterValidation whether a rollback should be issued
+     * after {@link #validateObject validating} {@link Connection}s.
+     * @param username
+     * @param password
+     */
+         public CPDSConnectionFactory(ConnectionPoolDataSource cpds,
+                                      ObjectPool pool,
+                                      String validationQuery,
+                                      boolean rollbackAfterValidation,
+                                      String username,
+                                      String password) {
+             this(cpds, pool, validationQuery, username, password);
+             _rollbackAfterValidation = rollbackAfterValidation;
+         }
+
 
     /**
      * Sets the {*link ConnectionFactory} from which to obtain base
@@ -103,6 +131,19 @@
     }
 
     /**
+     * Sets whether a rollback should be issued after 
+     * {*link #validateObject validating} 
+     * {*link Connection}s.
+     * @param rollbackAfterValidation whether a rollback should be issued after
+     *        {*link #validateObject validating} 
+     *        {*link Connection}s.
+     */
+    public synchronized void setRollbackAfterValidation(
+            boolean rollbackAfterValidation) {
+        _rollbackAfterValidation = rollbackAfterValidation;
+    }
+
+    /**
      * Sets the {*link ObjectPool} in which to pool {*link Connection}s.
      * @param pool the {*link ObjectPool} in which to pool those
      *        {*link Connection}s
@@ -173,6 +214,9 @@
                         valid = true;
                     } else {
                         valid = false;
+                    }
+                    if (_rollbackAfterValidation) {
+                        conn.rollback();
                     }
                 } catch (Exception e) {
                     valid = false;

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java
Sun Sep 17 19:55:50 2006
@@ -125,6 +125,7 @@
              GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
     private boolean _testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
     private String validationQuery = null;
+    private boolean rollbackAfterValidation = false;
     private boolean testPositionSet = false;
 
     protected String instanceKey = null;
@@ -608,6 +609,27 @@
         if (!testPositionSet) {
             setTestOnBorrow(true);
         }
+    }
+
+    /**
+     * Whether a rollback will be issued after executing the SQL query 
+     * that will be used to validate connections from this pool
+     * before returning them to the caller.
+     */
+    public boolean isRollbackAfterValidation() {
+        return (this.rollbackAfterValidation);
+    }
+
+    /**
+     * Whether a rollback will be issued after executing the SQL query 
+     * that will be used to validate connections from this pool
+     * before returning them to the caller. Default behavior is NOT
+     * to issue a rollback. The setting will only have an effect
+     * if a validation query is set.
+     */
+    public void setRollbackAfterValidation(boolean rollbackAfterValidation) {
+        assertInitializationAllowed();
+        this.rollbackAfterValidation = rollbackAfterValidation;
     }
 
     // ----------------------------------------------------------------------

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java
Sun Sep 17 19:55:50 2006
@@ -49,6 +49,7 @@
 
     protected ConnectionPoolDataSource _cpds = null;
     protected String _validationQuery = null;
+    protected boolean _rollbackAfterValidation = false;
     protected KeyedObjectPool _pool = null;
     private Map validatingMap = new HashMap();
     private WeakHashMap pcMap = new WeakHashMap();
@@ -69,8 +70,27 @@
     }
 
     /**
-     * Sets the {*link ConnectionFactory} from which to obtain base {*link Connection}s.
-     * @param connFactory the {*link ConnectionFactory} from which to obtain base {*link
Connection}s
+     * Create a new <tt>KeyedPoolableConnectionFactory</tt>.
+     * @param cpds the ConnectionPoolDataSource from which to obtain
+     * PooledConnections
+     * @param pool the {@link ObjectPool} in which to pool those
+     * {@link Connection}s
+     * @param validationQuery a query to use to {@link #validateObject validate}
+     * {@link Connection}s.  Should return at least one row. May be <tt>null</tt>
+     * @param rollbackAfterValidation whether a rollback should be issued after
+     * {@link #validateObject validating} {@link Connection}s.
+     */
+    public KeyedCPDSConnectionFactory(ConnectionPoolDataSource cpds, 
+                                      KeyedObjectPool pool, 
+                                      String validationQuery,
+                                      boolean rollbackAfterValidation) {
+        this(cpds , pool, validationQuery);
+        _rollbackAfterValidation = rollbackAfterValidation;
+    }
+
+    /**
+     * Sets the {@link ConnectionFactory} from which to obtain base {@link Connection}s.
+     * @param connFactory the {*link ConnectionFactory} from which to obtain base {@link
Connection}s
      */
     synchronized public void setCPDS(ConnectionPoolDataSource cpds) {
         _cpds = cpds;
@@ -87,6 +107,19 @@
     }
 
     /**
+     * Sets whether a rollback should be issued after 
+     * {*link #validateObject validating} 
+     * {*link Connection}s.
+     * @param rollbackAfterValidation whether a rollback should be issued after
+     *        {*link #validateObject validating} 
+     *        {*link Connection}s.
+     */
+    public synchronized void setRollbackAfterValidation(
+            boolean rollbackAfterValidation) {
+        _rollbackAfterValidation = rollbackAfterValidation;
+    }
+
+    /**
      * Sets the {*link ObjectPool} in which to pool {*link Connection}s.
      * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s
      */
@@ -165,6 +198,9 @@
                         valid = true;
                     } else {
                         valid = false;
+                    }
+                    if (_rollbackAfterValidation) {
+                        conn.rollback();
                     }
                 } catch(Exception e) {
                     valid = false;

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
Sun Sep 17 19:55:50 2006
@@ -481,6 +481,7 @@
         // the factory with the pool, so we do not have to do so
         // explicitly)
         new CPDSConnectionFactory(cpds, pool, getValidationQuery(),
+                                  isRollbackAfterValidation(), 
                                   username, password);
            
         pools.put(getPoolKey(username), pool);

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
Sun Sep 17 19:55:50 2006
@@ -213,7 +213,8 @@
         // Set up the factory we will use (passing the pool associates
         // the factory with the pool, so we do not have to do so
         // explicitly)
-        new KeyedCPDSConnectionFactory(cpds, pool, getValidationQuery());
+        new KeyedCPDSConnectionFactory(cpds, pool, getValidationQuery(),
+                                       isRollbackAfterValidation());
     }
 
     protected void setupDefaults(Connection con, String username)

Modified: jakarta/commons/proper/dbcp/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/xdocs/changes.xml?view=diff&rev=447204&r1=447203&r2=447204
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/dbcp/trunk/xdocs/changes.xml Sun Sep 17 19:55:50 2006
@@ -140,6 +140,11 @@
         to ensure it is reflexive, even when wrapped connections are not
         DelegatingConnections.
       </action>
+      <action dev="psteitz" type="update" issue="DBCP-116" due-to="Thomas Fischer">
+        Added rollbackAfterValidation property and code to issue a rollback on a
+        connection after validation when this property is set to true to eliminate
+        Oracle driver exceptions. Default property value is false.
+      </action>
     </release>   
 
     <release version="1.2.1" date="2004-06-12" description="Maintenance Release to restore
JDK 1.3 compatibility">



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message