You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2014/02/04 00:18:24 UTC
svn commit: r1564125 - in
/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src: changes/
main/java/org/apache/commons/dbcp/ test/java/org/apache/commons/dbcp/
Author: markt
Date: Mon Feb 3 23:18:24 2014
New Revision: 1564125
URL: http://svn.apache.org/r1564125
Log:
Fix DBCP-372
Using batchUpdate() should not invalidate the PreparedStatement when it is returned to the pool.
Modified:
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/PoolablePreparedStatement.java
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TestPStmtPooling.java
commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TesterStatement.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=1564125&r1=1564124&r2=1564125&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 Feb 3 23:18:24 2014
@@ -99,6 +99,10 @@ The <action> type attribute can be add,u
made to commit the current transaction for a connection when no
transaction has been started.
</action>
+ <action dev="markt" issue="DBCP-372" type="fix">
+ Using batchUpdate() should not invalidate the PreparedStatement when it
+ is returned to the pool.
+ </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/main/java/org/apache/commons/dbcp/PoolablePreparedStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/PoolablePreparedStatement.java?rev=1564125&r1=1564124&r2=1564125&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/PoolablePreparedStatement.java (original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/PoolablePreparedStatement.java Mon Feb 3 23:18:24 2014
@@ -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.
@@ -63,7 +63,7 @@ public class PoolablePreparedStatement e
_pool = pool;
_key = key;
- // Remove from trace now because this statement will be
+ // Remove from trace now because this statement will be
// added by the activate method.
if(_conn != null) {
_conn.removeTrace(this);
@@ -103,7 +103,7 @@ public class PoolablePreparedStatement e
}
}
}
-
+
protected void activate() throws SQLException{
_closed = false;
if(_conn != null) {
@@ -111,14 +111,19 @@ public class PoolablePreparedStatement e
}
super.activate();
}
-
+
protected void passivate() throws SQLException {
+ // DBCP-372. clearBatch with throw an exception if called when the
+ // connection is marked as closed.
+ if (batchAdded) {
+ clearBatch();
+ }
_closed = true;
if(_conn != null) {
_conn.removeTrace(this);
}
- // The JDBC spec requires that a statment close any open
+ // The JDBC spec requires that a statement close any open
// ResultSet's when it is closed.
// FIXME The PreparedStatement we're wrapping should handle this for us.
// See bug 17301 for what could happen when ResultSets are closed twice.
@@ -130,10 +135,7 @@ public class PoolablePreparedStatement e
}
clearTrace();
}
- if (batchAdded) {
- clearBatch();
- }
-
+
super.passivate();
}
Modified: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TestPStmtPooling.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TestPStmtPooling.java?rev=1564125&r1=1564124&r2=1564125&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TestPStmtPooling.java (original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TestPStmtPooling.java Mon Feb 3 23:18:24 2014
@@ -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.
@@ -18,6 +18,8 @@
package org.apache.commons.dbcp;
import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.SQLException;
@@ -34,7 +36,7 @@ import org.apache.commons.pool.impl.Gene
/**
* TestSuite for BasicDataSource with prepared statement pooling enabled
- *
+ *
* @author Dirk Verbeeck
* @version $Revision$ $Date$
*/
@@ -69,7 +71,7 @@ public class TestPStmtPooling extends Te
stmt2.close();
assertSame(ustmt1, ustmt2);
}
-
+
public void testCallableStatementPooling() throws Exception {
new TesterDriver();
ConnectionFactory connFactory = new DriverManagerConnectionFactory(
@@ -105,7 +107,7 @@ public class TestPStmtPooling extends Te
assertNotSame(ustmt1, ustmt3);
assertNotSame(ustmt3, ucstmt1);
}
-
+
public void testClosePool() throws Exception {
new TesterDriver();
ConnectionFactory connFactory = new DriverManagerConnectionFactory(
@@ -122,9 +124,9 @@ public class TestPStmtPooling extends Te
Connection conn = ds.getConnection();
conn.prepareStatement("select 1 from dual");
-
+
Connection poolableConnection = ((DelegatingConnection) conn).getDelegate();
- Connection poolingConnection =
+ Connection poolingConnection =
((DelegatingConnection) poolableConnection).getDelegate();
poolingConnection.close();
try {
@@ -132,6 +134,30 @@ public class TestPStmtPooling extends Te
fail("Expecting SQLException");
} catch (SQLException ex) {
assertTrue(ex.getMessage().endsWith("invalid PoolingConnection."));
- }
+ }
+ }
+
+ public void testBatchUpdate() throws Exception {
+ @SuppressWarnings("unused") // Ensure TesterDriver is registered
+ Driver d = new TesterDriver();
+ ConnectionFactory connFactory = new DriverManagerConnectionFactory(
+ "jdbc:apache:commons:testdriver","u1","p1");
+
+ ObjectPool connPool = new GenericObjectPool();
+ KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);
+
+ new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
+ null, false, true);
+
+ DataSource ds = new PoolingDataSource(connPool);
+
+ Connection conn = ds.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select 1 from dual");
+ Statement inner = ((DelegatingPreparedStatement) ps).getInnermostDelegate();
+ // Check DBCP-372
+ ps.addBatch();
+ ps.close();
+ conn.close();
+ assertFalse(inner.isClosed());
}
}
Modified: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TesterStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TesterStatement.java?rev=1564125&r1=1564124&r2=1564125&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TesterStatement.java (original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/TesterStatement.java Mon Feb 3 23:18:24 2014
@@ -285,7 +285,7 @@ public class TesterStatement implements
}
public boolean isClosed() throws SQLException {
- throw new SQLException("Not implemented.");
+ return !_open;
}
public void setPoolable(boolean poolable) throws SQLException {