db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r406101 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/LogicalConnection40.java engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
Date Sat, 13 May 2006 13:51:41 GMT
Author: rhillegas
Date: Sat May 13 06:51:40 2006
New Revision: 406101

URL: http://svn.apache.org/viewcvs?rev=406101&view=rev
Log:
DERBY-1090: Commit Olav's brokeredlogical1090.diff patch, which forwards missing Connection
calls for pooled and xa connections.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java

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=406101&r1=406100&r2=406101&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 Sat
May 13 06:51:40 2006
@@ -96,11 +96,30 @@
         throw SQLExceptionFactory.notImplemented("getClientInfo(String)");
     }
 
-    public boolean isValid(int timeout)
-        throws SQLException {
-        throw SQLExceptionFactory.notImplemented("isValid(int)");
+
+    /**
+     * Checks if the connection has not been closed and is still valid. 
+     * The validity is checked by running a simple query against the 
+     * database.
+     *
+     * @param timeout The time in seconds to wait for the database
+     * operation used to validate the connection to complete. If the 
+     * timeout period expires before the operation completes, this 
+     * method returns false. A value of 0 indicates a timeout is not 
+     * applied to the database operation.
+     * @return true if the connection is valid, false otherwise
+     * @throws SQLException if the call on the physical connection throws an
+     * exception.
+     */
+    synchronized public boolean isValid(int timeout) throws SQLException {
+        // Check if we have a underlying physical connection
+        if (physicalConnection_ == null) {
+            return false;
+        }
+        return physicalConnection_.isValid(timeout);
     }
    
+
     public boolean isWrapperFor(Class<?> interfaces)
         throws SQLException {
         checkForNullPhysicalConnection();

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=406101&r1=406100&r2=406101&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 13 06:51:40 2006
@@ -68,8 +68,34 @@
         throw Util.notImplemented();
     }
 
-    public boolean isValid(int timeout) throws SQLException{
-        throw Util.notImplemented();
+
+    /**
+     * Checks if the connection has not been closed and is still valid. 
+     * The validity is checked by running a simple query against the 
+     * database.
+     *
+     * @param timeout The time in seconds to wait for the database
+     * operation used to validate the connection to complete. If the 
+     * timeout period expires before the operation completes, this 
+     * method returns false. A value of 0 indicates a timeout is not 
+     * applied to the database operation.
+     * @return true if the connection is valid, false otherwise
+     * @throws SQLException if the call on the physical connection throws an
+     * exception.
+     */
+    public final boolean isValid(int timeout) throws SQLException{
+        // Check first if the Brokered connection is closed
+        if (isClosed()) {
+            return false;
+        }
+
+        // Forward the isValid call to the physical connection
+        try {
+            return getRealConnection().isValid(timeout);
+        } catch (SQLException sqle) {
+            notifyException(sqle);
+            throw sqle;
+        }
     }
     
     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java?rev=406101&r1=406100&r2=406101&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
Sat May 13 06:51:40 2006
@@ -172,6 +172,29 @@
     }
 
     /**
+     * Tests that <code>isValid</code> is implemented and returns true
+     * for the connection. This test is very limited but is tested
+     * for all connection types. A more complete test of isValid is
+     * found in the TestConnectionMethods.java test that is run for
+     * for embedded and network client connections.
+     */
+    public void testIsValidImplemented() throws SQLException {
+        // Test with an infinite (0) timeout
+        assertTrue(con.isValid(0));
+
+        // Test with a 1 second timeout
+        assertTrue(con.isValid(1));
+
+        // Test with an illegal timeout
+        try {
+            con.isValid(-1);
+        } catch (SQLException sqle) {
+            assertSQLState("Incorrect SQL state when calling isValid(-1)",
+                           "XJ081", sqle);
+        }
+    }
+
+    /**
      * Tests that <code>getTypeMap()</code> returns an empty map when
      * no type map has been installed.
      * @exception SQLException if an error occurs



Mime
View raw message