This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 3539add5ee Follow-up to BZ 69206 fix. Change log entry and code
clean-up.
3539add5ee is described below
commit 3539add5eecc84be3a6db46c88b90b6964111136
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Jul 23 10:21:40 2024 +0100
Follow-up to BZ 69206 fix. Change log entry and code clean-up.
---
.../apache/tomcat/jdbc/pool/StatementFacade.java | 56 ++++++-----
.../AbstractCreateStatementInterceptor.java | 93 ++++++++++---------
.../tomcat/jdbc/test/ProxiedResultSetTest.java | 103 ++++++++++-----------
.../tomcat/jdbc/test/ProxiedStatementTest.java | 20 ++--
.../apache/tomcat/jdbc/test/driver/ResultSet.java | 2 -
.../apache/tomcat/jdbc/test/driver/Statement.java | 5 -
webapps/docs/changelog.xml | 11 +++
7 files changed, 148 insertions(+), 142 deletions(-)
diff --git
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
index e30f7d91ec..e9cae3a734 100644
---
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
+++
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
@@ -60,16 +60,16 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
} else if (compare(PREPARE_STATEMENT, name)) {
// prepareStatement
constructor = getConstructor(PREPARE_STATEMENT_IDX,
PreparedStatement.class);
- sql = (String)args[0];
+ sql = (String) args[0];
} else if (compare(PREPARE_CALL, name)) {
// prepareCall
constructor = getConstructor(PREPARE_CALL_IDX,
CallableStatement.class);
- sql = (String)args[0];
+ sql = (String) args[0];
} else {
// do nothing
return statement;
}
- return constructor.newInstance(new Object[] { new
StatementProxy(statement,sql) });
+ return constructor.newInstance(new Object[] { new
StatementProxy(statement, sql) });
} catch (Exception x) {
logger.warn("Unable to create statement proxy.", x);
}
@@ -83,6 +83,7 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
protected boolean closed = false;
protected Object delegate;
protected final String query;
+
public StatementProxy(Object parent, String query) {
this.delegate = parent;
this.query = query;
@@ -90,47 +91,49 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
- if (compare(TOSTRING_VAL,method)) {
+ if (compare(TOSTRING_VAL, method)) {
return toString();
}
if (compare(EQUALS_VAL, method)) {
if (args[0] == null ||
!Proxy.isProxyClass(args[0].getClass())) {
return Boolean.FALSE;
}
- return Boolean.valueOf(
- this.equals(Proxy.getInvocationHandler(args[0])));
+ return
Boolean.valueOf(this.equals(Proxy.getInvocationHandler(args[0])));
}
if (compare(HASHCODE_VAL, method)) {
return Integer.valueOf(this.hashCode());
}
if (compare(CLOSE_VAL, method)) {
if (delegate == null) {
- return null;
+ return null;
}
}
if (compare(ISCLOSED_VAL, method)) {
if (delegate == null) {
- return Boolean.TRUE;
+ return Boolean.TRUE;
}
}
if (delegate == null) {
- throw new SQLException("Statement closed.");
+ throw new SQLException("Statement closed.");
}
if (compare(GET_RESULTSET, method)) {
- return getConstructor(RESULTSET_IDX,
ResultSet.class).newInstance(new ResultSetProxy(method.invoke(delegate,args),
proxy));
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
}
if (compare(GET_GENERATED_KEYS, method)) {
- return getConstructor(RESULTSET_IDX,
ResultSet.class).newInstance(new ResultSetProxy(method.invoke(delegate,args),
proxy));
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
}
if (compare(EXECUTE_QUERY, method)) {
- return getConstructor(RESULTSET_IDX,
ResultSet.class).newInstance(new ResultSetProxy(method.invoke(delegate,args),
proxy));
+ return getConstructor(RESULTSET_IDX, ResultSet.class)
+ .newInstance(new
ResultSetProxy(method.invoke(delegate, args), proxy));
}
- Object result = null;
+ Object result = null;
try {
- //invoke next
- result = method.invoke(delegate,args);
+ // invoke next
+ result = method.invoke(delegate, args);
} catch (Throwable t) {
if (t instanceof InvocationTargetException && t.getCause() !=
null) {
throw t.getCause();
@@ -138,7 +141,7 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
throw t;
}
}
- //perform close cleanup
+ // perform close cleanup
if (compare(CLOSE_VAL, method)) {
delegate = null;
}
@@ -152,7 +155,7 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
@Override
public boolean equals(Object obj) {
- return this==obj;
+ return this == obj;
}
@Override
@@ -181,15 +184,14 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
- if (compare(TOSTRING_VAL,method)) {
+ if (compare(TOSTRING_VAL, method)) {
return toString();
}
if (compare(EQUALS_VAL, method)) {
if (args[0] == null ||
!Proxy.isProxyClass(args[0].getClass())) {
return Boolean.FALSE;
}
- return Boolean.valueOf(
- this.equals(Proxy.getInvocationHandler(args[0])));
+ return
Boolean.valueOf(this.equals(Proxy.getInvocationHandler(args[0])));
}
if (compare(HASHCODE_VAL, method)) {
return Integer.valueOf(this.hashCode());
@@ -214,8 +216,8 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
Object result;
try {
- //invoke next
- result = method.invoke(delegate,args);
+ // invoke next
+ result = method.invoke(delegate, args);
} catch (Throwable t) {
if (t instanceof InvocationTargetException && t.getCause() !=
null) {
throw t.getCause();
@@ -223,7 +225,7 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
throw t;
}
}
- //perform close cleanup
+ // perform close cleanup
if (compare(CLOSE_VAL, method)) {
delegate = null;
}
@@ -237,16 +239,12 @@ public class StatementFacade extends
AbstractCreateStatementInterceptor {
@Override
public boolean equals(Object obj) {
- return this==obj;
+ return this == obj;
}
@Override
public String toString() {
- return ResultSetProxy.class.getName() + "[Proxy=" +
- hashCode() +
- "; Delegate=" +
- delegate +
- ']';
+ return ResultSetProxy.class.getName() + "[Proxy=" + hashCode() +
"; Delegate=" + delegate + ']';
}
}
diff --git
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
index 8ce289b577..c808070682 100644
---
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
+++
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
@@ -28,17 +28,17 @@ import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
import org.apache.tomcat.jdbc.pool.PooledConnection;
/**
- * Abstraction interceptor. This component intercepts all calls to create some
type of SQL statement.
- * By extending this class, one can intercept queries and update statements by
overriding the {@link #createStatement(Object, Method, Object[], Object, long)}
- * method.
+ * Abstraction interceptor. This component intercepts all calls to create some
type of SQL statement. By extending this
+ * class, one can intercept queries and update statements by overriding the
+ * {@link #createStatement(Object, Method, Object[], Object, long)} method.
*/
-public abstract class AbstractCreateStatementInterceptor extends
JdbcInterceptor {
- protected static final String CREATE_STATEMENT = "createStatement";
- protected static final int CREATE_STATEMENT_IDX = 0;
- protected static final String PREPARE_STATEMENT = "prepareStatement";
- protected static final int PREPARE_STATEMENT_IDX = 1;
- protected static final String PREPARE_CALL = "prepareCall";
- protected static final int PREPARE_CALL_IDX = 2;
+public abstract class AbstractCreateStatementInterceptor extends
JdbcInterceptor {
+ protected static final String CREATE_STATEMENT = "createStatement";
+ protected static final int CREATE_STATEMENT_IDX = 0;
+ protected static final String PREPARE_STATEMENT = "prepareStatement";
+ protected static final int PREPARE_STATEMENT_IDX = 1;
+ protected static final String PREPARE_CALL = "prepareCall";
+ protected static final int PREPARE_CALL_IDX = 2;
/**
* {@link Statement#getResultSet()}
@@ -55,30 +55,30 @@ public abstract class AbstractCreateStatementInterceptor
extends JdbcIntercepto
*/
protected static final String GET_STATEMENT = "getStatement";
- protected static final int RESULTSET_IDX = 3;
+ protected static final int RESULTSET_IDX = 3;
- protected static final String[] STATEMENT_TYPES = {CREATE_STATEMENT,
PREPARE_STATEMENT, PREPARE_CALL};
- protected static final int STATEMENT_TYPE_COUNT =
STATEMENT_TYPES.length;
+ protected static final String[] STATEMENT_TYPES = { CREATE_STATEMENT,
PREPARE_STATEMENT, PREPARE_CALL };
+ protected static final int STATEMENT_TYPE_COUNT = STATEMENT_TYPES.length;
- protected static final String EXECUTE = "execute";
- protected static final String EXECUTE_QUERY = "executeQuery";
+ protected static final String EXECUTE = "execute";
+ protected static final String EXECUTE_QUERY = "executeQuery";
protected static final String EXECUTE_UPDATE = "executeUpdate";
- protected static final String EXECUTE_BATCH = "executeBatch";
+ protected static final String EXECUTE_BATCH = "executeBatch";
- protected static final String[] EXECUTE_TYPES = {EXECUTE, EXECUTE_QUERY,
EXECUTE_UPDATE, EXECUTE_BATCH};
+ protected static final String[] EXECUTE_TYPES = { EXECUTE, EXECUTE_QUERY,
EXECUTE_UPDATE, EXECUTE_BATCH };
/**
* the constructors that are used to create statement proxies
*/
protected static final Constructor<?>[] constructors = new
Constructor[STATEMENT_TYPE_COUNT + 1];
- public AbstractCreateStatementInterceptor() {
+ public AbstractCreateStatementInterceptor() {
super();
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
- if (compare(CLOSE_VAL,method)) {
+ if (compare(CLOSE_VAL, method)) {
closeInvoked();
return super.invoke(proxy, method, args);
} else {
@@ -86,11 +86,11 @@ public abstract class AbstractCreateStatementInterceptor
extends JdbcIntercepto
process = isStatement(method, process);
if (process) {
long start = System.currentTimeMillis();
- Object statement = super.invoke(proxy,method,args);
+ Object statement = super.invoke(proxy, method, args);
long delta = System.currentTimeMillis() - start;
- return createStatement(proxy,method,args,statement, delta);
+ return createStatement(proxy, method, args, statement, delta);
} else {
- return super.invoke(proxy,method,args);
+ return super.invoke(proxy, method, args);
}
}
}
@@ -98,18 +98,17 @@ public abstract class AbstractCreateStatementInterceptor
extends JdbcIntercepto
/**
* Creates a constructor for a proxy class, if one doesn't already exist
*
- * @param idx
- * - the index of the constructor
- * @param clazz
- * - the interface that the proxy will implement
+ * @param idx - the index of the constructor
+ * @param clazz - the interface that the proxy will implement
+ *
* @return - returns a constructor used to create new instances
+ *
* @throws NoSuchMethodException Constructor not found
*/
/*
- * Neither the class nor the constructor are exposed outside of jdbc-pool.
- * Given the comments in the jdbc-pool code regarding caching for
- * performance, continue to use Proxy.getProxyClass(). This will need to be
- * revisited if that method is marked for removal.
+ * Neither the class nor the constructor are exposed outside of jdbc-pool.
Given the comments in the jdbc-pool code
+ * regarding caching for performance, continue to use
Proxy.getProxyClass(). This will need to be revisited if that
+ * method is marked for removal.
*/
@SuppressWarnings("deprecation")
protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws
NoSuchMethodException {
@@ -123,14 +122,16 @@ public abstract class AbstractCreateStatementInterceptor
extends JdbcIntercepto
/**
* This method will be invoked after a successful statement creation. This
method can choose to return a wrapper
- * around the statement or return the statement itself.
- * If this method returns a wrapper then it should return a wrapper object
that implements one of the following interfaces.
- * {@link java.sql.Statement}, {@link java.sql.PreparedStatement} or
{@link java.sql.CallableStatement}
- * @param proxy the actual proxy object
- * @param method the method that was called. It will be one of the methods
defined in {@link #STATEMENT_TYPES}
- * @param args the arguments to the method
+ * around the statement or return the statement itself. If this method
returns a wrapper then it should return a
+ * wrapper object that implements one of the following interfaces. {@link
java.sql.Statement},
+ * {@link java.sql.PreparedStatement} or {@link java.sql.CallableStatement}
+ *
+ * @param proxy the actual proxy object
+ * @param method the method that was called. It will be one of the
methods defined in {@link #STATEMENT_TYPES}
+ * @param args the arguments to the method
* @param statement the statement that the underlying connection created
- * @param time Elapsed time
+ * @param time Elapsed time
+ *
* @return a {@link java.sql.Statement} object
*/
public abstract Object createStatement(Object proxy, Method method,
Object[] args, Object statement, long time);
@@ -143,36 +144,42 @@ public abstract class AbstractCreateStatementInterceptor
extends JdbcIntercepto
/**
* Returns true if the method that is being invoked matches one of the
statement types.
*
- * @param method the method being invoked on the proxy
+ * @param method the method being invoked on the proxy
* @param process boolean result used for recursion
+ *
* @return returns true if the method name matched
*/
- protected boolean isStatement(Method method, boolean process){
+ protected boolean isStatement(Method method, boolean process) {
return process(STATEMENT_TYPES, method, process);
}
/**
* Returns true if the method that is being invoked matches one of the
execute types.
*
- * @param method the method being invoked on the proxy
+ * @param method the method being invoked on the proxy
* @param process boolean result used for recursion
+ *
* @return returns true if the method name matched
*/
- protected boolean isExecute(Method method, boolean process){
+ protected boolean isExecute(Method method, boolean process) {
return process(EXECUTE_TYPES, method, process);
}
/*
* Returns true if the method that is being invoked matches one of the
method names passed in
+ *
* @param names list of method names that we want to intercept
+ *
* @param method the method being invoked on the proxy
+ *
* @param process boolean result used for recursion
+ *
* @return returns true if the method name matched
*/
protected boolean process(String[] names, Method method, boolean process) {
final String name = method.getName();
- for (int i=0; (!process) && i<names.length; i++) {
- process = compare(names[i],name);
+ for (int i = 0; (!process) && i < names.length; i++) {
+ process = compare(names[i], name);
}
return process;
}
diff --git
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedResultSetTest.java
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedResultSetTest.java
index ae4d951f2c..17699c9886 100644
---
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedResultSetTest.java
+++
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedResultSetTest.java
@@ -16,19 +16,16 @@
*/
package org.apache.tomcat.jdbc.test;
-import org.apache.tomcat.jdbc.test.driver.Driver;
-import org.junit.Test;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.tomcat.jdbc.test.driver.Driver;
public class ProxiedResultSetTest extends DefaultTestCase {
@@ -37,9 +34,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("");
- ResultSet resultSet = statement.executeQuery()) {
- assertEquals(statement, resultSet.getStatement());
+ PreparedStatement statement = con.prepareStatement("");
+ ResultSet resultSet = statement.executeQuery()) {
+ Assert.assertEquals(statement, resultSet.getStatement());
}
}
@@ -48,9 +45,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- ResultSet resultSet = statement.getGeneratedKeys()) {
- assertEquals(statement, resultSet.getStatement());
+ Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ ResultSet resultSet = statement.getGeneratedKeys()) {
+ Assert.assertEquals(statement, resultSet.getStatement());
}
}
@@ -59,9 +56,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.executeQuery("")) {
- assertEquals(statement, resultSet.getStatement());
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.executeQuery("")) {
+ Assert.assertEquals(statement, resultSet.getStatement());
}
}
@@ -70,9 +67,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.getResultSet()) {
- assertEquals(statement, resultSet.getStatement());
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.getResultSet()) {
+ Assert.assertEquals(statement, resultSet.getStatement());
}
}
@@ -81,11 +78,11 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.getResultSet()) {
- assertFalse(resultSet.isClosed());
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.getResultSet()) {
+ Assert.assertFalse(resultSet.isClosed());
resultSet.close();
- assertTrue(resultSet.isClosed());
+ Assert.assertTrue(resultSet.isClosed());
}
}
@@ -94,11 +91,11 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.getResultSet()) {
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.getResultSet()) {
int hashcode = resultSet.hashCode();
resultSet.close();
- assertEquals(hashcode, resultSet.hashCode());
+ Assert.assertEquals(hashcode, resultSet.hashCode());
}
}
@@ -107,13 +104,13 @@ public class ProxiedResultSetTest extends DefaultTestCase
{
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.getResultSet()) {
- assertNotEquals(resultSet, "");
- assertEquals(resultSet, resultSet);
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.getResultSet()) {
+ Assert.assertNotEquals(resultSet, "");
+ Assert.assertEquals(resultSet, resultSet);
resultSet.close();
- assertNotEquals(resultSet, "");
- assertEquals(resultSet, resultSet);
+ Assert.assertNotEquals(resultSet, "");
+ Assert.assertEquals(resultSet, resultSet);
}
}
@@ -123,12 +120,12 @@ public class ProxiedResultSetTest extends DefaultTestCase
{
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = datasource.getConnection();
- Statement statement = con.createStatement();
- ResultSet resultSet = statement.getResultSet()) {
+ Statement statement = con.createStatement();
+ ResultSet resultSet = statement.getResultSet()) {
String toStringResult = resultSet.toString();
resultSet.close();
// the delegate will change, so we can't compare the whole string
- assertEquals(toStringResult.substring(0, 50),
resultSet.toString().substring(0, 50));
+ Assert.assertEquals(toStringResult.substring(0, 50),
resultSet.toString().substring(0, 50));
}
}
@@ -138,9 +135,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql");
- ResultSet resultSet = statement.executeQuery()) {
- assertNotEquals(resultSet, null);
+ PreparedStatement statement = con.prepareStatement("sql");
+ ResultSet resultSet = statement.executeQuery()) {
+ Assert.assertNotEquals(resultSet, null);
}
}
@@ -149,9 +146,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql");
- ResultSet resultSet = statement.executeQuery()) {
- assertNotEquals(resultSet, "");
+ PreparedStatement statement = con.prepareStatement("sql");
+ ResultSet resultSet = statement.executeQuery()) {
+ Assert.assertNotEquals(resultSet, "");
}
}
@@ -160,9 +157,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql");
- ResultSet resultSet = statement.executeQuery()) {
- assertNotEquals(resultSet, new
org.apache.tomcat.jdbc.test.driver.ResultSet(statement));
+ PreparedStatement statement = con.prepareStatement("sql");
+ ResultSet resultSet = statement.executeQuery()) {
+ Assert.assertNotEquals(resultSet, new
org.apache.tomcat.jdbc.test.driver.ResultSet(statement));
}
}
@@ -171,9 +168,9 @@ public class ProxiedResultSetTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql");
- ResultSet resultSet = statement.executeQuery()) {
- assertEquals(resultSet, resultSet);
+ PreparedStatement statement = con.prepareStatement("sql");
+ ResultSet resultSet = statement.executeQuery()) {
+ Assert.assertEquals(resultSet, resultSet);
}
}
@@ -182,12 +179,12 @@ public class ProxiedResultSetTest extends DefaultTestCase
{
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql");
- ResultSet resultSet = statement.executeQuery();
- Connection con2 = this.datasource.getConnection();
- PreparedStatement statement2 = con2.prepareStatement("sql");
- ResultSet resultSet2 = statement2.executeQuery()) {
- assertNotEquals(resultSet, resultSet2);
+ PreparedStatement statement = con.prepareStatement("sql");
+ ResultSet resultSet = statement.executeQuery();
+ Connection con2 = this.datasource.getConnection();
+ PreparedStatement statement2 = con2.prepareStatement("sql");
+ ResultSet resultSet2 = statement2.executeQuery()) {
+ Assert.assertNotEquals(resultSet, resultSet2);
}
}
}
diff --git
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedStatementTest.java
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedStatementTest.java
index c7b16b3125..2c76115c06 100644
---
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedStatementTest.java
+++
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ProxiedStatementTest.java
@@ -16,16 +16,16 @@
*/
package org.apache.tomcat.jdbc.test;
-import org.apache.tomcat.jdbc.test.driver.Driver;
-import org.junit.Test;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import static org.junit.Assert.assertNotEquals;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.tomcat.jdbc.test.driver.Driver;
public class ProxiedStatementTest extends DefaultTestCase {
@@ -34,8 +34,8 @@ public class ProxiedStatementTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- PreparedStatement statement = con.prepareStatement("sql")) {
- assertNotEquals(statement, null);
+ PreparedStatement statement = con.prepareStatement("sql")) {
+ Assert.assertNotEquals(statement, null);
}
}
@@ -44,8 +44,8 @@ public class ProxiedStatementTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
- assertNotEquals(statement, "");
+ Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
+ Assert.assertNotEquals(statement, "");
}
}
@@ -54,8 +54,8 @@ public class ProxiedStatementTest extends DefaultTestCase {
this.datasource.setDriverClassName(Driver.class.getName());
this.datasource.setUrl("jdbc:tomcat:test");
try (Connection con = this.datasource.getConnection();
- Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
- assertNotEquals(statement, new
org.apache.tomcat.jdbc.test.driver.Statement());
+ Statement statement =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
+ Assert.assertNotEquals(statement, new
org.apache.tomcat.jdbc.test.driver.Statement());
}
}
}
diff --git
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/ResultSet.java
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/ResultSet.java
index 86ce153b7a..fb048ac30d 100644
---
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/ResultSet.java
+++
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/ResultSet.java
@@ -442,7 +442,6 @@ public class ResultSet implements java.sql.ResultSet {
@Override
public Statement getStatement() throws SQLException {
- // TODO Auto-generated method stub
return owner;
}
@@ -602,7 +601,6 @@ public class ResultSet implements java.sql.ResultSet {
public boolean next() throws SQLException {
boolean next = hasNext;
hasNext = false;
- // TODO Auto-generated method stub
return next;
}
diff --git
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Statement.java
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Statement.java
index 1d48adcc7e..d5a8e8ead6 100644
---
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Statement.java
+++
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Statement.java
@@ -728,7 +728,6 @@ public class Statement implements CallableStatement {
@Override
public ResultSet executeQuery() throws SQLException {
- // TODO Auto-generated method stub
return new org.apache.tomcat.jdbc.test.driver.ResultSet(this);
}
@@ -1100,7 +1099,6 @@ public class Statement implements CallableStatement {
@Override
public ResultSet executeQuery(String sql) throws SQLException {
- // TODO Auto-generated method stub
return new org.apache.tomcat.jdbc.test.driver.ResultSet(this);
}
@@ -1148,7 +1146,6 @@ public class Statement implements CallableStatement {
@Override
public ResultSet getGeneratedKeys() throws SQLException {
- // TODO Auto-generated method stub
return new org.apache.tomcat.jdbc.test.driver.ResultSet(this);
}
@@ -1178,13 +1175,11 @@ public class Statement implements CallableStatement {
@Override
public int getQueryTimeout() throws SQLException {
- // TODO Auto-generated method stub
return timeout;
}
@Override
public ResultSet getResultSet() throws SQLException {
- // TODO Auto-generated method stub
return new org.apache.tomcat.jdbc.test.driver.ResultSet(this);
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f36677baf7..54896d2474 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -143,6 +143,17 @@
</update>
</changelog>
</subsection>
+ <subsection name="jdbc-pool">
+ <changelog>
+ <fix>
+ <bug>69206</bug>: Ensure statements returned from
<code>Statement</code>
+ methods <code>executeQuery()</code>, <code>getResultSet()</code> and
+ <code>getGeneratedKeys()</code> are correctly wrapped before being
+ returned to the caller. Based on pull request <pr>742</pr> provided by
+ Michael Clarke.
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Other">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]