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 ka...@apache.org on 2006/05/06 13:27:04 UTC
svn commit: r400287 - in
/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc:
BrokeredCallableStatement40.java BrokeredConnection.java
BrokeredConnection40.java BrokeredPreparedStatement40.java
BrokeredStatement.java BrokeredStatement40.java
Author: kahatlen
Date: Sat May 6 04:26:58 2006
New Revision: 400287
URL: http://svn.apache.org/viewcvs?rev=400287&view=rev
Log:
DERBY-1234 (partial) Verify that we raise SQLException when calling
methods on closed java.sql objects
New patch (part5) which makes all the BrokeredXXX classes check
whether the object is closed. What the patch does, is:
1) Implement checkIfClosed() and call it where needed.
2) Implement BrokeredStatement.isClosed() which was needed by
checkIfClosed().
3) Remove isWrapperFor() from BrokeredStatement40,
BrokeredPreparedStatement40 and BrokeredCallableStatement40 and
replace it by one shared method (which does the right thing when
the object is closed) in BrokeredStatement
With this patch, jdbc4/ClosedObjectTest.junit runs cleanly on embedded.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement40.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement40.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement40.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement40.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredCallableStatement40.java Sat May 6 04:26:58 2006
@@ -176,18 +176,14 @@
}
/**
- * Returns false unless <code>interfaces</code> is implemented
- *
- * @param interfaces a Class defining an interface.
- * @return true if this implements the interface or
- * directly or indirectly wraps an object
- * that does.
- * @throws java.sql.SQLException if an error occurs while determining
- * whether this is a wrapper for an object
- * with the given interface.
+ * Checks if the statement is closed.
+ *
+ * @return <code>true</code> if the statement is closed,
+ * <code>false</code> otherwise
+ * @exception SQLException if an error occurs
*/
- public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
- return interfaces.isInstance(this);
+ public final boolean isClosed() throws SQLException {
+ return getCallableStatement().isClosed();
}
/**
@@ -200,6 +196,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkIfClosed();
//Derby does not implement non-standard methods on
//JDBC objects
try {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Sat May 6 04:26:58 2006
@@ -508,6 +508,18 @@
}
/**
+ * Checks if the connection is closed and throws an exception if
+ * it is.
+ *
+ * @exception SQLException if the connection is closed
+ */
+ protected final void checkIfClosed() throws SQLException {
+ if (isClosed()) {
+ throw Util.noCurrentConnection();
+ }
+ }
+
+ /**
* Get the string representation for this connection. Return
* the class name/hash code and various debug information.
*
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java Sat May 6 04:26:58 2006
@@ -118,8 +118,19 @@
return new BrokeredCallableStatement40(statementControl, getJDBCLevel(), sql);
}
+ /**
+ * Returns the type map for this connection.
+ *
+ * @return type map for this connection
+ * @exception SQLException if a database access error occurs
+ */
public java.util.Map<String,Class<?>> getTypeMap() throws SQLException {
- throw Util.notImplemented();
+ try {
+ return getRealConnection().getTypeMap();
+ } catch (SQLException se) {
+ notifyException(se);
+ throw se;
+ }
}
int getJDBCLevel() { return 4;}
@@ -136,6 +147,7 @@
* with the given interface.
*/
public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+ checkIfClosed();
return interfaces.isInstance(this);
}
@@ -149,6 +161,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkIfClosed();
//Derby does not implement non-standard methods on
//JDBC objects
try {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement40.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement40.java Sat May 6 04:26:58 2006
@@ -70,18 +70,14 @@
}
/**
- * Returns false unless <code>interfaces</code> is implemented
- *
- * @param interfaces a Class defining an interface.
- * @return true if this implements the interface or
- * directly or indirectly wraps an object
- * that does.
- * @throws java.sql.SQLException if an error occurs while determining
- * whether this is a wrapper for an object
- * with the given interface.
+ * Checks if the statement is closed.
+ *
+ * @return <code>true</code> if the statement is closed,
+ * <code>false</code> otherwise
+ * @exception SQLException if an error occurs
*/
- public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
- return interfaces.isInstance(this);
+ public final boolean isClosed() throws SQLException {
+ return getPreparedStatement().isClosed();
}
/**
@@ -94,6 +90,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException{
+ checkIfClosed();
//Derby does not implement non-standard methods on
//JDBC objects
try {
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java Sat May 6 04:26:58 2006
@@ -540,12 +540,53 @@
return control;
}
- public boolean isClosed()
- throws SQLException {
- // NOTE 1: Depending on implementation, this method may have to be
- // duplicated in the 3 *Statement40 classes.
- // NOTE 2: This is the only method using the Util class. Remove
- // import when method is implemented.
+ /**
+ * Returns false unless <code>iface</code> is implemented
+ *
+ * @param iface a Class defining an interface.
+ * @return true if this implements the interface or
+ * directly or indirectly wraps an object
+ * that does.
+ * @throws java.sql.SQLException if an error occurs while determining
+ * whether this is a wrapper for an object
+ * with the given interface.
+ */
+ public boolean isWrapperFor(Class iface) throws SQLException {
+ checkIfClosed();
+ return iface.isInstance(this);
+ }
+
+ /**
+ * Checks if the statement is closed. Not implemented for this
+ * class since <code>isClosed()</code> is a new method in JDBC
+ * 4.0. The JDBC 4.0 sub-classes should override this method.
+ *
+ * @return <code>true</code> if the statement is closed,
+ * <code>false</code> otherwise
+ * @exception SQLException not-implemented exception
+ */
+ protected boolean isClosed() throws SQLException {
+ // Not implemented since we cannot forward the call to a JDBC
+ // 4.0 method from this class. This dummy implementation is
+ // provided here so that checkIfClosed() can be implemented
+ // once in this class instead of once in each of the
+ // Brokered*Statement40 classes.
throw Util.notImplemented();
+ }
+
+ /**
+ * Checks if the statement is closed and throws an exception if it
+ * is. This method relies on the <code>isClosed()</code> method
+ * and therefore only works with JDBC 4.0.
+ *
+ * @exception SQLException if the statement is closed
+ */
+ protected final void checkIfClosed()
+ throws SQLException
+ {
+ if (isClosed()) {
+ throw Util.generateCsSQLException(SQLState.ALREADY_CLOSED,
+ "Statement");
+ }
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement40.java?rev=400287&r1=400286&r2=400287&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement40.java Sat May 6 04:26:58 2006
@@ -41,18 +41,14 @@
}
/**
- * Returns false unless <code>interfaces</code> is implemented
- *
- * @param interfaces a Class defining an interface.
- * @return true if this implements the interface or
- * directly or indirectly wraps an object
- * that does.
- * @throws java.sql.SQLException if an error occurs while determining
- * whether this is a wrapper for an object
- * with the given interface.
+ * Checks if the statement is closed.
+ *
+ * @return <code>true</code> if the statement is closed,
+ * <code>false</code> otherwise
+ * @exception SQLException if an error occurs
*/
- public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
- return interfaces.isInstance(this);
+ public final boolean isClosed() throws SQLException {
+ return getStatement().isClosed();
}
/**
@@ -65,6 +61,7 @@
*/
public <T> T unwrap(java.lang.Class<T> interfaces)
throws SQLException {
+ checkIfClosed();
//Derby does not implement non-standard methods on
//JDBC objects
try {