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/14 10:11:03 UTC

svn commit: r406280 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/functionTests/suites/ testin...

Author: kahatlen
Date: Sun May 14 01:11:01 2006
New Revision: 406280

URL: http://svn.apache.org/viewcvs?rev=406280&view=rev
Log:
DERBY-1234: Verify that we raise SQLException when calling methods on
closed java.sql objects

Final patch for DERBY-1234. The patch makes the methods in the client
driver check whether the object is closed. With this patch,
jdbcapi/StmtCloseFunTest.java has the same behaviour with the client
driver as with the embedded driver so the DerbyNetClient canon could
be removed. Also, jdbc4/ClosedObjectTest.junit runs cleanly both on
embedded and on the client, and it has been added to the jdbc40 suite.

In addition to adding checkForClosedXXX() calls, this patch

  a) implements Connection.getTypeMap() with the correct generic
     signature in NetConnection40 and LogicalConnection40 to avoid
     compiler warnings

  b) implements isWrapperFor() (with check for closed object) in
     Statement, so that it could be removed from Statement40,
     PreparedStatement40 and CallableStatement40

Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/StmtCloseFunTest.out
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java Sun May 14 01:11:01 2006
@@ -653,11 +653,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getDate", parameterIndex, cal);
             }
+            java.sql.Date result = getDate(parameterIndex);
             if (cal == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL)).getSQLException();
             }
-            java.sql.Date result = getDate(parameterIndex);
             if (result != null) {
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(cal.getTimeZone());
                 targetCalendar.clear();
@@ -711,11 +711,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getTime", parameterIndex, cal);
             }
+            java.sql.Time result = getTime(parameterIndex);
             if (cal == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL)).getSQLException();
             }
-            java.sql.Time result = getTime(parameterIndex);
             if (result != null) {
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(cal.getTimeZone());
                 targetCalendar.clear();
@@ -768,11 +768,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getTimestamp", parameterIndex, cal);
             }
+            java.sql.Timestamp result = getTimestamp(parameterIndex);
             if (cal == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL)).getSQLException();
             }
-            java.sql.Timestamp result = getTimestamp(parameterIndex);
             if (result != null) {
                 int nano = result.getNanos();
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(cal.getTimeZone());
@@ -1150,6 +1150,7 @@
         if (agent_.loggingEnabled()) {
             agent_.logWriter_.traceEntry(this, "setDate", parameterName, x);
         }
+        throw jdbcMethodNotImplemented();
     }
 
     public void setTime(String parameterName, java.sql.Time x) throws SQLException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement40.java Sun May 14 01:11:01 2006
@@ -193,21 +193,6 @@
     }
     
     /**
-     * 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.
-     */
-    public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
-        return interfaces.isInstance(this);
-    }
-    
-    /**
      * Returns <code>this</code> if this class implements the interface
      *
      * @param  interfaces a Class defining an interface
@@ -218,10 +203,13 @@
     public <T> T unwrap(java.lang.Class<T> interfaces)
                                    throws SQLException {
         try { 
+            checkForClosedStatement();
             return interfaces.cast(this);
         } catch (ClassCastException cce) {
             throw new SqlException(null, new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
                     interfaces).getSQLException();
+        } catch (SqlException se) {
+            throw se.getSQLException();
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Sun May 14 01:11:01 2006
@@ -535,6 +535,7 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "commit");
             }
+            checkForClosedConnection();
 
             // the following XA State check must be in commit instead of commitX since
             // external application call commit, the SqlException should be thrown
@@ -542,7 +543,6 @@
             // internal code will call commitX which will ignore the commit request
             // while in a Global transaction
             checkForInvalidXAStateOnCommitOrRollback();
-            checkForClosedConnection();
             flowCommit();
         }
         catch ( SqlException se )
@@ -642,9 +642,9 @@
                 agent_.logWriter_.traceEntry(this, "rollback");
             }
             
+            checkForClosedConnection();
             checkForInvalidXAStateOnCommitOrRollback();
 
-            checkForClosedConnection();
             flowRollback();
         }
         catch ( SqlException se )
@@ -951,10 +951,15 @@
         }
     }
 
-    public java.sql.SQLWarning getWarnings() {
+    public java.sql.SQLWarning getWarnings() throws SQLException {
         if (agent_.loggingEnabled()) {
             agent_.logWriter_.traceExit(this, "getWarnings", warnings_);
         }
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         return warnings_ == null ? null : warnings_.getSQLWarning();
     }
 
@@ -964,6 +969,7 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "clearWarnings");
             }
+            checkForClosedConnection();
             clearWarningsX();
         }
         catch ( SqlException se )

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java Sun May 14 01:11:01 2006
@@ -34,6 +34,7 @@
 
 import org.apache.derby.client.ClientPooledConnection;
 import org.apache.derby.shared.common.reference.SQLState;
+import java.util.Map;
 
 /**
  * A simple delegation wrapper handle for a physical connection.
@@ -96,6 +97,16 @@
         throw SQLExceptionFactory.notImplemented("getClientInfo(String)");
     }
 
+    /**
+     * Returns the type map for this connection.
+     *
+     * @return type map for this connection
+     * @exception SQLException if a database access error occurs
+     */
+    public Map<String, Class<?>> getTypeMap() throws SQLException {
+        checkForNullPhysicalConnection();
+        return ((java.sql.Connection) physicalConnection_).getTypeMap();
+    }
 
     /**
      * Checks if the connection has not been closed and is still valid. 
@@ -132,6 +143,7 @@
             SQLExceptionFactory.notImplemented("setClientInfo(Properties)");
         throw new ClientInfoException(sqle.getMessage(), 
                                       sqle.getSQLState(), 
+                                      properties == null ? null :
                                       (Properties)properties.clone());
     }
     

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Sun May 14 01:11:01 2006
@@ -611,6 +611,7 @@
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "setDate", parameterIndex, x);
                 }
+                checkForClosedStatement();
                 parameterIndex = checkSetterPreconditions(parameterIndex);
                 parameterMetaData_.clientParamtertype_[parameterIndex - 1] = java.sql.Types.DATE;
                 if (x == null) {
@@ -635,6 +636,7 @@
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "setDate", parameterIndex, x, calendar);
                 }
+                checkForClosedStatement();
                 if (calendar == null) {
                     throw new SqlException(agent_.logWriter_, 
                         new ClientMessageId(SQLState.INVALID_API_PARAMETER),
@@ -691,6 +693,7 @@
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "setTime", parameterIndex, x, calendar);
                 }
+                checkForClosedStatement();
                 if (calendar == null) {
                     throw new SqlException(agent_.logWriter_,
                         new ClientMessageId(SQLState.INVALID_API_PARAMETER),
@@ -750,6 +753,7 @@
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "setTimestamp", parameterIndex, x, calendar);
                 }
+                checkForClosedStatement();
                 if (calendar == null) {
                     throw new SqlException(agent_.logWriter_, 
                         new ClientMessageId(SQLState.INVALID_API_PARAMETER),
@@ -2127,6 +2131,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "setClob",
                         parameterIndex, reader, new Long(length));
+            }
+            try {
+                checkForClosedStatement();
+            } catch (SqlException se) {
+                throw se.getSQLException();
             }
             if(length > Integer.MAX_VALUE)
                 throw new SqlException(agent_.logWriter_,

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement40.java Sun May 14 01:11:01 2006
@@ -123,20 +123,6 @@
                 throws SQLException{
         throw SQLExceptionFactory.notImplemented ("setSQLXML (int, SQLXML)");
     }
-    /**
-     * 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.
-     */
-    public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
-        return interfaces.isInstance(this);
-    }
     
     /**
      * Returns <code>this</code> if this class implements the interface
@@ -149,10 +135,13 @@
     public <T> T unwrap(java.lang.Class<T> interfaces)
                                    throws SQLException {
         try { 
+            checkForClosedStatement();
             return interfaces.cast(this);
         } catch (ClassCastException cce) {
             throw new SqlException(null,new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
                     interfaces).getSQLException();
+        } catch (SqlException se) {
+            throw se.getSQLException();
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Sun May 14 01:11:01 2006
@@ -881,11 +881,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getDate", column, calendar);
             }
+            java.sql.Date date = getDate(column);
             if (calendar == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL));
             }
-            java.sql.Date date = getDate(column);
             if (date != null) {
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone());
                 targetCalendar.clear();
@@ -946,11 +946,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getTime", column, calendar);
             }
+            java.sql.Time time = getTime(column);
             if (calendar == null) {
                 throw new SqlException(agent_.logWriter_,
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL));
             }
-            java.sql.Time time = getTime(column);
             if (time != null) {
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone());
                 targetCalendar.clear();
@@ -1011,11 +1011,11 @@
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "getTimestamp", column, calendar);
             }
+            java.sql.Timestamp timestamp = getTimestamp(column);
             if (calendar == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CALENDAR_IS_NULL));
             }
-            java.sql.Timestamp timestamp = getTimestamp(column);
             if (timestamp != null) {
                 int nano = timestamp.getNanos();
                 java.util.Calendar targetCalendar = java.util.Calendar.getInstance(calendar.getTimeZone());

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Sun May 14 01:11:01 2006
@@ -481,6 +481,26 @@
     }
 
     /**
+     * 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 {
+        try {
+            checkForClosedStatement();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
+        return iface.isInstance(this);
+    }
+
+    /**
      * Tell whether the statement has been closed or not.
      *
      * @return <code>true</code> if closed, <code>false</code> otherwise.
@@ -751,6 +771,11 @@
         if (agent_.loggingEnabled()) {
             agent_.logWriter_.traceExit(this, "getWarnings", warnings_);
         }
+        try {
+            checkForClosedStatement();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         return warnings_ == null ? null : warnings_.getSQLWarning();
     }
 
@@ -758,6 +783,11 @@
         synchronized (connection_) {
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "clearWarnings");
+            }
+            try {
+                checkForClosedStatement();
+            } catch (SqlException se) {
+                throw se.getSQLException();
             }
             clearWarningsX();
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement40.java Sun May 14 01:11:01 2006
@@ -60,21 +60,6 @@
     }
     
     /**
-     * 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.
-     */
-    public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
-        return interfaces.isInstance(this);
-    }
-    
-    /**
      * Returns <code>this</code> if this class implements the interface
      *
      * @param  interfaces a Class defining an interface
@@ -85,10 +70,13 @@
     public <T> T unwrap(java.lang.Class<T> interfaces)
                                    throws SQLException {
         try { 
+            checkForClosedStatement();
             return interfaces.cast(this);
         } catch (ClassCastException cce) {
             throw new SqlException(null,new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
                     interfaces).getSQLException();
+        } catch (SqlException se) {
+            throw se.getSQLException();
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Sun May 14 01:11:01 2006
@@ -34,9 +34,10 @@
 import java.sql.SQLException;
 import java.sql.SQLXML;
 import java.sql.Struct;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 import org.apache.derby.impl.jdbc.Util;
-import org.apache.derby.jdbc.InternalDriver;
 import org.apache.derby.client.ClientPooledConnection;
 import org.apache.derby.client.am.ClientMessageId;
 import org.apache.derby.shared.common.reference.SQLState;
@@ -140,6 +141,11 @@
      */
     
     public Clob createClob() throws SQLException {
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         org.apache.derby.client.am.Clob clob = new org.apache.derby.client.am.Clob(this.agent_,"");
         return clob;
     }
@@ -154,6 +160,11 @@
      */
     
     public Blob createBlob() throws SQLException {
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         org.apache.derby.client.am.Blob blob = new org.apache.derby.client.am.Blob(new byte[0],this.agent_, 0);
         return blob;
     }
@@ -277,6 +288,27 @@
     }
     
     /**
+     * Returns the type map for this connection.
+     *
+     * @return type map for this connection
+     * @exception SQLException if a database access error occurs
+     */
+    public final Map<String, Class<?>> getTypeMap() throws SQLException {
+        // This method is already implemented with a non-generic
+        // signature in am/Connection. We could just use that method
+        // directly, but then we get a compiler warning (unchecked
+        // cast/conversion). Copy the map to avoid the compiler
+        // warning.
+        Map typeMap = super.getTypeMap();
+        if (typeMap == null) return null;
+        Map<String, Class<?>> genericTypeMap = new HashMap<String, Class<?>>();
+        for (Object key : typeMap.keySet()) {
+            genericTypeMap.put((String) key, (Class) typeMap.get(key));
+        }
+        return genericTypeMap;
+    }
+
+    /**
      * This method forwards all the calls to default query object provided by 
      * the jdk.
      * @param ifc interface to generated concreate class
@@ -284,6 +316,11 @@
      */
     public <T extends BaseQuery> T createQueryObject(Class<T> ifc) 
                                                     throws SQLException {
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         return QueryObjectFactory.createDefaultQueryObject (ifc, this);
     } 
     
@@ -299,6 +336,11 @@
      *                                with the given interface.
      */
     public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         return interfaces.isInstance(this);
     }
     
@@ -307,17 +349,20 @@
      *
      * @param  interfaces a Class defining an interface
      * @return an object that implements the interface
-     * @throws java.sql.SQLExption if no object if found that implements the 
+     * @throws java.sql.SQLException if no object if found that implements the 
      * interface
      */
     public <T> T unwrap(java.lang.Class<T> interfaces)
                                    throws SQLException {
         try { 
+            checkForClosedConnection();
             return interfaces.cast(this);
         } catch (ClassCastException cce) {
             throw new SqlException(null,
                 new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
                 interfaces).getSQLException();
+        } catch (SqlException se) {
+            throw se.getSQLException();
         }
     }
     

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet40.java Sun May 14 01:11:01 2006
@@ -158,6 +158,11 @@
      *                                with the given interface.
      */
     public boolean isWrapperFor(Class<?> interfaces) throws SQLException {
+        try {
+            checkForClosedResultSet();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
         return interfaces.isInstance(this);
     }
     
@@ -172,11 +177,14 @@
     public <T> T unwrap(java.lang.Class<T> interfaces)
                                    throws SQLException {
         try { 
+            checkForClosedResultSet();
             return interfaces.cast(this);
         } catch (ClassCastException cce) {
             throw new SqlException(null,
                 new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
                 interfaces).getSQLException();
+        } catch (SqlException se) {
+            throw se.getSQLException();
         }
     }
     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall Sun May 14 01:11:01 2006
@@ -11,6 +11,7 @@
 jdbc4/BlobTest.junit
 jdbc4/CallableStatementTest.junit
 jdbc4/ClobTest.junit
+jdbc4/ClosedObjectTest.junit
 jdbc4/DataSourceTest.junit
 jdbc4/ParameterMetaDataWrapperTest.junit
 jdbc4/ResultSetMetaDataTest.junit

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java Sun May 14 01:11:01 2006
@@ -37,7 +37,6 @@
 import java.sql.ResultSet;
 import java.sql.SQLXML;
 import java.sql.Statement;
-import org.apache.derby.shared.common.error.ExceptionUtil;
 import org.apache.derby.shared.common.reference.SQLState;
 import org.apache.derby.tools.ij;
 import org.apache.derby.iapi.error.StandardException;
@@ -51,7 +50,6 @@
     
     static Connection conn = null;
     PreparedStatement ps = null;
-    boolean stmtIsClosed = false;
     
     String filepath;
     String sep;
@@ -452,12 +450,9 @@
         } catch(SQLException sqle) {
             // Check which SQLException state we've got and if it is
             // expected, do not print a stackTrace
-            // FIXME: Note that the test for stmtIsClosed boolean can
-            // be removed _once_ the client driver reports the same
-            // SQLState as the embedded driver does - See JIRA-254.
-            if (ExceptionUtil.getSQLStateFromIdentifier(
-                        SQLState.ALREADY_CLOSED).equals(sqle.getSQLState()) ||
-                stmtIsClosed) {
+            // Embedded uses XJ012, client uses XCL31.
+            if (sqle.getSQLState().equals("XJ012") ||
+                sqle.getSQLState().equals("XCL31")) {
                 // All is good and is expected
             } else {
                 System.out.println("Unexpected SQLException " + sqle);
@@ -476,12 +471,9 @@
         } catch(SQLException sqle) {
             // Check which SQLException state we've got and if it is
             // expected, do not print a stackTrace
-            // FIXME: Note that the test for stmtIsClosed boolean can
-            // be removed _once_ the client driver reports the same
-            // SQLState as the embedded driver does - See JIRA-254.
-            if (ExceptionUtil.getSQLStateFromIdentifier(
-                        SQLState.ALREADY_CLOSED).equals(sqle.getSQLState()) ||
-                stmtIsClosed) {
+            // Embedded uses XJ012, client uses XCL31.
+            if (sqle.getSQLState().equals("XJ012") ||
+                sqle.getSQLState().equals("XCL31")) {
                 // All is good and is expected
             } else {
                 System.out.println("Unexpected SQLException " + sqle);
@@ -549,7 +541,6 @@
      */
     void startClientTestMethods( Connection conn_main ) {
         PreparedStatement ps_main = null;
-        stmtIsClosed = false;
         
         try {
             ps_main = conn_main.prepareStatement("select count(*) from " +
@@ -565,15 +556,12 @@
             t_setSQLXML();
             t_isPoolable();
             t_setPoolable();
+            t_wrapper();
             // Close the prepared statement and verify the poolable hint
             // cannot be set or retrieved
             ps.close();
-            stmtIsClosed = true; // This until JIRA-953 is addressed then
-                                 // stmt.isClosed() can be called in the
-                                 // poolable hint set/get test methods below
             t_isPoolable();
             t_setPoolable();
-            t_wrapper();
         } catch(SQLException sqle) {
             sqle.printStackTrace();
         } finally {
@@ -589,7 +577,6 @@
      */
     void startEmbeddedTestMethods( Connection conn_main ) {
         PreparedStatement ps_main = null;
-        stmtIsClosed = false;
         
         try {            
             Statement s = conn_main.createStatement();
@@ -635,9 +622,6 @@
             // Close the prepared statement and verify the poolable hint
             // cannot be set or retrieved
             ps.close();
-            stmtIsClosed = true; // This until JIRA-953 is addressed then
-                                 // stmt.isClosed() can be called in the
-                                 // poolable hint set/get test methods below
             t_isPoolable();
             t_setPoolable();
         }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java?rev=406280&r1=406279&r2=406280&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java Sun May 14 01:11:01 2006
@@ -57,7 +57,8 @@
     public static void main(String[] args) {
 
 		System.out.println("Statement Close Fun Test starting ");
-		isDerbyNet= TestUtil.isNetFramework();
+		isDerbyNet = TestUtil.isJCCFramework();
+
 
 
 		try {
@@ -166,7 +167,7 @@
 
 			if (! isDerbyNet)
 			{
-				// DerbyNet and DerbyNetClient don't throw exception
+				// DerbyNet doesn't throw exception
 				try {
 					s.getQueryTimeout();
 					System.out.println("Statement Test failed (9)");
@@ -420,7 +421,7 @@
 
 			if (! isDerbyNet)
 			{
-				// DerbyNet and DerbyNetClient don't throw exception
+				// DerbyNet doesn't throw exception
 				try {
 					ps.getQueryTimeout();
 					System.out.println("Prepared Statement Test failed");
@@ -702,7 +703,7 @@
 
 			if (! isDerbyNet)
 			{
-				// DerbyNet and DerbyNetClient don't throw exception
+				// DerbyNet doesn't throw exception
 				try {
 					cs.getQueryTimeout();
 					System.out.println("Callable Statement Test failed");