db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r630507 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derby/client/am/
Date Sat, 23 Feb 2008 19:07:57 GMT
Author: kristwaa
Date: Sat Feb 23 11:07:52 2008
New Revision: 630507

URL: http://svn.apache.org/viewvc?rev=630507&view=rev
Log:
DERBY-3328 (DERBY-3326): Change factory method signatures and affected classes in preparation
for later changes.
Patch file: derby-3328-2a-change_signatures.diff

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
    db/derby/code/trunk/java/testing/org/apache/derby/client/am/LogicalStatementEntityTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
Sat Feb 23 11:07:52 2008
@@ -185,26 +185,26 @@
      *
      * @param ps underlying physical prepared statement
      * @param stmtKey key for the underlying physical prepared statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical prepared statement.
      */
-    java.sql.PreparedStatement newLogicalPreparedStatement(
+    LogicalPreparedStatement newLogicalPreparedStatement(
             java.sql.PreparedStatement ps,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache);
+            StatementCacheInteractor cacheInteractor);
 
     /**
      * Returns a new logical callable statement object.
      *
      * @param cs underlying physical callable statement
      * @param stmtKey key for the underlying physical callable statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical callable statement.
      */
-    public java.sql.CallableStatement newLogicalCallableStatement(
+    LogicalCallableStatement newLogicalCallableStatement(
             java.sql.CallableStatement cs,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache);
+            StatementCacheInteractor cacheInteractor);
 
     /**
      * This method returns an instance of NetConnection (or NetConnection40) class

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement.java
Sat Feb 23 11:07:52 2008
@@ -35,7 +35,6 @@
 import java.util.Calendar;
 import java.util.Map;
 
-import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
 import org.apache.derby.client.am.stmtcache.StatementKey;
 
 /**
@@ -59,13 +58,13 @@
      *
      * @param physicalCs underlying physical statement
      * @param stmtKey key for the physical statement
-     * @param cache associated statement cache
+     * @param cacheInteractor creating statement cache interactor
      * @throws IllegalArgumentException if {@code cache} is {@code null}
      */
     public LogicalCallableStatement(java.sql.CallableStatement physicalCs,
                                     StatementKey stmtKey,
-                                    JDBCStatementCache cache) {
-        super(physicalCs, stmtKey, cache);
+                                    StatementCacheInteractor cacheInteractor) {
+        super(physicalCs, stmtKey, cacheInteractor);
     }
 
     public boolean wasNull() throws SQLException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement40.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalCallableStatement40.java
Sat Feb 23 11:07:52 2008
@@ -29,7 +29,6 @@
 import java.sql.SQLException;
 import java.sql.SQLXML;
 
-import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
 import org.apache.derby.client.am.stmtcache.StatementKey;
 
 import org.apache.derby.shared.common.reference.SQLState;
@@ -48,13 +47,13 @@
      *
      * @param physicalCs underlying physical statement
      * @param stmtKey key for the physical statement
-     * @param cache associated statement cache
+     * @param cacheInteractor creating statement cache interactor
      * @throws IllegalArgumentException if {@code cache} is {@code null}
      */
     public LogicalCallableStatement40(java.sql.CallableStatement physicalCs,
                                       StatementKey stmtKey,
-                                      JDBCStatementCache cache) {
-        super(physicalCs, stmtKey, cache);
+                                      StatementCacheInteractor cacheInteractor){
+        super(physicalCs, stmtKey, cacheInteractor);
     }
 
     public void setRowId(int arg0, RowId arg1)

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
Sat Feb 23 11:07:52 2008
@@ -40,7 +40,6 @@
 import java.sql.Time;
 import java.sql.Timestamp;
 
-import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
 import org.apache.derby.client.am.stmtcache.StatementKey;
 
 /**
@@ -64,13 +63,13 @@
      *
      * @param physicalPs underlying physical statement
      * @param stmtKey key for the physical statement
-     * @param cache associated statement cache
+     * @param cacheInteractor creating statement cache interactor
      * @throws IllegalArgumentException if {@code cache} is {@code null}
      */
     public LogicalPreparedStatement(java.sql.PreparedStatement physicalPs,
                                     StatementKey stmtKey,
-                                    JDBCStatementCache cache) {
-        super(physicalPs, stmtKey, cache);
+                                    StatementCacheInteractor cacheInteractor) {
+        super(physicalPs, stmtKey, cacheInteractor);
     }
 
     public int executeUpdate() throws SQLException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement40.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement40.java
Sat Feb 23 11:07:52 2008
@@ -28,7 +28,6 @@
 import java.sql.SQLException;
 import java.sql.SQLXML;
 
-import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
 import org.apache.derby.client.am.stmtcache.StatementKey;
 
 import org.apache.derby.shared.common.reference.SQLState;
@@ -47,13 +46,13 @@
      *
      * @param physicalPs underlying physical statement
      * @param stmtKey key for the physical statement
-     * @param cache associated statement cache
+     * @param cacheInteractor creating statement cache interactor
      * @throws IllegalArgumentException if {@code cache} is {@code null}
      */
     public LogicalPreparedStatement40(java.sql.PreparedStatement physicalPs,
                                       StatementKey stmtKey,
-                                      JDBCStatementCache cache) {
-        super(physicalPs, stmtKey, cache);
+                                      StatementCacheInteractor cacheInteractor){
+        super(physicalPs, stmtKey, cacheInteractor);
     }
 
     public void setRowId(int arg0, RowId arg1)

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
Sat Feb 23 11:07:52 2008
@@ -81,20 +81,20 @@
      *
      * @param physicalPs a physical {@link java.sql.PreparedStatement}
      * @param stmtKey cache key for the physical statement
-     * @param cache statement cache
+     * @param cacheInteractor creating statement cache interactor
      * @throws IllegalArgumentException if {@code cache} is {@code null}
      */
     protected LogicalStatementEntity(java.sql.PreparedStatement physicalPs,
                                      StatementKey stmtKey,
-                                     JDBCStatementCache cache) {
-        if (cache == null) {
+                                     StatementCacheInteractor cacheInteractor) {
+        if (cacheInteractor.getCache() == null) {
             // Internal check, failure indicates programming error.
             // No need to localize error message.
             throw new IllegalArgumentException(
                     "statement cache reference cannot be <null>");
         }
         this.stmtKey = stmtKey;
-        this.cache = cache;
+        this.cache = cacheInteractor.getCache();
         this.physicalPs = physicalPs;
         if (physicalPs instanceof CallableStatement) {
             this.hasCallableStmt = true;

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
Sat Feb 23 11:07:52 2008
@@ -23,7 +23,7 @@
  *      <li>Return referecne to existing or newly created statement.</li>
  * </ol>
  */
-final class StatementCacheInteractor {
+public final class StatementCacheInteractor {
 
     /** TODO: Fetch from connection, see DERBY-3192. */
     private final String currentSchema = "APP";
@@ -62,7 +62,7 @@
             ps = physicalConnection.prepareStatement(sql);
         }
         return ClientDriver.getFactory().newLogicalPreparedStatement(
-                    ps, stmtKey, cache);
+                    ps, stmtKey, this);
     }
 
     /**
@@ -82,7 +82,7 @@
                     sql, resultSetType, resultSetConcurrency);
         }
         return ClientDriver.getFactory().newLogicalPreparedStatement(
-                ps, stmtKey, cache);
+                ps, stmtKey, this);
     }
 
     /**
@@ -104,7 +104,7 @@
                 sql, resultSetType,resultSetConcurrency, resultSetHoldability);
         }
         return ClientDriver.getFactory().newLogicalPreparedStatement(
-                    ps, stmtKey, cache);
+                    ps, stmtKey, this);
     }
 
     /**
@@ -122,7 +122,7 @@
             ps = physicalConnection.prepareStatement(sql, autoGeneratedKeys);
         }
         return ClientDriver.getFactory().newLogicalPreparedStatement(
-                    ps, stmtKey, cache);
+                    ps, stmtKey, this);
     }
 
     /**
@@ -137,7 +137,7 @@
             cs = physicalConnection.prepareCall(sql);
         }
         return ClientDriver.getFactory().newLogicalCallableStatement(
-                    cs, stmtKey, cache);
+                    cs, stmtKey, this);
     }
 
     /**
@@ -155,7 +155,7 @@
             cs = physicalConnection.prepareCall(sql, resultSetType, resultSetConcurrency);
         }
         return ClientDriver.getFactory().newLogicalCallableStatement(
-                    cs, stmtKey, cache);
+                    cs, stmtKey, this);
     }
 
     /**
@@ -175,6 +175,15 @@
                     resultSetHoldability);
         }
         return ClientDriver.getFactory().newLogicalCallableStatement(
-                    cs, stmtKey, cache);
+                    cs, stmtKey, this);
+    }
+
+    /**
+     * Returns the associated statement cache.
+     *
+     * @return A statement cache.
+     */
+    JDBCStatementCache getCache() {
+        return this.cache;
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
Sat Feb 23 11:07:52 2008
@@ -47,6 +47,7 @@
 import org.apache.derby.jdbc.ClientBaseDataSource;
 import org.apache.derby.jdbc.ClientXADataSource;
 import org.apache.derby.client.am.ColumnMetaData;
+import org.apache.derby.client.am.StatementCacheInteractor;
 
 /**
  * Implements the the ClientJDBCObjectFactory interface and returns the classes
@@ -212,14 +213,14 @@
      *
      * @param ps underlying physical prepared statement
      * @param stmtKey key for the underlying physical prepared statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical prepared statement.
      */
-    public java.sql.PreparedStatement newLogicalPreparedStatement(
+    public LogicalPreparedStatement newLogicalPreparedStatement(
             java.sql.PreparedStatement ps,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache) {
-        return new LogicalPreparedStatement(ps, stmtKey, stmtCache);
+            StatementCacheInteractor cacheInteractor) {
+        return new LogicalPreparedStatement(ps, stmtKey, cacheInteractor);
     }
 
     /**
@@ -227,14 +228,14 @@
      *
      * @param cs underlying physical callable statement
      * @param stmtKey key for the underlying physical callable statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical callable statement.
      */
-    public java.sql.CallableStatement newLogicalCallableStatement(
+    public LogicalCallableStatement newLogicalCallableStatement(
             java.sql.CallableStatement cs,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache) {
-        return new LogicalCallableStatement(cs, stmtKey, stmtCache);
+            StatementCacheInteractor cacheInteractor) {
+        return new LogicalCallableStatement(cs, stmtKey, cacheInteractor);
     }
 
     /**

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
Sat Feb 23 11:07:52 2008
@@ -37,7 +37,9 @@
 import org.apache.derby.client.am.PreparedStatement40;
 import org.apache.derby.client.am.ParameterMetaData;
 import org.apache.derby.client.am.ParameterMetaData40;
+import org.apache.derby.client.am.LogicalCallableStatement;
 import org.apache.derby.client.am.LogicalCallableStatement40;
+import org.apache.derby.client.am.LogicalPreparedStatement;
 import org.apache.derby.client.am.LogicalPreparedStatement40;
 import org.apache.derby.client.am.LogWriter;
 import org.apache.derby.client.am.Agent;
@@ -45,6 +47,7 @@
 import org.apache.derby.client.am.Section;
 import org.apache.derby.client.am.Statement;
 import org.apache.derby.client.am.Statement40;
+import org.apache.derby.client.am.StatementCacheInteractor;
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.am.Cursor;
 import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
@@ -210,14 +213,14 @@
      *
      * @param ps underlying physical prepared statement
      * @param stmtKey key for the underlying physical prepared statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical prepared statement.
      */
-    public java.sql.PreparedStatement newLogicalPreparedStatement(
+    public LogicalPreparedStatement newLogicalPreparedStatement(
             java.sql.PreparedStatement ps,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache) {
-        return new LogicalPreparedStatement40(ps, stmtKey, stmtCache);
+            StatementCacheInteractor cacheInteractor) {
+        return new LogicalPreparedStatement40(ps, stmtKey, cacheInteractor);
     }
 
     /**
@@ -225,14 +228,14 @@
      *
      * @param cs underlying physical callable statement
      * @param stmtKey key for the underlying physical callable statement
-     * @param stmtCache the statement cache
+     * @param cacheInteractor the statement cache interactor
      * @return A logical callable statement.
      */
-    public java.sql.CallableStatement newLogicalCallableStatement(
+    public LogicalCallableStatement newLogicalCallableStatement(
             java.sql.CallableStatement cs,
             StatementKey stmtKey,
-            JDBCStatementCache stmtCache) {
-        return new LogicalCallableStatement40(cs, stmtKey, stmtCache);
+            StatementCacheInteractor cacheInteractor) {
+        return new LogicalCallableStatement40(cs, stmtKey, cacheInteractor);
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derby/client/am/LogicalStatementEntityTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derby/client/am/LogicalStatementEntityTest.java?rev=630507&r1=630506&r2=630507&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derby/client/am/LogicalStatementEntityTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derby/client/am/LogicalStatementEntityTest.java
Sat Feb 23 11:07:52 2008
@@ -28,13 +28,12 @@
 import org.apache.derby.client.am.stmtcache.StatementKey;
 import org.apache.derby.client.am.stmtcache.StatementKeyFactory;
 
-import org.apache.derby.jdbc.ClientDriver;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
- * Tests for the handling of logical prepared statements.
+ * Tests for the handling of logical statements.
  */
 public class LogicalStatementEntityTest
     extends BaseJDBCTestCase {
@@ -52,13 +51,11 @@
     public void testCloseBehaviorExternalPs()
             throws SQLException {
         final String sql = "values 7";
-        final String schema = "APP";
         java.sql.PreparedStatement ps = prepareStatement(sql);
-        StatementKey stmtKey = StatementKeyFactory.newPrepared(
-                sql, schema, getConnection().getHoldability());
         JDBCStatementCache cache = new JDBCStatementCache(10);
+        insertStatementIntoCache(cache, ps, sql);
         LogicalStatementEntity logic =
-                new LogicalStatementEntityClass(ps, stmtKey, cache);
+                createLogicalStatementEntity(sql, false, cache);
         assertSame(ps, logic.getPhysPs());
         assertFalse(logic.isLogicalEntityClosed());
         logic.close();
@@ -83,13 +80,11 @@
     public void testCloseBehaviorExternalCs()
             throws SQLException {
         final String sql = "values 3";
-        final String schema = "APP";
         java.sql.CallableStatement cs = prepareCall(sql);
-        StatementKey stmtKey = StatementKeyFactory.newCallable(
-                sql, schema, getConnection().getHoldability());
         JDBCStatementCache cache = new JDBCStatementCache(10);
+        insertStatementIntoCache(cache, cs, sql);
         LogicalStatementEntity logic =
-                new LogicalStatementEntityClass(cs, stmtKey, cache);
+                createLogicalStatementEntity(sql, true, cache);
         assertSame(cs, logic.getPhysCs());
         assertFalse(logic.isLogicalEntityClosed());
         logic.close();
@@ -115,28 +110,30 @@
             throws SQLException {
         // Initial setup.
         final String sql = "values 7";
-        final String schema = "APP";
         java.sql.PreparedStatement ps = prepareStatement(sql);
-        StatementKey stmtKey = StatementKeyFactory.newPrepared(
-                sql, schema, getConnection().getHoldability());
         JDBCStatementCache cache = new JDBCStatementCache(10);
+        StatementKey stmtKey = insertStatementIntoCache(cache, ps, sql);
         LogicalStatementEntity logic =
-                new LogicalStatementEntityClass(ps, stmtKey, cache);
+                createLogicalStatementEntity(sql, false, cache);
         assertSame(ps, logic.getPhysPs());
         assertFalse(logic.isLogicalEntityClosed());
 
         // Put a statement into the cache.
-        assertTrue(cache.cacheStatement(stmtKey, ps));
+        //assertTrue(cache.cacheStatement(stmtKey, ps));
         // Create a second statement, equal to the first.
         java.sql.PreparedStatement psDupe = prepareStatement(sql);
+        insertStatementIntoCache(cache, psDupe, sql);
         LogicalStatementEntity logicDupe =
-                new LogicalStatementEntityClass(psDupe, stmtKey, cache);
+                createLogicalStatementEntity(sql, false, cache);
+        // Close the first logical entry, to put the physical statement back
+        // into the cache.
+        logic.close();
         // When we ask the logical entity to close the statement now, the
         // underlying physical prepared statement should actually be closed.
         logicDupe.close();
         assertTrue(logicDupe.isLogicalEntityClosed());
-        // Since we are possibly running in pre-JDBC 4, try do do something to
-        // provoke exception.
+        // Since we are possibly running in a pre-JDBC 4 environment, try do do
+        // something to provoke an exception.
         try {
             psDupe.execute();
             fail("Statement should have been closed and throw an exception");
@@ -161,13 +158,11 @@
             throws SQLException {
         // Initial setup.
         final String sql = "values 9";
-        final String schema = "APP";
         java.sql.PreparedStatement ps = prepareStatement(sql);
-        StatementKey stmtKey = StatementKeyFactory.newPrepared(
-                sql, schema, getConnection().getHoldability());
         JDBCStatementCache cache = new JDBCStatementCache(10);
+        StatementKey stmtKey = insertStatementIntoCache(cache, ps, sql);
         LogicalStatementEntity logic =
-                new LogicalStatementEntityClass(ps, stmtKey, cache);
+                createLogicalStatementEntity(sql, false, cache);
         assertSame(ps, logic.getPhysPs());
         assertFalse(logic.isLogicalEntityClosed());
 
@@ -192,17 +187,15 @@
             throws SQLException {
         // Initial setup.
         final String sql = "values 19";
-        final String schema = "APP";
         java.sql.PreparedStatement ps = prepareStatement(sql);
-        StatementKey stmtKey = StatementKeyFactory.newPrepared(
-                sql, schema, getConnection().getHoldability());
         JDBCStatementCache cache = new JDBCStatementCache(10);
+        insertStatementIntoCache(cache, ps, sql);
         LogicalStatementEntity logic =
-                new LogicalStatementEntityClass(ps, stmtKey, cache);
+                createLogicalStatementEntity(sql, false, cache);
         assertSame(ps, logic.getPhysPs());
         assertFalse(logic.isLogicalEntityClosed());
-        java.sql.PreparedStatement logicalPs = ClientDriver.getFactory().
-                newLogicalPreparedStatement(ps, stmtKey, cache);
+        java.sql.PreparedStatement logicalPs =
+                (java.sql.PreparedStatement)logic;
         assertNotNull(logicalPs.getMetaData());
         ps.close();
         try {
@@ -227,24 +220,29 @@
             throws SQLException {
         // Initial setup.
         JDBCStatementCache cache = new JDBCStatementCache(2);
-        final String schema = "APP";
-        java.sql.PreparedStatement ps1 = prepareStatement("values 1");
-        java.sql.PreparedStatement ps2 = prepareStatement("values 2");
-        java.sql.PreparedStatement ps3 = prepareStatement("values 3");
-        StatementKey stmtKey1 = StatementKeyFactory.newPrepared(
-                "values 1", schema, getConnection().getHoldability());
-        StatementKey stmtKey2 = StatementKeyFactory.newPrepared(
-                "values 2", schema, getConnection().getHoldability());
-        StatementKey stmtKey3 = StatementKeyFactory.newPrepared(
-                "values 3", schema, getConnection().getHoldability());
+        final String sql1 = "values 1";
+        final String sql2 = "values 2";
+        final String sql3 = "values 3";
+        // Create three physical prepares statements.
+        java.sql.PreparedStatement ps1 = prepareStatement(sql1);
+        java.sql.PreparedStatement ps2 = prepareStatement(sql2);
+        java.sql.PreparedStatement ps3 = prepareStatement(sql3);
+        // Insert the two first physical statements, the get logical wrappers.
+        StatementKey stmtKey1 = insertStatementIntoCache(cache, ps1, sql1);
+        StatementKey stmtKey2 = insertStatementIntoCache(cache, ps2, sql2);
         LogicalStatementEntity logic1 =
-                new LogicalStatementEntityClass(ps1, stmtKey1, cache);
+                createLogicalStatementEntity(sql1, false, cache);
         LogicalStatementEntity logic2 =
-                new LogicalStatementEntityClass(ps2, stmtKey2, cache);
+                createLogicalStatementEntity(sql2, false, cache);
+        // Insert the last physical statement and get the logical wrapper.
+        StatementKey stmtKey3 = insertStatementIntoCache(cache, ps3, sql3);
         LogicalStatementEntity logic3 =
-                new LogicalStatementEntityClass(ps3, stmtKey3, cache);
+                createLogicalStatementEntity(sql3, false, cache);
+        assertSame(ps1, logic1.getPhysPs());
+        assertSame(ps2, logic2.getPhysPs());
+        assertSame(ps3, logic3.getPhysPs());
 
-        // Close the two first logical statements, putting them into the cache.
+        // Close two first logical statements, putting them back into the cache.
         logic1.close();
         logic2.close();
         // Assert both of the statements are open.
@@ -278,21 +276,58 @@
     }
 
     /**
-     * Class used to represent a logical statement.
+     * Creates a logical statement entity.
+     * <p>
+     * The entity represents a prepared statement.
+     *
+     * @param sql the SQL text
+     * @param isCallable whether the entity is a callable statement or not
+     * @param cache the statement cache to interact with.
+     * @return A logical statement entity.
+     * @throws SQLException if creating the entity fails
      */
-    private static class LogicalStatementEntityClass
-            extends LogicalStatementEntity {
+    private LogicalStatementEntity createLogicalStatementEntity(
+                                        String sql,
+                                        boolean isCallable,
+                                        JDBCStatementCache cache)
+            throws SQLException {
+        StatementCacheInteractor cacheInteractor =
+                new StatementCacheInteractor(
+                    cache,
+                    ((org.apache.derby.client.am.Connection)getConnection()));
+        LogicalStatementEntity entity;
+        if (isCallable) {
+            entity = (LogicalStatementEntity)cacheInteractor.prepareCall(sql);
+        } else {
+            entity =(LogicalStatementEntity)
+                    cacheInteractor.prepareStatement(sql);
+        }
+        return entity;
+    }
 
-        /**
-         * Constructor creating an object handling closing of a logical
-         * prepared / callable statement.
-         *
-         * @param ps underlying physical prepared / callable statement
-         */
-        public LogicalStatementEntityClass(java.sql.PreparedStatement ps,
-                                           StatementKey key,
-                                           JDBCStatementCache cache) {
-            super(ps, key, cache);
+    /**
+     * Insers the statement into the cache.
+     *
+     * @param cache the to insert into
+     * @param ps the statement to insert
+     * @param sql the SQL text of the statement
+     * @return The key the statement was inserted with.
+     *
+     * @throws SQLException if getting the connection holdability fails
+     */
+    private StatementKey insertStatementIntoCache(
+                            JDBCStatementCache cache,
+                            java.sql.PreparedStatement ps,
+                            String sql) throws SQLException {
+        StatementKey key;
+        if (ps instanceof java.sql.CallableStatement) {
+            key = StatementKeyFactory.newCallable(sql, "APP",
+                    getConnection().getHoldability());
+        } else {
+            key = StatementKeyFactory.newPrepared(sql, "APP",
+                    getConnection().getHoldability());
         }
+        assertTrue(cache.cacheStatement(key, ps));
+        return key;
     }
 }



Mime
View raw message