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/27 14:05:33 UTC
svn commit: r631577 -
/db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
Author: kristwaa
Date: Wed Feb 27 05:05:32 2008
New Revision: 631577
URL: http://svn.apache.org/viewvc?rev=631577&view=rev
Log:
DERBY-3457 (partial): Closing a caching logical connection must close all associated logical statements.
This partial patch adds a list of open logical statements in SCI. The logic for maintaining the list when statements are closed, and for closing remaining open statements when the caching logical connection is closed, will follow in another patch.
Patch file: derby-3457-2a-stmt_registration.diff
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/StatementCacheInteractor.java
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=631577&r1=631576&r2=631577&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 Wed Feb 27 05:05:32 2008
@@ -4,10 +4,13 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.ArrayList;
+
import org.apache.derby.client.am.stmtcache.JDBCStatementCache;
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.derby.shared.common.sanity.SanityManager;
/**
* Utility class encapsulating the logic for interacting with the JDBC statement
@@ -20,7 +23,7 @@
* <ol> <li>Generate a key for the statement to create.</li>
* <li>Consult cache to see if an existing statement can be used.</li>
* <li>Create new statement on physical connection if necessary.</li>
- * <li>Return referecne to existing or newly created statement.</li>
+ * <li>Return reference to existing or newly created statement.</li>
* </ol>
*/
public final class StatementCacheInteractor {
@@ -37,6 +40,9 @@
* invoked if the logical statement has been closed.
*/
private final Connection physicalConnection;
+ /** List of open logical statements created by this cache interactor. */
+ //@GuardedBy("this")
+ private final ArrayList openLogicalStatements = new ArrayList();
/**
* Creates a new JDBC statement cache interactor.
@@ -61,8 +67,7 @@
if (ps == null) {
ps = physicalConnection.prepareStatement(sql);
}
- return ClientDriver.getFactory().newLogicalPreparedStatement(
- ps, stmtKey, this);
+ return createLogicalPreparedStatement(ps, stmtKey);
}
/**
@@ -81,8 +86,7 @@
ps = physicalConnection.prepareStatement(
sql, resultSetType, resultSetConcurrency);
}
- return ClientDriver.getFactory().newLogicalPreparedStatement(
- ps, stmtKey, this);
+ return createLogicalPreparedStatement(ps, stmtKey);
}
/**
@@ -103,8 +107,7 @@
ps = physicalConnection.prepareStatement(
sql, resultSetType,resultSetConcurrency, resultSetHoldability);
}
- return ClientDriver.getFactory().newLogicalPreparedStatement(
- ps, stmtKey, this);
+ return createLogicalPreparedStatement(ps, stmtKey);
}
/**
@@ -121,8 +124,7 @@
if (ps == null) {
ps = physicalConnection.prepareStatement(sql, autoGeneratedKeys);
}
- return ClientDriver.getFactory().newLogicalPreparedStatement(
- ps, stmtKey, this);
+ return createLogicalPreparedStatement(ps, stmtKey);
}
/**
@@ -136,8 +138,7 @@
if (cs == null) {
cs = physicalConnection.prepareCall(sql);
}
- return ClientDriver.getFactory().newLogicalCallableStatement(
- cs, stmtKey, this);
+ return createLogicalCallableStatement(cs, stmtKey);
}
/**
@@ -154,8 +155,7 @@
if (cs == null) {
cs = physicalConnection.prepareCall(sql, resultSetType, resultSetConcurrency);
}
- return ClientDriver.getFactory().newLogicalCallableStatement(
- cs, stmtKey, this);
+ return createLogicalCallableStatement(cs, stmtKey);
}
/**
@@ -174,8 +174,45 @@
cs = physicalConnection.prepareCall(sql, resultSetType, resultSetConcurrency,
resultSetHoldability);
}
- return ClientDriver.getFactory().newLogicalCallableStatement(
- cs, stmtKey, this);
+ return createLogicalCallableStatement(cs, stmtKey);
+ }
+
+ /**
+ * Creates a logical prepared statement.
+ *
+ * @param ps the underlying physical prepared statement
+ * @param stmtKey the statement key for the physical statement
+ * @return A logical prepared statement.
+ * @throws SQLException if creating a logical prepared statement fails
+ */
+ private PreparedStatement createLogicalPreparedStatement(
+ PreparedStatement ps,
+ StatementKey stmtKey)
+ throws SQLException {
+ LogicalPreparedStatement logicalPs =
+ ClientDriver.getFactory().newLogicalPreparedStatement(
+ ps, stmtKey, this);
+ this.openLogicalStatements.add(logicalPs);
+ return logicalPs;
+ }
+
+ /**
+ * Creates a logical callable statement.
+ *
+ * @param cs the underlying physical callable statement
+ * @param stmtKey the statement key for the physical statement
+ * @return A logical callable statement.
+ * @throws SQLException if creating a logical callable statement fails
+ */
+ private CallableStatement createLogicalCallableStatement(
+ CallableStatement cs,
+ StatementKey stmtKey)
+ throws SQLException {
+ LogicalCallableStatement logicalCs =
+ ClientDriver.getFactory().newLogicalCallableStatement(
+ cs, stmtKey, this);
+ this.openLogicalStatements.add(logicalCs);
+ return logicalCs;
}
/**