db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r595803 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ ...
Date Fri, 16 Nov 2007 20:08:29 GMT
Author: mamta
Date: Fri Nov 16 12:08:28 2007
New Revision: 595803

URL: http://svn.apache.org/viewvc?rev=595803&view=rev
Log:
This is a followup checkin to checkin(595050) was committed for DERBY-3172. The DataSourceTest
had started failing
under JDK1.6 after 595050. The particular test case that was failing was for Connection.getTypeMap
The reason for
failure was that this method was overridden in a subclass which kicks in only when JDBC4.0
is available. The
overriden method was not sending the correct connection error event as expected by the test
and hence the failure.
While fixing this, I realized that there are several new JDBC4.0 apis that need to send the
correct events to
ConnectionEventListeners. This checkin takes care of those apis. More info on what was changed
in this commit is
as follows.

New JDBC4.0 api, setClientInfo, wraps SQLException inside SQLClientInfoException but we were
not copying the 
error code of SQLException into SQLClientInfoException. Without the correct error code, we
would not send 
connection error event because the severity has to be fatal for us to send connection error
event. Because of this, 
I had to change several places where SQLException is wrapped inside SQLClientInfoException
to pass SQLException's
error code to SQLClientInfoException. The classes changed because of this are EmbedConnection40,

BrokeredConnection40, NetConnection40.

For methods that throw SQLClientInfoException, we were not notifying the connection error
events. I made changes to 
fix this.

Several of new JDBC4 apis on connection object were not sending error events so I changed
those methods in 
BrokeredConnection40 and LogicalConnection40. 

BrokeredConnection40 implements new JDBC4 methods on Connection object but these new methods
did not follow the
same logic as the other existing pre-JDBC4 methods to check for connection close and that
caused the events to
be not sent correctly. The problematic apis were createBlob, createClob, isWrapperFor, unwrap
and I fixed those.

Not all the new JDBC4 apis have been implemented (they throw not implemented exception) so
the tests written for 
those apis just catch the unimplemented exception. These methods include createArrayOf, createNClob,
createSQLXML, 
createStruct.

In JDBC4, Connection object has two methods isWrapperFor and unwrap which do not go to the
server when Derby is
being accessed in client server mode and because of this, we never detect that the server
is down and hence no
connection error event is thrown in client server mode for these 2 apis. But when the same
apis are called in 
embedded Derby after the engine is shutdown, we get connection error event. I have added the
test for these 2 apis 
to count for the different in behavior but I am not sure if this is the expected behavior
difference between the 
2 configurations of Derby. I will enter a Jira entry for this.

And lastly, the new JDBC4 api isValid on Connection object has different behavior in client
server mode and
embedded mode. They both throw exception that the connection is down but the connection close
and error events
are not dealt the same way in the 2 configurations. In embedded mode, after the engine is
shutdown, an isValid 
call on Connection object raises a connection closed event and no connection error event.
In client server mode, 
after the Network Server is shutdown, an isValid call on Connection object does not raise
any event. In both the 
configurations, we do get a SQLException stating that connection is down. Again, I am not
sure if this is expected 
bahavior difference between the 2 configurations of Derby. I will enter a Jira entry for this
too. In addition, as 
per Connection.isValid api Java specification, a SQLException is thrown under following condition
which is not
being followed in embedded and client-server mode
Throws: 
SQLException - if the value supplied for timeout is less then 0
Based on this, I am not sure if our behavior is correct to throw an SQLException if the server/engine
is down. I 
will include this information in the Jira entry that I will make.

The tests for all these new JDBC4 apis are in jdbc4/DataSourceTest.  

I moved the AssertEventCatcher class implementation from jdbcapi/DataSourceTest into a class
of it's own. This way,
it can be shared by jdbcapi/DataSourceTest and jdbc4/DataSourceTest.



Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection40.java?rev=595803&r1=595802&r2=595803&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 Fri
Nov 16 12:08:28 2007
@@ -54,38 +54,74 @@
 
     public Array createArrayOf(String typeName, Object[] elements)
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createArrayOf( typeName, elements );
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createArrayOf( typeName, elements );
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
     
     public Blob createBlob()
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createBlob();
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createBlob();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     public Clob createClob()
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createClob();
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createClob();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
     
     public NClob createNClob()
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createNClob();
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createNClob();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     public SQLXML createSQLXML()
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createSQLXML();
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createSQLXML();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     public Struct createStruct(String typeName, Object[] attributes)
         throws SQLException {
-		checkForNullPhysicalConnection();
-        return physicalConnection_.createStruct( typeName, attributes );
+        try
+        {
+    		checkForNullPhysicalConnection();
+            return physicalConnection_.createStruct( typeName, attributes );
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     /**
@@ -100,8 +136,14 @@
      */
     public Properties getClientInfo()
         throws SQLException {
-	checkForNullPhysicalConnection();
-	return physicalConnection_.getClientInfo();
+        try
+        {
+        	checkForNullPhysicalConnection();
+        	return physicalConnection_.getClientInfo();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
     
     /**
@@ -116,8 +158,14 @@
      */
     public String getClientInfo(String name)
         throws SQLException {
-	checkForNullPhysicalConnection();
-	return physicalConnection_.getClientInfo(name);
+        try
+        {
+        	checkForNullPhysicalConnection();
+        	return physicalConnection_.getClientInfo(name);
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     /**
@@ -127,8 +175,14 @@
      * @exception SQLException if a database access error occurs
      */
     public Map<String, Class<?>> getTypeMap() throws SQLException {
-        checkForNullPhysicalConnection();
-        return ((java.sql.Connection) physicalConnection_).getTypeMap();
+        try
+        {
+            checkForNullPhysicalConnection();
+            return ((java.sql.Connection) physicalConnection_).getTypeMap();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     /**
@@ -146,18 +200,30 @@
      * 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);
+        try
+        {
+            // Check if we have a underlying physical connection
+            if (physicalConnection_ == null) {
+                return false;
+            }
+            return physicalConnection_.isValid(timeout);
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
    
 
     public boolean isWrapperFor(Class<?> interfaces)
         throws SQLException {
-        checkForNullPhysicalConnection();
-        return interfaces.isInstance(this);
+        try
+        {
+            checkForNullPhysicalConnection();
+            return interfaces.isInstance(this);
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
     }
 
     /**
@@ -170,13 +236,20 @@
      */
     public void setClientInfo(Properties properties)
         throws SQLClientInfoException {
-	try { checkForNullPhysicalConnection(); }
-	catch (SQLException se) { 
-	    throw new SQLClientInfoException
-		(se.getMessage(), se.getSQLState(), 
-		 (new FailedProperties40(properties)).getProperties());
-	}
-	physicalConnection_.setClientInfo(properties);
+        try
+        {
+    		checkForNullPhysicalConnection(); 
+        	physicalConnection_.setClientInfo(properties);
+        } catch (SQLClientInfoException cie) {
+            notifyException(cie);
+            throw cie;
+    	} catch (SQLException sqle) {
+    		notifyException(sqle);
+    	    throw new SQLClientInfoException
+    		(sqle.getMessage(), sqle.getSQLState(), 
+    				sqle.getErrorCode(),
+    				(new FailedProperties40(properties)).getProperties());
+    	}
     }
     
     /**
@@ -189,28 +262,41 @@
      */
     public void setClientInfo(String name, String value)
         throws SQLClientInfoException {
-	try { checkForNullPhysicalConnection(); }
-        catch (SQLException se) {
+        try
+        {
+    		checkForNullPhysicalConnection(); 
+        	physicalConnection_.setClientInfo(name, value);
+        } catch (SQLClientInfoException cie) {
+            notifyException(cie);
+            throw cie;
+    	} catch (SQLException sqle) {
+    		notifyException(sqle);
             throw new SQLClientInfoException
-                (se.getMessage(), se.getSQLState(),
-                 new FailedProperties40
-                 (FailedProperties40.makeProperties
-                  (name,value)).getProperties());
-        }
-	physicalConnection_.setClientInfo(name, value);
+            (sqle.getMessage(), sqle.getSQLState(),
+            		sqle.getErrorCode(),
+             new FailedProperties40
+             (FailedProperties40.makeProperties
+              (name,value)).getProperties());
+    	}
     }
     
     public <T>T unwrap(Class<T> interfaces)
         throws SQLException {
-        checkForNullPhysicalConnection();
-        // Derby does not implement non-standard methods on JDBC objects
-        try {
-            return interfaces.cast(this);
-        } catch (ClassCastException cce) {
-            throw new SqlException(null,
-                                   new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
-                                   interfaces).getSQLException();
-        }
+        try
+        {
+            checkForNullPhysicalConnection();
+            // Derby does not implement non-standard methods on JDBC objects
+            try {
+                return interfaces.cast(this);
+            } catch (ClassCastException cce) {
+                throw new SqlException(null,
+                                       new ClientMessageId(SQLState.UNABLE_TO_UNWRAP),
+                                       interfaces).getSQLException();
+            }
+    	} catch (SQLException sqle) {
+    		notifyException(sqle);
+    		throw sqle;
+    	}
     }
     
 } // End class LogicalConnection40

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=595803&r1=595802&r2=595803&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 Fri Nov
16 12:08:28 2007
@@ -244,8 +244,9 @@
 	try { checkForClosedConnection(); }
 	catch (SqlException se) {
             throw new SQLClientInfoException
-                (se.getMessage(), se.getSQLState(), 
-                 new FailedProperties40(p).getProperties());
+                (se.getMessage(), se.getSQLState(),
+                		se.getErrorCode(),
+                		new FailedProperties40(p).getProperties());
         }
 
         if (name == null && value == null) {
@@ -274,7 +275,8 @@
 	try { checkForClosedConnection(); } 
 	catch (SqlException se) {
 	    throw new SQLClientInfoException(se.getMessage(), se.getSQLState(),
-					  fp.getProperties());
+	    		se.getErrorCode(),
+	    		fp.getProperties());
 	}
 	
 	if (properties == null || properties.isEmpty()) {
@@ -287,7 +289,9 @@
 			     (SQLState.PROPERTY_UNSUPPORTED_CHANGE), 
 			     fp.getFirstKey(), fp.getFirstValue());
         throw new SQLClientInfoException(se.getMessage(),
-                                         se.getSQLState(), fp.getProperties());
+        		se.getSQLState(), 
+	    		se.getErrorCode(),
+	    		fp.getProperties());
     }
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java?rev=595803&r1=595802&r2=595803&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 Fri
Nov 16 12:08:28 2007
@@ -67,9 +67,6 @@
      *
      */
     public Blob createBlob() throws SQLException {
-        if (isClosed()) {
-            throw Util.noCurrentConnection();
-        }
         // Forward the createBlob call to the physical connection
         try {
             return getRealConnection().createBlob();
@@ -93,9 +90,6 @@
      *
      */
     public Clob createClob() throws SQLException{
-        if (isClosed()) {
-            throw Util.noCurrentConnection();
-        }
         // Forward the createClob call to the physical connection
         try {
             return getRealConnection().createClob();
@@ -182,8 +176,10 @@
             throw se;
         }
         catch (SQLException se) {
+            notifyException(se);
             throw new SQLClientInfoException
                 (se.getMessage(), se.getSQLState(), 
+                		se.getErrorCode(),
   		 (new FailedProperties40
 		  (FailedProperties40.makeProperties(name,value))).
 		 getProperties());
@@ -210,8 +206,10 @@
             throw cie;
         }
         catch (SQLException se) {
+            notifyException(se);
             throw new SQLClientInfoException
-                (se.getMessage(), se.getSQLState(), 
+                (se.getMessage(), se.getSQLState(),
+                		se.getErrorCode(),
   		 (new FailedProperties40(properties)).getProperties());
         }
     }
@@ -311,8 +309,14 @@
      *                                with the given interface.
      */
     public final boolean isWrapperFor(Class<?> interfaces) throws SQLException {
-        checkIfClosed();
-        return interfaces.isInstance(this);
+        try {
+            if (getRealConnection().isClosed())
+                throw Util.noCurrentConnection();
+            return interfaces.isInstance(this);
+        } catch (SQLException sqle) {
+            notifyException(sqle);
+            throw sqle;
+        }
     }
     
     /**
@@ -325,14 +329,20 @@
      */
     public final <T> T unwrap(java.lang.Class<T> interfaces) 
                             throws SQLException{
-        checkIfClosed();
-        //Derby does not implement non-standard methods on 
-        //JDBC objects
-        try {
-            return interfaces.cast(this);
-        } catch (ClassCastException cce) {
-            throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP,
-                    interfaces);
+        try {
+            if (getRealConnection().isClosed())
+                throw Util.noCurrentConnection();
+            //Derby does not implement non-standard methods on 
+            //JDBC objects
+            try {
+                return interfaces.cast(this);
+            } catch (ClassCastException cce) {
+                throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP,
+                        interfaces);
+            }
+        } catch (SQLException sqle) {
+            notifyException(sqle);
+            throw sqle;
         }
     }    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java?rev=595803&r1=595802&r2=595803&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java Fri
Nov 16 12:08:28 2007
@@ -120,6 +120,7 @@
             FailedProperties40 fp = new FailedProperties40(p);
             throw new SQLClientInfoException(se.getMessage(), 
                                              se.getSQLState(), 
+                                             se.getErrorCode(),
                                              fp.getProperties());
         }
         // Allow null to simplify compliance testing through
@@ -152,7 +153,7 @@
         try { checkIfClosed(); }
         catch (SQLException se) {
             throw new SQLClientInfoException(se.getMessage(), se.getSQLState(),
-                                             fp.getProperties());
+            		se.getErrorCode(), fp.getProperties());
         }
 
         // Allow null to simplify compliance testing through
@@ -169,7 +170,9 @@
              fp.getFirstKey(), 
              fp.getFirstValue());
         throw new SQLClientInfoException(se.getMessage(),
-                                         se.getSQLState(), fp.getProperties());
+        		se.getSQLState(), 
+        		se.getErrorCode(),
+        		fp.getProperties());
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java?rev=595803&r1=595802&r2=595803&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
Fri Nov 16 12:08:28 2007
@@ -23,11 +23,16 @@
 
 import junit.framework.*;
 
+import org.apache.derby.jdbc.ClientConnectionPoolDataSource;
+import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 import java.sql.*;
+
 import javax.sql.*;
 
 /**
@@ -38,6 +43,8 @@
     
     //Default DataSource that will be used by the tests
     private DataSource ds = null;
+    protected static String dbName = 
+        TestConfiguration.getCurrent().getDefaultDatabaseName();
     
     /**
      *
@@ -114,6 +121,192 @@
         } catch (SQLException e) {
             assertSQLState("XJ128", e);
         }
+    }
+    
+    /**
+     * Test case for DERBY-3172
+     * When the Derby engine is shutdown or Network Server is brought down, any
+     * api on JDBC Connection object should generate a Connection error event.
+     */
+    public void testConnectionErrorEvent() throws SQLException, Exception
+    {
+    	Connection conn;
+    	ConnectionPoolDataSource ds;
+    	PooledConnection pc;
+    	Statement st;
+        AssertEventCatcher aes12 = new AssertEventCatcher(12);
+        //Get the correct ConnectionPoolDataSource object
+        if (usingEmbedded())
+        {
+        	ds = new EmbeddedConnectionPoolDataSource();
+            ((EmbeddedConnectionPoolDataSource)ds).setDatabaseName(dbName);
+        } else
+        {
+            ds = new ClientConnectionPoolDataSource();
+            ((ClientConnectionPoolDataSource)ds).setDatabaseName(dbName);
+        }
+        pc = ds.getPooledConnection();
+        //Add a connection event listener to ConnectionPoolDataSource
+        pc.addConnectionEventListener(aes12);
+        conn = pc.getConnection();
+        st = conn.createStatement();
+        //TAB1 does not exist and hence catch the expected exception
+        try {
+            st.executeUpdate("drop table TAB1");
+        } catch (SQLException sqle) {
+            assertSQLState("42Y55", sqle);
+        }
+        //No event should have been generated at this point
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertFalse(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();
+        //Shutdown the Derby engine or Network Server depending on what 
+        //mode we are running in.
+        if (usingEmbedded())
+        {
+        	getTestConfiguration().shutdownDatabase();
+        } else
+        {
+        	getTestConfiguration().stopNetworkServer();
+        }
+        //Now try to use various apis on the JDBC Connection object created 
+        //before shutdown and they all should generate connection error event.
+        try {
+            conn.createArrayOf("junk", null);
+        } catch (SQLException e) {
+            assertSQLState("0A000", e);
+        }
+        try {
+            conn.createNClob();
+        } catch (SQLException e) {
+            assertSQLState("0A000", e);
+        }
+        try {
+            conn.createSQLXML();
+        } catch (SQLException e) {
+            assertSQLState("0A000", e);
+        }
+        try {
+            conn.createStruct("junk", null);
+        } catch (SQLException e) {
+            assertSQLState("0A000", e);
+        }
+        try {
+            conn.createBlob();
+        } catch (SQLException e) {
+            //The first call on JDBC Connection object after Network Server
+            //shutdown will generate a communication error and that's why we
+            //are checking for SQL State 08006 rather than No current connection
+            //SQL State 08003. In embedded mode, we will get SQL State 08003
+        	//meaning No current connection
+            if (usingEmbedded())
+                assertSQLState("08003", e);
+            else
+                assertSQLState("08006", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.createClob();
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.getClientInfo();
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.getClientInfo("junk");
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.setClientInfo(null);
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.setClientInfo("junk1", "junk2");
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        assertTrue(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.isWrapperFor(this.getClass());
+        } catch (SQLException e) {
+                assertSQLState("08003", e);
+        }
+        assertFalse(aes12.didConnectionClosedEventHappen());
+        if (usingEmbedded())
+        	assertTrue(aes12.didConnectionErrorEventHappen());
+        else
+        	//We do not make any call on underneath JDBC Connection
+        	//object for isWrapperFor and hence never get Connection
+        	//Error event
+        	assertFalse(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.unwrap(this.getClass());
+        } catch (SQLException e) {
+            if (usingEmbedded())
+                assertSQLState("08003", e);
+            else
+            	//We do not make any call on underneath JDBC Connection
+            	//object for unwrap and hence never get Connection
+            	//closed exception. Instead we got exception because
+            	//client driver code is trying to unwrap this.getClass
+            	//and it can't do that
+                assertSQLState("XJ128", e);
+        }
+    	assertFalse(aes12.didConnectionClosedEventHappen());
+        if (usingEmbedded())
+        	assertTrue(aes12.didConnectionErrorEventHappen());
+        else
+        	//We do not make any call on underneath JDBC Connection
+        	//object for isWrapperFor and hence never get Connection
+        	//Error event
+        	assertFalse(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        try {
+            conn.isValid(5);
+        } catch (SQLException e) {
+            assertSQLState("08003", e);
+        }
+        if (usingEmbedded())
+        	assertTrue(aes12.didConnectionClosedEventHappen());
+        else
+        	assertFalse(aes12.didConnectionClosedEventHappen());
+    	//As per the JDBC definition, an exception and hence an event is raised
+    	//for isValid only if the param value is illegal
+    	assertFalse(aes12.didConnectionErrorEventHappen());
+        aes12.resetState();        	
+        if (usingEmbedded())
+        {
+            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+        }else
+        {
+        	getTestConfiguration().startNetworkServer();
+        }
+
+        // Get a new connection to the database
+        conn = getConnection();
+        conn.close();
     }
 
     /**

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java?rev=595803&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java
Fri Nov 16 12:08:28 2007
@@ -0,0 +1,75 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+
+import javax.sql.*;
+
+public class AssertEventCatcher implements ConnectionEventListener
+{
+    private final int catcher;
+    //The following flags will indicate what kind of event was
+    //received by this listener
+    private boolean gotConnectionClosed = false;
+    private boolean gotConnectionErrorOccured = false;
+
+    public AssertEventCatcher(int which) {
+        catcher=which;
+    }
+
+    // ConnectionEventListener methods
+    public void connectionClosed(ConnectionEvent event)
+    {
+        gotConnectionClosed = true;
+    }
+
+    public void connectionErrorOccurred(ConnectionEvent event)
+    {
+        gotConnectionErrorOccured = true;
+    }
+
+    /**
+     * Tell the caller if we received Connection closed event
+     * @return true if received Connection closed event
+     */
+    public boolean didConnectionClosedEventHappen() 
+    {
+    	return gotConnectionClosed;
+    }
+    
+    /**
+     * Tell the caller if we received Connection error event
+     * @return true if received Connection error event
+     */
+    public boolean didConnectionErrorEventHappen() 
+    {
+    	return gotConnectionErrorOccured;
+    }
+    
+    /**
+     * Clear the event received flags for this listener.
+     */
+    public void resetState() 
+    {
+    	gotConnectionClosed = false;
+    	gotConnectionErrorOccured = false;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AssertEventCatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java?rev=595803&r1=595802&r2=595803&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
Fri Nov 16 12:08:28 2007
@@ -36,8 +36,7 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 
-import javax.sql.ConnectionEvent;
-import javax.sql.ConnectionEventListener;
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher;
 import javax.sql.ConnectionPoolDataSource;
 import javax.sql.DataSource;
 import javax.sql.PooledConnection;
@@ -3614,56 +3613,5 @@
     public byte[] getBranchQualifier()
     {
         return(branch_id);
-    }
-}
-
-class AssertEventCatcher implements ConnectionEventListener
-{
-    private final int catcher;
-    //The following flags will indicate what kind of event was
-    //received by this listener
-    private boolean gotConnectionClosed = false;
-    private boolean gotConnectionErrorOccured = false;
-
-    AssertEventCatcher(int which) {
-        catcher=which;
-    }
-
-    // ConnectionEventListener methods
-    public void connectionClosed(ConnectionEvent event)
-    {
-        gotConnectionClosed = true;
-    }
-
-    public void connectionErrorOccurred(ConnectionEvent event)
-    {
-        gotConnectionErrorOccured = true;
-    }
-
-    /**
-     * Tell the caller if we received Connection closed event
-     * @return true if received Connection closed event
-     */
-    public boolean didConnectionClosedEventHappen() 
-    {
-    	return gotConnectionClosed;
-    }
-    
-    /**
-     * Tell the caller if we received Connection error event
-     * @return true if received Connection error event
-     */
-    public boolean didConnectionErrorEventHappen() 
-    {
-    	return gotConnectionErrorOccured;
-    }
-    
-    /**
-     * Clear the event received flags for this listener.
-     */
-    public void resetState() 
-    {
-    	gotConnectionClosed = false;
-    	gotConnectionErrorOccured = false;
     }
 }



Mime
View raw message