Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 18901 invoked from network); 17 Apr 2006 22:18:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Apr 2006 22:18:51 -0000 Received: (qmail 31661 invoked by uid 500); 17 Apr 2006 22:18:50 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 31621 invoked by uid 500); 17 Apr 2006 22:18:50 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 31610 invoked by uid 99); 17 Apr 2006 22:18:50 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Apr 2006 15:18:50 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 17 Apr 2006 15:18:49 -0700 Received: (qmail 18735 invoked by uid 65534); 17 Apr 2006 22:18:28 -0000 Message-ID: <20060417221828.18734.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r394788 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/suites/ testing/org/apache/derbyTesting/functionTests/... Date: Mon, 17 Apr 2006 22:18:26 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rhillegas Date: Mon Apr 17 15:18:21 2006 New Revision: 394788 URL: http://svn.apache.org/viewcvs?rev=394788&view=rev Log: DERBY-941: Commit Narayanan's statementeventlisteners_embedded_v2.diff patch, implementing embedded support for JDBC4 statement event listening. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java (with props) Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection40.java db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java Mon Apr 17 15:18:21 2006 @@ -102,4 +102,20 @@ Optionally wrap a CallableStatement with an CallableStatement. */ public CallableStatement wrapStatement(CallableStatement realStatement, String sql) throws SQLException; + + /** + * Close called on the associated PreparedStatement object + * @param statement PreparedStatement object on which the close event + * occurred + */ + public void onStatementClose(PreparedStatement statement); + + /** + * Error occurred on associated PreparedStatement object + * @param statement PreparedStatement object on which the + * error occured + * @param sqle The SQLExeption that caused the error + */ + public void onStatementErrorOccurred(PreparedStatement statement,SQLException sqle); + } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java Mon Apr 17 15:18:21 2006 @@ -68,6 +68,7 @@ import java.io.Reader; import java.sql.Types; +import org.apache.derby.iapi.jdbc.BrokeredConnectionControl; /** * @@ -94,6 +95,8 @@ protected PreparedStatement preparedStatement; private Activation activation; + + private BrokeredConnectionControl bcc=null; // By default a PreparedStatement is poolable when it is created //required for jdbc4.0 methods @@ -208,6 +211,8 @@ */ void closeActions() throws SQLException { + if (bcc!=null) + bcc.onStatementClose(this); //we release the resource for preparedStatement preparedStatement = null; @@ -246,15 +251,19 @@ * @exception SQLException thrown on failure. */ public final java.sql.ResultSet executeQuery() throws SQLException { - executeStatement(activation, true, false); - - if (SanityManager.DEBUG) { - if (results == null) - SanityManager.THROWASSERT("no results returned on executeQuery()"); - } - - return results; - } + try { + executeStatement(activation, true, false); + } catch(SQLException sqle) { + checkStatementValidity(sqle); + } + + if (SanityManager.DEBUG) { + if (results == null) + SanityManager.THROWASSERT("no results returned on executeQuery()"); + } + + return results; + } /** * Execute a SQL INSERT, UPDATE or DELETE statement. In addition, @@ -265,10 +274,14 @@ * for SQL statements that return nothing * @exception SQLException thrown on failure. */ - public final int executeUpdate() throws SQLException { - executeStatement(activation, false, true); - return updateCount; - } + public final int executeUpdate() throws SQLException { + try { + executeStatement(activation, false, true); + } catch(SQLException sqle) { + checkStatementValidity(sqle); + } + return updateCount; + } /** * Set a parameter to SQL NULL. @@ -1107,9 +1120,15 @@ * @see java.sql.Statement#execute * @exception SQLException thrown on failure. */ - public final boolean execute() throws SQLException { - return executeStatement(activation, false, false); - } + public final boolean execute() throws SQLException { + boolean ret=false; + try{ + ret = executeStatement(activation, false, false); + } catch(SQLException sqle) { + checkStatementValidity(sqle); + } + return ret; + } /** * Set a parameter to a java.sql.Date value. The driver converts this * to a SQL DATE value when it sends it to the database. @@ -1433,7 +1452,49 @@ sourceType); return se; } - + /* + * This method is used to initialize the BrokeredConnectionControl + * variable with its implementation. This method will be called in the + * BrokeredConnectionControl class + * + * @param control used to call the onStatementClose and + * onStatementErrorOccurred methods that have logic to + * raise StatementEvents for the close and error events + * on the PreparedStatement + * + */ + public void setBrokeredConnectionControl(BrokeredConnectionControl control) { + bcc = control; + } + + /* + * Method calls onStatementError occurred on the + * BrokeredConnectionControl class after checking the + * SQLState of the SQLException thrown. + */ + + private void checkStatementValidity(SQLException sqle) throws SQLException { + /* + * The subclass of SQLException thrown when the SQLState class value is + * '42'. This indicates that the in-progress query has violated SQL + * syntax rules. + * + * Check if the exception has occurred because the connection + * associated with the PreparedStatement has been closed + * + * This exception has the SQLState of 08003 which is represented + * by the constant SQLState.ERROR_CLOSE + */ + if(bcc != null && (sqle.getSQLState().equals("08003") + || sqle.getSQLState().startsWith(SQLState.LSE_COMPILATION_PREFIX)) ) { + //call the BrokeredConnectionControl interface method + //onStatementErrorOccurred + bcc.onStatementErrorOccurred(this,sqle); + } + throw sqle; + } + + //jdbc 4.0 methods @@ -1518,5 +1579,4 @@ return isPoolable; } - } Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Mon Apr 17 15:18:21 2006 @@ -31,6 +31,8 @@ import org.apache.derby.iapi.jdbc.BrokeredConnection; import org.apache.derby.iapi.jdbc.BrokeredConnectionControl; import org.apache.derby.iapi.jdbc.EngineConnection; +import org.apache.derby.impl.jdbc.EmbedPreparedStatement; +import org.apache.derby.impl.jdbc.EmbedCallableStatement; import java.sql.Connection; @@ -88,7 +90,7 @@ */ private final boolean requestPassword; - private boolean isActive; + protected boolean isActive; private synchronized int nextId() { @@ -428,16 +430,45 @@ return s; } /** - No need to wrap statements for PooledConnections. - */ + * Call the setBrokeredConnectionControl method inside the + * EmbedPreparedStatement class to set the BrokeredConnectionControl + * variable to this instance of EmbedPooledConnection + * This will then be used to call the onStatementErrorOccurred + * and onStatementClose events when the corresponding events + * occur on the PreparedStatement + * + * @param ps PreparedStatment to be wrapped + * @param sql String + * @param generatedKeys Object + * @return returns the wrapped PreparedStatement + * @throws java.sql.SQLException + */ public PreparedStatement wrapStatement(PreparedStatement ps, String sql, Object generatedKeys) throws SQLException { - return ps; + /* + + */ + EmbedPreparedStatement ps_ = (EmbedPreparedStatement)ps; + ps_.setBrokeredConnectionControl(this); + return (PreparedStatement)ps_; } - /** - No need to wrap statements for PooledConnections. - */ + + /** + * Call the setBrokeredConnectionControl method inside the + * EmbedCallableStatement class to set the BrokeredConnectionControl + * variable to this instance of EmbedPooledConnection + * This will then be used to call the onStatementErrorOccurred + * and onStatementClose events when the corresponding events + * occur on the CallableStatement + * + * @param cs CallableStatment to be wrapped + * @param sql String + * @return returns the wrapped CallableStatement + * @throws java.sql.SQLException + */ public CallableStatement wrapStatement(CallableStatement cs, String sql) throws SQLException { - return cs; + EmbedCallableStatement cs_ = (EmbedCallableStatement)cs; + cs_.setBrokeredConnectionControl(this); + return (CallableStatement)cs_; } /** @@ -468,5 +499,34 @@ return connString; } - + + /*-----------------------------------------------------------------*/ + /* + * These methods are from the BrokeredConnectionControl interface. + * These methods are needed to provide StatementEvent support for + * derby. + * They are actually implemented in EmbedPooledConnection40 but have + * a dummy implementation here so that the compilation wont fail when they + * are compiled with jdk1.4 + */ + + /** + * Dummy implementation for the actual methods found in + * org.apache.derby.jdbc.EmbedPooledConnection40 + * @param statement PreparedStatement + */ + public void onStatementClose(PreparedStatement statement) { + + } + + /** + * Dummy implementation for the actual methods found in + * org.apache.derby.jdbc.EmbedPooledConnection40 + * @param statement PreparedStatement + * @param sqle SQLException + */ + public void onStatementErrorOccurred(PreparedStatement statement, + SQLException sqle) { + + } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection40.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection40.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection40.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection40.java Mon Apr 17 15:18:21 2006 @@ -23,6 +23,10 @@ import java.sql.Connection; import java.sql.SQLException; +import java.util.Enumeration; +import java.util.Vector; +import java.sql.PreparedStatement; +import javax.sql.StatementEvent; import javax.sql.StatementEventListener; /** @@ -37,6 +41,11 @@ */ class EmbedPooledConnection40 extends EmbedPooledConnection { + + //using generics to avoid casting problems + protected final Vector statementEventListeners = + new Vector(); + EmbedPooledConnection40 (ReferenceableDataSource ds, String user, String password, boolean requestPassword) throws SQLException { @@ -55,8 +64,9 @@ * @since 1.6 */ public void removeStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException ( - "addStatementEventListener(StatementEventListener listener)"); + if (listener == null) + return; + statementEventListeners.removeElement(listener); } /** @@ -75,7 +85,47 @@ * @since 1.6 */ public void addStatementEventListener(StatementEventListener listener) { - throw new UnsupportedOperationException ( - "addStatementEventListener(StatementEventListener listener)"); + if (!isActive) + return; + if (listener == null) + return; + statementEventListeners.addElement(listener); + } + + /** + * Raise the statementClosed event for all the listeners when the + * corresponding events occurs + * @param statement PreparedStatement + */ + public void onStatementClose(PreparedStatement statement) { + if (!statementEventListeners.isEmpty()){ + StatementEvent event = new StatementEvent(this,statement); + //synchronized block on statementEventListeners to make it thread + //safe + synchronized(statementEventListeners) { + for (StatementEventListener l : statementEventListeners) { + l.statementClosed(event); + } + } + } + } + + /** + * Raise the statementErrorOccurred event for all the listeners when the + * corresponding events occurs + * @param statement PreparedStatement + * @param sqle SQLException + */ + public void onStatementErrorOccurred(PreparedStatement statement,SQLException sqle) { + if (!statementEventListeners.isEmpty()){ + StatementEvent event = new StatementEvent(this,statement,sqle); + //synchronized block on statementEventListeners to make it thread + //safe + synchronized(statementEventListeners) { + for (StatementEventListener l : statementEventListeners){ + l.statementErrorOccurred(event); + } + } + } } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Mon Apr 17 15:18:21 2006 @@ -165,6 +165,7 @@ Wrap and control a PreparedStatement */ public PreparedStatement wrapStatement(PreparedStatement ps, String sql, Object generatedKeys) throws SQLException { + ps = super.wrapStatement(ps,sql,generatedKeys); XAStatementControl sc = new XAStatementControl(this, ps, sql, generatedKeys); return (PreparedStatement) sc.applicationStatement; } @@ -172,6 +173,7 @@ Wrap and control a PreparedStatement */ public CallableStatement wrapStatement(CallableStatement cs, String sql) throws SQLException { + cs = super.wrapStatement(cs,sql); XAStatementControl sc = new XAStatementControl(this, cs, sql); return (CallableStatement) sc.applicationStatement; } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Mon Apr 17 15:18:21 2006 @@ -36,4 +36,6 @@ #failing (hanging?) on jdk 1.5/jdk 1.6 jdbcapi/checkDataSource.java jdbcapi/checkDataSource30.java - +#exclude the statement events test until the feature is added on the +#client side +jdbc4/StatementEventsTest.junit 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=394788&r1=394787&r2=394788&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 Mon Apr 17 15:18:21 2006 @@ -4,6 +4,7 @@ jdbc4/TestQueryObject.java jdbc4/TestDbMetaData.java jdbc4/TestJDBC40Exception.java +jdbc4/StatementEventsTest.junit jdbc4/CallableStatementTest.junit jdbc4/RowIdNotImplementedTest.junit jdbc4/StatementTest.junit Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java?rev=394788&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java Mon Apr 17 15:18:21 2006 @@ -0,0 +1,180 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.StatementEventsTest + + Copyright 2006 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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.jdbc4; + +import java.sql.*; +import javax.sql.*; +import junit.framework.*; + +import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase; + +/* + This class is used to test the JDBC4 statement event + support +*/ +public class StatementEventsTest extends BaseJDBCTestCase + implements StatementEventListener { + + PooledConnection pooledConnection; + Connection conn; + PreparedStatement ps_close; + PreparedStatement ps_error; + boolean statementCloseEventOccurred=false; + boolean statementErrorEventOccurred=false; + + + /** + * Create a test with the given name. + * + * @param name name of the test. + */ + public StatementEventsTest(String name) { + super(name); + } + + /** + * + * get a connection object from which the PreparedStatement objects + * that will be used to raise the events will be created + * + */ + public void setUp() throws SQLException { + ConnectionPoolDataSource cpds = getConnectionPoolDataSource(); + pooledConnection = cpds.getPooledConnection(); + //register this class as a event listener for the + //statement events + pooledConnection.addStatementEventListener(this); + + //Get a connection from the PooledConnection object + conn = pooledConnection.getConnection(); + } + + /** + * + * Close the PooledConnection object and the connection and the + * statements obtained from it. + * + */ + + public void tearDown() throws SQLException { + if(ps_close != null && !ps_close.isClosed()) { + ps_close.close(); + } + if(ps_error != null && !ps_error.isClosed()) { + ps_error.close(); + } + if(conn != null && !conn.isClosed()) { + conn.rollback(); + conn.close(); + } + if(pooledConnection != null) + pooledConnection.close(); + } + + /* + The method closes a created Prepared Statement + to raise a closed event + */ + void raiseCloseEvent() { + try { + ps_close = conn.prepareStatement("create table temp(n int)"); + + //call the close method on this prepared statement object + //this should result in a statement event being generated + //control is transferred to the sattementCLosed function + ps_close.close(); + } catch(SQLException e) { + e.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /* + This method closes a connection and then tries to close the prepared + statement associated with the connection causing an error + event + */ + void raiseErrorEvent() { + try { + ps_error = conn.prepareStatement("create table temp(n int)"); + + //close the connection associated with this prepared statement + conn.close(); + //Now execute the prepared statement this should cause an error + ps_error.execute(); + + } catch(SQLException e) { + /* + Throw an exception only if the exception does not have a + state of 08003 which is the state of the SqlException + got when the connection associated with the PreparedStatement + is closed before doing a execute on the PreparedStatement + */ + if(!(e.getSQLState().compareTo("08003") == 0)) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /* + implementations of methods in interface + javax.sql.StatementEventListener + */ + + public void statementClosed(StatementEvent event) { + statementCloseEventOccurred = true; + if(ps_close==null || !event.getStatement().equals(ps_close)) { + System.out.println("The statement event has the wrong reference + of PreparedStatement"); + } + } + + public void statementErrorOccurred(StatementEvent event) { + statementErrorEventOccurred = true; + if(ps_error==null || !event.getStatement().equals(ps_error)) { + System.out.println("The statement event has the wrong reference + of PreparedStatement"); + } + } + + /* + Check to see if the events were properly raised during execution + */ + public void testIfEventOccurred() { + raiseCloseEvent(); + raiseErrorEvent(); + if(statementCloseEventOccurred != true) { + System.out.println("The Close Event did not occur"); + } + if(statementErrorEventOccurred != true) { + System.out.println("The Error Event did not occur"); + } + } + + /** + * Return suite with all tests of the class. + */ + public static Test suite() { + return (new TestSuite(StatementEventsTest.class, + "StatementEventsTest suite")); + } +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementEventsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java Mon Apr 17 15:18:21 2006 @@ -339,5 +339,5 @@ //The SQLState of the SQLExcepion thrown when a class for which //isWrapperFor returns false is passed as a parameter to the //unwrap method. - public static final String UNABLE_TO_UNWRAP = "XJ120"; + public static final String UNABLE_TO_UNWRAP = "XJ128"; } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=394788&r1=394787&r2=394788&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java Mon Apr 17 15:18:21 2006 @@ -307,16 +307,7 @@ if(HAVE_DRIVER_CLASS) { classname = getDataSourcePrefix() + REGULAR_DATASOURCE_STRING + "DataSource"; - // The JDBC 4.0 implementation of the DataSource interface - // is suffixed with "40". Use it if it is available and - // the JVM version is at least 1.6. - if (JVMInfo.JDK_ID >= JVMInfo.J2SE_16) { - String classname40 = classname + "40"; - try { - Class.forName(classname40); - classname = classname40; - } catch (ClassNotFoundException e) {} - } + classname = checkForJDBC40Implementation(classname); return (javax.sql.DataSource) getDataSourceWithReflection(classname, attrs); } else @@ -357,8 +348,32 @@ public static javax.sql.ConnectionPoolDataSource getConnectionPoolDataSource(Properties attrs) { String classname = getDataSourcePrefix() + CONNECTION_POOL_DATASOURCE_STRING + "DataSource"; + classname = checkForJDBC40Implementation(classname); return (javax.sql.ConnectionPoolDataSource) getDataSourceWithReflection(classname, attrs); } + + /** + * returns the class name for the JDBC40 implementation + * if present. otherwise returns the class name of the class + * written for the lower jdk versions + * @param classname String + * @return String containing the name of the appropriate + * implementation + */ + public static String checkForJDBC40Implementation(String classname) { + String classname_ = classname; + // The JDBC 4.0 implementation of the + // interface is suffixed with "40". Use it if it is available + // and the JVM version is at least 1.6. + if (JVMInfo.JDK_ID >= JVMInfo.J2SE_16) { + String classname40 = classname_ + "40"; + try { + Class.forName(classname40); + classname_ = classname40; + } catch (ClassNotFoundException e) {} + } + return classname_; + } public static String getDataSourcePrefix() {