Author: markt
Date: Mon Dec 9 21:19:26 2013
New Revision: 1549686
URL: http://svn.apache.org/r1549686
Log:
Fix DBCP-347
Correct implementation of DelegatingStatement.isWrapperFor(). Also fix
DelegatingDatabaseMetaData.isWrapperFor() and
DelegatingResultSet.isWrapperFor() that had the same problem.
Based on a patch by Robert Poskrobek
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingStatement.java
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
Modified: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml?rev=1549686&r1=1549685&r2=1549686&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
(original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml Mon
Dec 9 21:19:26 2013
@@ -55,6 +55,11 @@ The <action> type attribute can be add,u
Correct implementation of DelegatingConnection.isWrapperFor() so it
works correctly with older JDBC drivers.
</action>
+ <action dev="markt" issue="DBCP-347" type="fix" due-to="Robert
Poskrobek">
+ Correct implementation of DelegatingStatement.isWrapperFor(). Also fix
+ DelegatingDatabaseMetaData.isWrapperFor() and
+ DelegatingResultSet.isWrapperFor() that had the same problem.
+ </action>
</release>
<release version="1.4.1" date="TBD" description="TBD">
<action dev="psteitz" issue="DBCP-367" type="fix" due-to="Ken
Tatsushita">
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java?rev=1549686&r1=1549685&r2=1549686&view=diff
==============================================================================
---
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
(original)
+++
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
Mon Dec 9 21:19:26 2013
@@ -1122,7 +1122,13 @@ public class DelegatingDatabaseMetaData
/* JDBC_4_ANT_KEY_BEGIN */
public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return iface.isAssignableFrom(getClass()) || _meta.isWrapperFor(iface);
+ if (iface.isAssignableFrom(getClass())) {
+ return true;
+ } else if (iface.isAssignableFrom(_meta.getClass())) {
+ return true;
+ } else {
+ return _meta.isWrapperFor(iface);
+ }
}
public <T> T unwrap(Class<T> iface) throws SQLException {
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingResultSet.java?rev=1549686&r1=1549685&r2=1549686&view=diff
==============================================================================
---
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
(original)
+++
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
Mon Dec 9 21:19:26 2013
@@ -623,7 +623,13 @@ public class DelegatingResultSet extends
/* JDBC_4_ANT_KEY_BEGIN */
public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return iface.isAssignableFrom(getClass()) || _res.isWrapperFor(iface);
+ if (iface.isAssignableFrom(getClass())) {
+ return true;
+ } else if (iface.isAssignableFrom(_res.getClass())) {
+ return true;
+ } else {
+ return _res.isWrapperFor(iface);
+ }
}
public <T> T unwrap(Class<T> iface) throws SQLException {
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingStatement.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingStatement.java?rev=1549686&r1=1549685&r2=1549686&view=diff
==============================================================================
---
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingStatement.java
(original)
+++
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/java/org/apache/commons/dbcp/DelegatingStatement.java
Mon Dec 9 21:19:26 2013
@@ -451,7 +451,13 @@ public class DelegatingStatement extends
/* JDBC_4_ANT_KEY_BEGIN */
public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return iface.isAssignableFrom(getClass()) || _stmt.isWrapperFor(iface);
+ if (iface.isAssignableFrom(getClass())) {
+ return true;
+ } else if (iface.isAssignableFrom(_stmt.getClass())) {
+ return true;
+ } else {
+ return _stmt.isWrapperFor(iface);
+ }
}
public <T> T unwrap(Class<T> iface) throws SQLException {
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java?rev=1549686&r1=1549685&r2=1549686&view=diff
==============================================================================
---
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
(original)
+++
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
Mon Dec 9 21:19:26 2013
@@ -5,9 +5,9 @@
* 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.
@@ -17,6 +17,7 @@
package org.apache.commons.dbcp;
+import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@@ -67,33 +68,33 @@ public class TestDelegatingStatement ext
assertEquals(stmt1.hashCode(), stmt2.hashCode());
assertTrue(stmt1.hashCode() != stmt3.hashCode());
}
-
+
public void testEquals() {
delegateStmt = new TesterPreparedStatement(delegateConn,"select * from
foo");
DelegatingStatement stmt1 = new DelegatingStatement(conn,
delegateStmt);
DelegatingStatement stmt2 = new DelegatingStatement(conn,
delegateStmt);
DelegatingStatement stmt3 = new DelegatingStatement(conn, null);
DelegatingStatement stmt4 = new DelegatingStatement(conn, stmt1);
-
+
// not null
assertTrue(!stmt1.equals(null));
-
+
// same innermost delegate
assertTrue(stmt1.equals(stmt2));
assertTrue(stmt1.equals(stmt4));
-
+
// innermost delegate itself - bugged behavior?
assertTrue(stmt1.equals(delegateStmt));
-
+
// not same delegate
assertTrue(!stmt1.equals(stmt3));
-
+
// reflexive
assertTrue(stmt1.equals(stmt1));
assertTrue(stmt2.equals(stmt2));
assertTrue(stmt3.equals(stmt3));
}
-
+
public void testCheckOpen() throws Exception {
stmt.checkOpen();
stmt.close();
@@ -102,6 +103,36 @@ public class TestDelegatingStatement ext
fail("Expecting SQLException");
} catch (SQLException ex) {
// expected
- }
+ }
+ }
+
+
+ public void testIsWrapperFor() throws Exception {
+ TesterConnection tstConn = new TesterConnection("test", "test");
+ TesterStatement tstStmt = new TesterStatementNonWrapping(tstConn);
+ DelegatingConnection conn = new DelegatingConnection(tstConn);
+ DelegatingStatement stmt = new DelegatingStatement(conn, tstStmt);
+
+ Class<?> stmtProxyClass = Proxy.getProxyClass(
+ this.getClass().getClassLoader(),
+ Statement.class);
+
+ assertTrue(stmt.isWrapperFor(DelegatingStatement.class));
+ assertTrue(stmt.isWrapperFor(TesterStatement.class));
+ assertFalse(stmt.isWrapperFor(stmtProxyClass));
+
+ stmt.close();
+ }
+
+ private static class TesterStatementNonWrapping extends TesterStatement {
+
+ public TesterStatementNonWrapping(Connection conn) {
+ super(conn);
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
}
}