Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 69254 invoked from network); 18 Jan 2011 15:38:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Jan 2011 15:38:42 -0000 Received: (qmail 54110 invoked by uid 500); 18 Jan 2011 15:38:42 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 54049 invoked by uid 500); 18 Jan 2011 15:38:40 -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 54042 invoked by uid 99); 18 Jan 2011 15:38:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Jan 2011 15:38:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Jan 2011 15:38:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D7A062388A36; Tue, 18 Jan 2011 15:38:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1060422 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ drda/org/apache/derby/drda/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTestin... Date: Tue, 18 Jan 2011 15:38:06 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110118153806.D7A062388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhillegas Date: Tue Jan 18 15:38:05 2011 New Revision: 1060422 URL: http://svn.apache.org/viewvc?rev=1060422&view=rev Log: DERBY-4869: Implementation of Connection.abort(Executor) for JDBC 4.1. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java (with props) Modified: 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/net/NetConnection40.java db/derby/code/trunk/java/drda/org/apache/derby/drda/server.policy db/derby/code/trunk/java/drda/org/apache/derby/drda/template.policy db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=1060422&r1=1060421&r2=1060422&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 Tue Jan 18 15:38:05 2011 @@ -29,8 +29,9 @@ import java.sql.SQLException; import org.apache.derby.client.net.NetXAResource; import org.apache.derby.shared.common.sanity.SanityManager; -public abstract class Connection implements java.sql.Connection, - ConnectionCallbackInterface { +public abstract class Connection + implements java.sql.Connection, ConnectionCallbackInterface, Runnable +{ //---------------------navigational members----------------------------------- @@ -92,6 +93,7 @@ public abstract class Connection impleme // ------------------------dynamic properties--------------------------------- protected boolean open_ = true; + private boolean aborting_ = false; private boolean availableForReuse_ = false; /** @@ -646,7 +648,7 @@ public abstract class Connection impleme agent_.logWriter_.traceEntry(this, "rollback"); } - checkForClosedConnection(); + if ( !isAborting() ) { checkForClosedConnection(); } checkForInvalidXAStateOnCommitOrRollback(); flowRollback(); @@ -740,7 +742,7 @@ public abstract class Connection impleme // This is a no-op if the connection is already closed. synchronized public void closeX() throws SQLException { - if (!open_) { + if (!open_ && !isAborting()) { return; } closeResourcesX(); @@ -756,6 +758,7 @@ public abstract class Connection impleme } private void closeResourcesX() throws SQLException { + try { checkForTransactionInProgress(); @@ -793,6 +796,7 @@ public abstract class Connection impleme } markClosed(false); + aborting_ = false; try { agent_.close(); } catch (SqlException e) { @@ -2462,7 +2466,36 @@ public abstract class Connection impleme return blob; } + + /** Return true if the connection is aborting */ + public boolean isAborting() { return aborting_; } + + /** Begin aborting the connection */ + public void beginAborting() + { + aborting_ = true; + markClosed( false ); + } + ////////////////////////////////////////////////////////// + // + // Runnable BEHAVIOR + // + // This class implements Runnable so that the JDBC 4.1 abort(Executor) + // method can run the closeX() logic in a separate thread if necessary. + // + ////////////////////////////////////////////////////////// + + public void run() + { + try { + rollback(); + close(); + } catch (SQLException se) + { + se.printStackTrace( agent_.getLogWriter() ); + } + } } 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=1060422&r1=1060421&r2=1060422&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 Tue Jan 18 15:38:05 2011 @@ -30,8 +30,10 @@ import java.sql.SQLXML; import java.sql.SQLException; import java.sql.Struct; import java.util.Properties; +import java.util.concurrent.Executor; import org.apache.derby.client.ClientPooledConnection; +import org.apache.derby.client.net.NetConnection40; import org.apache.derby.shared.common.reference.SQLState; import java.util.Map; @@ -309,4 +311,15 @@ public class LogicalConnection40 } } + //////////////////////////////////////////////////////////////////// + // + // INTRODUCED BY JDBC 4.1 IN JAVA 7 + // + //////////////////////////////////////////////////////////////////// + + public void abort( Executor executor ) throws SQLException + { + ((NetConnection40) physicalConnection_).abort( executor ); + } + } // 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=1060422&r1=1060421&r2=1060422&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 Tue Jan 18 15:38:05 2011 @@ -32,12 +32,14 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLClientInfoException; import java.sql.SQLException; +import java.sql.SQLPermission; import java.sql.SQLXML; import java.sql.Struct; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Enumeration; +import java.util.concurrent.Executor; import org.apache.derby.client.ClientPooledConnection; import org.apache.derby.client.am.ClientMessageId; import org.apache.derby.client.am.FailedProperties40; @@ -393,4 +395,49 @@ public class NetConnection40 extends or } } + //////////////////////////////////////////////////////////////////// + // + // INTRODUCED BY JDBC 4.1 IN JAVA 7 + // + //////////////////////////////////////////////////////////////////// + + public void abort( Executor executor ) throws SQLException + { + // NOP if called on a closed connection. + if ( !open_ ) { return; } + // Null executor not allowed. + if ( executor == null ) + { + ClientMessageId cmi = new ClientMessageId( SQLState.UU_INVALID_PARAMETER ); + SqlException se = new SqlException( agent_.logWriter_, cmi, "executor", "null" ); + + throw se.getSQLException(); + } + + // + // Must have privilege to invoke this method. + // + // The derby jars should be granted this permission. We deliberately + // do not wrap this check in an AccessController.doPrivileged() block. + // If we did so, that would absolve outer code blocks of the need to + // have this permission granted to them too. It is critical that the + // outer code blocks enjoy this privilege. That is what allows + // connection pools to prevent ordinary code from calling abort() + // and restrict its usage to privileged tools. + // + SecurityManager securityManager = System.getSecurityManager(); + if ( securityManager != null ) + { securityManager.checkPermission( new SQLPermission( "callAbort" ) ); } + + // Mark the Connection as closed. Set the "aborting" flag to allow internal + // processing in close() to proceed. + beginAborting(); + + // + // The run() method in Connection does the + // actual releasing of resources. + // + executor.execute( this ); + } + } Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/server.policy URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/server.policy?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/drda/org/apache/derby/drda/server.policy (original) +++ db/derby/code/trunk/java/drda/org/apache/derby/drda/server.policy Tue Jan 18 15:38:05 2011 @@ -92,6 +92,12 @@ grant codeBase "${derby.install.url}derb // getProtectionDomain is an optional permission needed for printing classpath // information to derby.log permission java.lang.RuntimePermission "getProtectionDomain"; + + // + // The following permission must be granted for Connection.abort(Executor) to work. + // Note that this permission must also be granted to outer (application) code domains. + // + permission java.sql.SQLPermission "callAbort"; }; grant codeBase "${derby.install.url}derbynet.jar" @@ -181,6 +187,12 @@ grant codeBase "${derby.install.url}derb permission java.io.FilePermission "<>", "read"; permission java.io.FilePermission "java.runtime.version", "read"; permission java.io.FilePermission "java.fullversion", "read"; + + // + // The following permission must be granted for Connection.abort(Executor) to work. + // Note that this permission must also be granted to outer (application) code domains. + // + permission java.sql.SQLPermission "callAbort"; }; Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/template.policy URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/template.policy?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/drda/org/apache/derby/drda/template.policy (original) +++ db/derby/code/trunk/java/drda/org/apache/derby/drda/template.policy Tue Jan 18 15:38:05 2011 @@ -80,6 +80,11 @@ grant codeBase "${derby.install.url}derb // information to derby.log permission java.lang.RuntimePermission "getProtectionDomain"; + // + // The following permission must be granted for Connection.abort(Executor) to work. + // Note that this permission must also be granted to outer (application) code domains. + // + permission java.sql.SQLPermission "callAbort"; }; grant codeBase "${derby.install.url}derbynet.jar" 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=1060422&r1=1060421&r2=1060422&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 Tue Jan 18 15:38:05 2011 @@ -31,9 +31,11 @@ import java.sql.SQLException; import java.sql.SQLXML; import java.sql.Struct; import java.util.Properties; +import java.util.concurrent.Executor; import org.apache.derby.impl.jdbc.Util; //import org.apache.derby.impl.jdbc.EmbedConnection40; import org.apache.derby.iapi.reference.SQLState; +import org.apache.derby.impl.jdbc.EmbedConnection40; public class BrokeredConnection40 extends BrokeredConnection30 { @@ -342,5 +344,17 @@ public class BrokeredConnection40 extend notifyException(sqle); throw sqle; } - } + } + + //////////////////////////////////////////////////////////////////// + // + // INTRODUCED BY JDBC 4.1 IN JAVA 7 + // + //////////////////////////////////////////////////////////////////// + + public void abort( Executor executor ) throws SQLException + { + ((EmbedConnection40) getRealConnection()).abort( executor ); + } + } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Tue Jan 18 15:38:05 2011 @@ -115,7 +115,7 @@ import org.apache.derby.impl.jdbc.authen * @see TransactionResourceImpl * */ -public abstract class EmbedConnection implements EngineConnection +public abstract class EmbedConnection implements EngineConnection, Runnable { private static final StandardException exceptionClose = StandardException.closeException(); @@ -165,6 +165,7 @@ public abstract class EmbedConnection im // specific) ////////////////////////////////////////////////////////// private boolean active; + private boolean aborting = false; boolean autoCommit = true; boolean needCommit; @@ -1899,7 +1900,7 @@ public abstract class EmbedConnection im /* * If it isn't active, it's already been closed. */ - if (active) { + if (active || isAborting()) { if (tr.isActive()) { setupContextStack(); try { @@ -1933,6 +1934,8 @@ public abstract class EmbedConnection im } } + aborting = false; + if (!isClosed()) setInactive(); } @@ -2247,7 +2250,7 @@ public abstract class EmbedConnection im public final LanguageConnectionContext getLanguageConnection() { if (SanityManager.DEBUG) - SanityManager.ASSERT(!isClosed(), "connection is closed"); + SanityManager.ASSERT(!isClosed() || isAborting(), "connection is closed"); return getTR().getLcc(); } @@ -2472,7 +2475,7 @@ public abstract class EmbedConnection im is in a finally block. */ - checkIfClosed(); + if ( !isAborting()) { checkIfClosed(); } getTR().setupContextStack(); @@ -3322,4 +3325,32 @@ public abstract class EmbedConnection im lobFiles.remove(lobFile); } } + + /** Return true if the connection is aborting */ + public boolean isAborting() { return aborting; } + + /** Begin aborting the connection */ + public void beginAborting() + { + aborting = true; + setInactive(); + } + + ////////////////////////////////////////////////////////// + // + // Runnable BEHAVIOR + // + // This class implements Runnable so that the JDBC 4.1 abort(Executor) + // method can run the close() logic in a separate thread if necessary. + // + ////////////////////////////////////////////////////////// + + public void run() + { + try { + rollback(); + close(exceptionClose); + } catch (SQLException se) { Util.logSQLException( se ); } + } + } 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=1060422&r1=1060421&r2=1060422&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 Tue Jan 18 15:38:05 2011 @@ -28,12 +28,14 @@ import java.sql.Clob; import java.sql.Connection; import java.sql.NClob; import java.sql.SQLException; +import java.sql.SQLPermission; import java.sql.SQLXML; import java.sql.Struct; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Enumeration; +import java.util.concurrent.Executor; import org.apache.derby.jdbc.InternalDriver; import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.iapi.error.StandardException; @@ -262,4 +264,47 @@ public class EmbedConnection40 extends E throw newSQLException(SQLState.UNABLE_TO_UNWRAP,interfaces); } } + + //////////////////////////////////////////////////////////////////// + // + // INTRODUCED BY JDBC 4.1 IN JAVA 7 + // + //////////////////////////////////////////////////////////////////// + + public void abort( Executor executor ) throws SQLException + { + // NOP if called on a closed connection. + if ( isClosed() ) { return; } + // Null executor not allowed. + if ( executor == null ) + { + throw newSQLException( SQLState.UU_INVALID_PARAMETER, "executor", "null" ); + } + + // + // Must have privilege to invoke this method. + // + // The derby jars should be granted this permission. We deliberately + // do not wrap this check in an AccessController.doPrivileged() block. + // If we did so, that would absolve outer code blocks of the need to + // have this permission granted to them too. It is critical that the + // outer code blocks enjoy this privilege. That is what allows + // connection pools to prevent ordinary code from calling abort() + // and restrict its usage to privileged tools. + // + SecurityManager securityManager = System.getSecurityManager(); + if ( securityManager != null ) + { securityManager.checkPermission( new SQLPermission( "callAbort" ) ); } + + // Mark the Connection as closed. Set the "aborting" flag to allow internal + // processing in close() to proceed. + beginAborting(); + + // + // The run() method in EmbedConnection does the + // actual releasing of resources. + // + executor.execute( this ); + } + } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java Tue Jan 18 15:38:05 2011 @@ -105,7 +105,7 @@ public abstract class Util { * * @param se SQLException to log */ - private static void logSQLException(SQLException se) { + public static void logSQLException(SQLException se) { if (se == null) return; String message = se.getMessage(); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java Tue Jan 18 15:38:05 2011 @@ -43,6 +43,7 @@ import java.sql.Clob; import javax.sql.DataSource; import java.security.AccessController; import java.security.*; +import java.util.concurrent.Executor; import org.apache.derbyTesting.junit.NetworkServerTestSetup; import org.apache.derby.drda.NetworkServerControl; import org.apache.derby.jdbc.ClientDataSource; @@ -61,14 +62,47 @@ import junit.framework.TestSuite; * This class is used to test the implementations of the JDBC 4.0 methods * in the Connection interface */ -public class ConnectionMethodsTest extends BaseJDBCTestCase { +public class ConnectionMethodsTest extends Wrapper41Test +{ + /////////////////////////////////////////////////////////////////////// + // + // NESTED CLASSES + // + /////////////////////////////////////////////////////////////////////// + + /** An Executor which runs in the current thread. */ + public static final class DirectExecutor implements Executor + { + public void execute(Runnable r) + { + r.run(); + } + } + + /////////////////////////////////////////////////////////////////////// + // + // STATE + // + /////////////////////////////////////////////////////////////////////// FileInputStream is; + /////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTORS + // + /////////////////////////////////////////////////////////////////////// + public ConnectionMethodsTest(String name) { super(name); } + /////////////////////////////////////////////////////////////////////// + // + // JUnit SETUP + // + /////////////////////////////////////////////////////////////////////// + public static Test suite() { TestSuite suite = new TestSuite("ConnectionMethodsTest"); @@ -87,10 +121,18 @@ public class ConnectionMethodsTest exten protected void decorateSQL(Statement s) throws SQLException { s.execute("create table clobtable2(n int,clobcol CLOB)"); s.execute("create table blobtable2(n int,blobcol BLOB)"); + s.execute("create table abort_table(a int)"); } }; } + + /////////////////////////////////////////////////////////////////////// + // + // TEST CASES + // + /////////////////////////////////////////////////////////////////////// + /** * Test the createClob method implementation in the Connection interface * @@ -342,4 +384,92 @@ public class ConnectionMethodsTest exten } } } + + /** + * Test the JDBC 4.1 Connection.abort(Executor) method. + */ + public void testAbort() throws Exception + { + // + // In order to run this test, a special permission must be granted to + // the jar file containing this method. + // + if ( !TestConfiguration.loadingFromJars() ) { return; } + + // NOP if called on a closed connection + Connection conn0 = openUserConnection( "user0"); + conn0.close(); + Wrapper41Conn wrapper0 = new Wrapper41Conn( conn0 ); + wrapper0.abort( new DirectExecutor() ); + + Connection conn1 = openUserConnection( "user1"); + conn1.setAutoCommit( false ); + final Wrapper41Conn wrapper1 = new Wrapper41Conn( conn1 ); + + // the Executor may not be null + try { + wrapper1.abort( null ); + } + catch (SQLException se) + { + assertSQLState( "XCZ02", se ); + } + + PreparedStatement ps = prepareStatement + ( conn1, "insert into app.abort_table( a ) values ( 1 )" ); + ps.execute(); + ps.close(); + + // abort the connection + try { + // + // This doPrivileged block absolves outer code blocks (like JUnit) + // of the need to be granted SQLPermission( "callAbort" ). However, + // derbyTesting.jar still needs that permission. + // + AccessController.doPrivileged + ( + new PrivilegedExceptionAction() + { + public Object run() throws Exception + { + DirectExecutor executor = new DirectExecutor(); + wrapper1.abort( executor ); + return null; + } + } + ); + } + catch (Exception e) + { + e.printStackTrace(); + // + // We need to fail now. But the connection holds locks + // which prevent our test apparatus from cleaning up. + // We need to release those locks before failing. + // + conn1.rollback(); + fail( "Could not abort connection!" ); + } + + // verify that the connection is closed + try { + prepareStatement( conn1, "select * from sys.systables" ); + fail( "Connection should be dead!" ); + } + catch (SQLException se) + { + assertSQLState( "08003", se ); + } + + // verify that the changes were rolled back + Connection conn2 = openUserConnection( "user2"); + ps = prepareStatement( conn2, "select * from app.abort_table" ); + ResultSet rs = ps.executeQuery(); + assertFalse( rs.next() ); + rs.close(); + ps.close(); + conn2.close(); + } + } Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java?rev=1060422&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java Tue Jan 18 15:38:05 2011 @@ -0,0 +1,103 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.Wrapper41Conn + + 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.jdbc4; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.concurrent.Executor; + +import org.apache.derby.impl.jdbc.EmbedConnection40; +import org.apache.derby.iapi.jdbc.BrokeredConnection40; +import org.apache.derby.client.net.NetConnection40; +import org.apache.derby.client.am.LogicalConnection40; + +/** + * A wrapper around the abort(Executor) method added by JDBC 4.1. + * We can eliminate this class after Java 7 goes GA and we are allowed + * to use the Java 7 compiler to build our released versions of derbyTesting.jar. + */ +public class Wrapper41Conn +{ + /////////////////////////////////////////////////////////////////////// + // + // STATE + // + /////////////////////////////////////////////////////////////////////// + + private EmbedConnection40 _embedded; + private NetConnection40 _netclient; + private BrokeredConnection40 _brokeredConnection; + private LogicalConnection40 _logicalConnection; + + /////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTORS + // + /////////////////////////////////////////////////////////////////////// + + public Wrapper41Conn( Object wrapped ) throws Exception + { + if ( wrapped instanceof EmbedConnection40 ) { _embedded = (EmbedConnection40) wrapped; } + else if ( wrapped instanceof NetConnection40 ) { _netclient = (NetConnection40) wrapped; } + else if ( wrapped instanceof BrokeredConnection40 ) { _brokeredConnection = (BrokeredConnection40) wrapped; } + else if ( wrapped instanceof LogicalConnection40 ) { _logicalConnection = (LogicalConnection40) wrapped; } + else { throw nothingWrapped(); } + } + + /////////////////////////////////////////////////////////////////////// + // + // JDBC 4.1 BEHAVIOR + // + /////////////////////////////////////////////////////////////////////// + + public void abort( Executor executor ) throws SQLException + { + if ( _embedded != null ) { _embedded.abort( executor ); } + else if ( _netclient != null ) { _netclient.abort( executor ); } + else if ( _brokeredConnection != null ) { _brokeredConnection.abort( executor ); } + else if ( _logicalConnection != null ) { _logicalConnection.abort( executor ); } + else { throw nothingWrapped(); } + } + + /////////////////////////////////////////////////////////////////////// + // + // OTHER PUBLIC BEHAVIOR + // + /////////////////////////////////////////////////////////////////////// + + public Connection getWrappedObject() throws SQLException + { + if ( _embedded != null ) { return _embedded; } + else if ( _netclient != null ) { return _netclient; } + else { throw nothingWrapped(); } + } + + /////////////////////////////////////////////////////////////////////// + // + // MINIONS + // + /////////////////////////////////////////////////////////////////////// + + private SQLException nothingWrapped() { return new SQLException( "Nothing wrapped!" ); } + +} + Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=1060422&r1=1060421&r2=1060422&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy Tue Jan 18 15:38:05 2011 @@ -133,6 +133,9 @@ grant codeBase "${derbyTesting.codejar}d // traces upon failure. permission java.lang.RuntimePermission "getStackTrace"; permission java.lang.RuntimePermission "modifyThreadGroup"; + + // This permission is needed to call the Connection.abort(Executor) method added by JDBC 4.1 + permission java.sql.SQLPermission "callAbort"; }; // @@ -182,6 +185,9 @@ grant codeBase "${derbyTesting.clientjar permission java.lang.RuntimePermission "getStackTrace"; permission java.lang.RuntimePermission "modifyThreadGroup"; + // This permission is needed to call the Connection.abort(Executor) method added by JDBC 4.1 + permission java.sql.SQLPermission "callAbort"; + }; // @@ -248,6 +254,12 @@ grant codeBase "${derbyTesting.testjar}d permission org.apache.derby.security.SystemPermission "jmx", "control"; permission org.apache.derby.security.SystemPermission "engine", "monitor"; permission org.apache.derby.security.SystemPermission "server", "control,monitor"; + + // useful for debugging + //permission java.lang.RuntimePermission "getProtectionDomain"; + + // This permission is needed to call the Connection.abort(Executor) method added by JDBC 4.1 + permission java.sql.SQLPermission "callAbort"; // These permissions are needed when testing code instrumented with EMMA. permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";