You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2008/02/28 20:08:22 UTC

svn commit: r632093 - /db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java

Author: kristwaa
Date: Thu Feb 28 11:08:20 2008
New Revision: 632093

URL: http://svn.apache.org/viewvc?rev=632093&view=rev
Log:
DERBY-3329 (partial): Enable statement pooling in the client JDBC driver.
NB! This patch does not enable statement pooling.
Made sure state is initialized before the reference to self is published, and also moved some code not throwing exceptions out of try-catch blocks.
Added method isStatementPoolingEnabled.
Patch file: derby-3329-1b-enable_statement_pooling.diff

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java?rev=632093&r1=632092&r2=632093&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java Thu Feb 28 11:08:20 2008
@@ -32,6 +32,7 @@
 import org.apache.derby.jdbc.ClientDriver;
 import org.apache.derby.client.am.ClientMessageId;
 import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
 import org.apache.derby.client.net.NetLogWriter;
 import org.apache.derby.shared.common.reference.SQLState;
 
@@ -50,6 +51,13 @@
     org.apache.derby.client.net.NetConnection netPhysicalConnection_ = null;
     org.apache.derby.client.net.NetXAConnection netXAPhysicalConnection_ = null;
 
+    /**
+     * The statement cache for the underlying physical connection.
+     * <p>
+     * This will be {@code null} if statement caching is disabled (default).
+     */
+    private final JDBCStatementCache statementCache;
+
     /** The logical connection using the physical connection. */
     //@GuardedBy("this")
     org.apache.derby.client.am.LogicalConnection logicalConnection_ = null;
@@ -81,14 +89,21 @@
                                   org.apache.derby.client.am.LogWriter logWriter,
                                   String user,
                                   String password) throws SQLException {
-        try
-        {
-            logWriter_ = logWriter;
-            ds_ = ds;
-            user_ = user;
-            password_ = password;
-            listeners_ = new ArrayList();
-            
+        logWriter_ = logWriter;
+        ds_ = ds;
+        user_ = user;
+        password_ = password;
+        listeners_ = new ArrayList();
+
+        if (ds.maxStatementsToPool() <= 0) {
+            this.statementCache = null;
+        } else {
+            // Disabled for now.
+            this.statementCache = null;
+            //        new JDBCStatementCache(ds.maxStatementsToPool());
+        }
+
+        try {
             //pass the client pooled connection instance to this
             //instance of the NetConnection object 
             //this object is then used to pass the close and the error events 
@@ -105,13 +120,10 @@
                     -1,
                     false,
                     this);
-        
-        physicalConnection_ = netPhysicalConnection_;
-        }
-        catch ( SqlException se )
-        {
+        } catch (SqlException se) {
             throw se.getSQLException();
         }
+        physicalConnection_ = netPhysicalConnection_;
     }
 
     /**
@@ -133,22 +145,40 @@
                                   String user,
                                   String password,
                                   int rmId) throws SQLException {
+        logWriter_ = logWriter;
+        ds_ = ds;
+        user_ = user;
+        password_ = password;
+        rmId_ = rmId;
+        listeners_ = new ArrayList();
+
+        if (ds.maxStatementsToPool() <= 0) {
+            this.statementCache = null;
+        } else {
+            // NOTE: Disable statement pooling for XA for now.
+            this.statementCache = null;
+            //        new JDBCStatementCache(ds.maxStatementsToPool());
+        }
+
         try {
-            logWriter_ = logWriter;
-            ds_ = ds;
-            user_ = user;
-            password_ = password;
-            rmId_ = rmId;
-            listeners_ = new ArrayList();
             netXAPhysicalConnection_ = getNetXAConnection(ds,
                     (NetLogWriter) logWriter_,
                     user,
                     password,
                     rmId);
-            physicalConnection_ = netXAPhysicalConnection_.getNetConnection();
         } catch ( SqlException se ) {
             throw se.getSQLException();
         }
+        physicalConnection_ = netXAPhysicalConnection_.getNetConnection();
+    }
+
+    /**
+     * Tells is statement pooling is enabled or not.
+     *
+     * @return {@code true} if enabled, {@code false} if disabled.
+     */
+    public boolean isStatementPoolingEnabled() {
+        return this.statementCache != null;
     }
 
     protected void finalize() throws java.lang.Throwable {
@@ -268,9 +298,15 @@
         if (logicalConnection_ != null) {
             logicalConnection_.closeWithoutRecyclingToPool();
         }
-        logicalConnection_ = ClientDriver.getFactory().newLogicalConnection(
+        if (this.statementCache == null) {
+            logicalConnection_ = ClientDriver.getFactory().newLogicalConnection(
                                                         physicalConnection_,
                                                         this);
+        } else {
+            logicalConnection_ = ClientDriver.getFactory().
+                    newCachingLogicalConnection(
+                            physicalConnection_, this, statementCache);
+        }
     }
 
     public synchronized void addConnectionEventListener(