The attached patch provides support for the three currently unsupported
Connection properties ("catalog", "transaction isolation", and "type
map").  To keep backwards compatability, the defaults for these
newly-supported properties are only used if explicitly set by the
client.  Thus, the hard-coded "defaults for the defaults" are never
used.

Enjoy!

-Russ

-----Original Message-----
From: Rodney Waldhoff [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 19, 2003 6:17 AM
To: Jakarta Commons Developers List
Subject: Re: [DBCP] Support for other default Connection properties?


As far a I know, these additional properties simply aren't exposed at a
"default" level (although as you note, are accessible via the regular
API).

Patches welcome.

On Wed, 19 Feb 2003, Russ Milliken wrote:

> Is there support for default Connection properties other than ReadOnly

> and AutoCommit?  You can create a PoolableConnectionFactory specifying

> defaultReadOnly and defaultAutoCommit at construction time, or may 
> change the defaults at any time thereafter via API methods.  This is 
> good, but what of the other properties on Connection, e.g. Catalog, 
> TransactionIsolation, and TypeMap?  Are these in DBCP somewhere else, 
> and if so, shouldn't these all be in one place, i.e., 
> PoolableConnectionFactory?
>
> -Russ
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Index: src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java,v
retrieving revision 1.4
diff -u -r1.4 PoolableConnectionFactory.java
--- src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java     29 Jun 2002 
16:46:02 -0000      1.4
+++ src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java     21 Feb 2003 
21:48:36 -0000
@@ -65,6 +65,7 @@
 import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Map;
 import org.apache.commons.pool.*;
 
 /**
@@ -180,6 +181,33 @@
         _defaultAutoCommit = defaultAutoCommit;
     }
 
+    /**
+     * Sets the default "catalog" setting for borrowed [EMAIL PROTECTED] Connection}s
+     * @param defaultCatalog the default "catalog" setting for borrowed [EMAIL 
PROTECTED] Connection}s
+     */
+    public void setDefaultCatalog(String defaultCatalog) {
+        _defaultCatalog = defaultCatalog;
+        _defaultCatalogExplicitlySet = true;
+    }
+
+    /**
+     * Sets the default "transaction isolation" setting for borrowed [EMAIL 
PROTECTED] Connection}s
+     * @param defaultTransactionIsolation the default "transaction isolation" setting 
for borrowed [EMAIL PROTECTED] Connection}s
+     */
+    public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
+        _defaultTransactionIsolation = defaultTransactionIsolation;
+        _defaultTransactionIsolationExplicitlySet = true;
+    }
+
+    /**
+     * Sets the default "type map" setting for borrowed [EMAIL PROTECTED] Connection}s
+     * @param defaultTypeMap the default "type map" setting for borrowed [EMAIL 
PROTECTED] Connection}s
+     */
+    public void setDefaultTypeMap(Map defaultTypeMap) {
+        _defaultTypeMap = defaultTypeMap;
+        _defaultTypeMapExplicitlySet = true;
+    }
+
     synchronized public Object makeObject() throws Exception {
         Connection conn = _connFactory.createConnection();
         if(null != _stmtPoolFactory) {
@@ -279,6 +307,27 @@
             } catch(SQLException e) {
                 ; // ignored
             }
+            if (_defaultCatalogExplicitlySet) {
+                try {
+                    conn.setCatalog(_defaultCatalog);
+                } catch(SQLException e) {
+                    ; // ignored
+                }
+            }
+            if (_defaultTransactionIsolationExplicitlySet) {
+                try {
+                    conn.setTransactionIsolation(_defaultTransactionIsolation);
+                } catch(SQLException e) {
+                    ; // ignored
+                }
+            }
+            if (_defaultTypeMapExplicitlySet) {
+                try {
+                    conn.setTypeMap(_defaultTypeMap);
+                } catch(SQLException e) {
+                    ; // ignored
+                }
+            }
         }
     }
 
@@ -288,5 +337,11 @@
     protected KeyedObjectPoolFactory _stmtPoolFactory = null;
     protected boolean _defaultReadOnly = false;
     protected boolean _defaultAutoCommit = true;
+    protected String _defaultCatalog = null;
+    protected boolean _defaultCatalogExplicitlySet = false;
+    protected int _defaultTransactionIsolation = -1;
+    protected boolean _defaultTransactionIsolationExplicitlySet = false;
+    protected Map _defaultTypeMap = null;
+    protected boolean _defaultTypeMapExplicitlySet = false;
     protected AbandonedConfig _config = null;
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to