Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3477DB60 for ; Mon, 23 Jul 2012 07:11:13 +0000 (UTC) Received: (qmail 99440 invoked by uid 500); 23 Jul 2012 07:11:13 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 99297 invoked by uid 500); 23 Jul 2012 07:11:10 -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 99244 invoked by uid 99); 23 Jul 2012 07:11:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 07:11:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Mon, 23 Jul 2012 07:10:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6EF79238890D; Mon, 23 Jul 2012 07:09:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1364524 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ Date: Mon, 23 Jul 2012 07:09:55 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120723070955.6EF79238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Mon Jul 23 07:09:54 2012 New Revision: 1364524 URL: http://svn.apache.org/viewvc?rev=1364524&view=rev Log: DERBY-5872: Inconsistency between isWrapperFor() and unwrap() in logical statements Make LogicalStatementEntity's isWrapperFor() only check the interfaces implemented by the logical statement. This makes it consistent with the unwrap() method, and also consistent with how isWrapperFor() works in LogicalConnection40 and LogicalDatabaseMetaData40. Add test cases for the new behaviour in PreparedStatementTest and CallableStatementTest. Enable ClosedObjectTest for logical statements. Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java?rev=1364524&r1=1364523&r2=1364524&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java Mon Jul 23 07:09:54 2012 @@ -231,8 +231,8 @@ abstract class LogicalStatementEntity * instance implements {@code iface} */ public boolean isWrapperFor(Class iface) throws SQLException { - return ((org.apache.derby.client.am.Statement) getPhysStmt()) - .isWrapperFor(iface); + getPhysStmt(); // Just to check that the statement is not closed. + return iface.isInstance(this); } /** Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java?rev=1364524&r1=1364523&r2=1364524&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java Mon Jul 23 07:09:54 2012 @@ -491,6 +491,10 @@ public class CallableStatementTest exte assertFalse(cStmt.isWrapperFor(ResultSet.class)); } + public void testIsWrapperForSelf() throws SQLException { + assertTrue(cStmt.isWrapperFor(cStmt.getClass())); + } + public void testUnwrapStatement() throws SQLException { Statement stmt = cStmt.unwrap(Statement.class); assertSame("Unwrap returned wrong object.", cStmt, stmt); @@ -506,6 +510,11 @@ public class CallableStatementTest exte assertSame("Unwrap returned wrong object.", cStmt, cs); } + public void testUnwrapAsSelf() throws SQLException { + PreparedStatement cs = cStmt.unwrap(cStmt.getClass()); + assertSame("Unwrap returned wrong object.", cStmt, cs); + } + public void testUnwrapResultSet() { try { ResultSet rs = cStmt.unwrap(ResultSet.class); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?rev=1364524&r1=1364523&r2=1364524&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java Mon Jul 23 07:09:54 2012 @@ -372,6 +372,10 @@ public class PreparedStatementTest exten assertFalse(ps.isWrapperFor(ResultSet.class)); } + public void testIsWrapperForSelf() throws SQLException { + assertTrue(ps.isWrapperFor(ps.getClass())); + } + public void testUnwrapStatement() throws SQLException { Statement stmt = ps.unwrap(Statement.class); assertSame("Unwrap returned wrong object.", ps, stmt); @@ -382,6 +386,11 @@ public class PreparedStatementTest exten assertSame("Unwrap returned wrong object.", ps, ps2); } + public void testUnwrapAsSelf() throws SQLException { + PreparedStatement ps2 = ps.unwrap(ps.getClass()); + assertSame("Unwrap returned wrong object.", ps, ps2); + } + public void testUnwrapCallableStatement() { try { CallableStatement cs = ps.unwrap(CallableStatement.class); Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java?rev=1364524&r1=1364523&r2=1364524&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java Mon Jul 23 07:09:54 2012 @@ -28,6 +28,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; import java.util.Properties; import javax.sql.ConnectionPoolDataSource; import javax.sql.DataSource; @@ -117,9 +120,8 @@ public class ClosedObjectTest extends Ba /** Creates a suite with all tests in the class. */ public static Test suite() { TestSuite suite = new TestSuite("ClosedObjectTest suite"); - suite.addTest(baseSuite("ClosedObjectTest:embedded")); - suite.addTest(TestConfiguration.clientServerDecorator( - baseSuite("ClosedObjectTest:client"))); + suite.addTest(baseSuite(false)); + suite.addTest(baseSuite(true)); return suite; } @@ -128,11 +130,13 @@ public class ClosedObjectTest extends Ba * DataSource, ConnectionPoolDataSource * and XADataSource to obtain objects. * + * @param network whether or not to run tests with the network client * @return a Test value * @exception Exception if an error occurs while building the test suite */ - private static Test baseSuite(String name) { - TestSuite topSuite = new TestSuite(name); + private static Test baseSuite(boolean network) { + TestSuite topSuite = new TestSuite( + "ClosedObjectTest:" + (network ? "client" : "embedded")); TestSuite dsSuite = new TestSuite("ClosedObjectTest DataSource"); DataSourceDecorator dsDecorator = new DataSourceDecorator(dsSuite); @@ -141,21 +145,43 @@ public class ClosedObjectTest extends Ba // JDBC 3 required for ConnectionPoolDataSource and XADataSource if (JDBC.vmSupportsJDBC3()) { - - TestSuite poolSuite = new TestSuite( - "ClosedObjectTest ConnectionPoolDataSource"); - PoolDataSourceDecorator poolDecorator = - new PoolDataSourceDecorator(poolSuite); - topSuite.addTest(poolDecorator); - fillDataSourceSuite(poolSuite, poolDecorator); - + + // Plain connection pool test. + topSuite.addTest(poolSuite(Collections.emptyMap())); + + // The client driver has a variant of connection pool that caches + // and reuses JDBC statements. Test it here by setting the + // maxStatements property. + if (network) { + topSuite.addTest(poolSuite(Collections.singletonMap( + "maxStatements", Integer.valueOf(5)))); + } + TestSuite xaSuite = new TestSuite("ClosedObjectTest XA"); XADataSourceDecorator xaDecorator = new XADataSourceDecorator(xaSuite); topSuite.addTest(xaDecorator); fillDataSourceSuite(xaSuite, xaDecorator); } - return topSuite; + return network ? + TestConfiguration.clientServerDecorator(topSuite) : + topSuite; + } + + /** + * Creates a suite that tests objects produced by a + * ConnectionPoolDataSource. + * + * @param dsProps properties to set on the data source + * @return a suite + */ + private static Test poolSuite(Map dsProps) { + TestSuite poolSuite = new TestSuite( + "ClosedObjectTest ConnectionPoolDataSource"); + PoolDataSourceDecorator poolDecorator = + new PoolDataSourceDecorator(poolSuite, dsProps); + fillDataSourceSuite(poolSuite, poolDecorator); + return poolDecorator; } /** @@ -750,13 +776,17 @@ public class ClosedObjectTest extends Ba * ConnectionPoolDataSource. */ private static class PoolDataSourceDecorator extends DataSourceDecorator { + private final Map dsProps; + /** * Creates a new PoolDataSourceDecorator instance. * * @param test the test to decorate + * @param dsProps data source properties */ - public PoolDataSourceDecorator(Test test) { + public PoolDataSourceDecorator(Test test, Map dsProps) { super(test); + this.dsProps = dsProps; } /** @@ -768,6 +798,11 @@ public class ClosedObjectTest extends Ba */ protected Connection newConnection_() throws SQLException { ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource(); + for (Iterator it = dsProps.entrySet().iterator(); it.hasNext(); ) { + Map.Entry e = (Map.Entry) it.next(); + J2EEDataSource.setBeanProperty( + ds, (String) e.getKey(), e.getValue()); + } PooledConnection pc = ds.getPooledConnection(); return pc.getConnection();