[
https://issues.apache.org/jira/browse/DBCP-566?focusedWorklogId=454661&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-454661
]
ASF GitHub Bot logged work on DBCP-566:
---------------------------------------
Author: ASF GitHub Bot
Created on: 05/Jul/20 23:10
Start Date: 05/Jul/20 23:10
Worklog Time Spent: 10m
Work Description: psteitz commented on a change in pull request #42:
URL: https://github.com/apache/commons-dbcp/pull/42#discussion_r449928885
##########
File path:
src/test/java/org/apache/commons/dbcp2/TestPStmtPoolingBasicDataSource.java
##########
@@ -233,6 +233,52 @@ public void testPStmtPoolingAcrossClose() throws Exception
{
assertSame(inner1, inner2);
}
+ @Test
+ public void testPStmtPoolingAcrossCloseWithClearOnReturn() throws
Exception {
+ ds.setMaxTotal(1); // only one connection in pool needed
+ ds.setMaxIdle(1);
+ ds.setClearStatementPoolOnReturn(true);
+ ds.setAccessToUnderlyingConnectionAllowed(true);
+ final Connection conn1 = getConnection();
+ assertNotNull(conn1);
+ assertEquals(1, ds.getNumActive());
+ assertEquals(0, ds.getNumIdle());
+
+ final PreparedStatement stmt1 = conn1.prepareStatement("select 'a'
from dual");
+ assertNotNull(stmt1);
+ final Statement inner1 = ((DelegatingPreparedStatement)
stmt1).getInnermostDelegate();
+ assertNotNull(inner1);
+ stmt1.close();
+
+ final PreparedStatement stmt2 = conn1.prepareStatement("select 'a'
from dual");
+ assertNotNull(stmt2);
+ final Statement inner2 = ((DelegatingPreparedStatement)
stmt2).getInnermostDelegate();
+ assertNotNull(inner2);
+ assertSame(inner1, inner2); // from the same connection the statement
must be pooled
+ stmt2.close();
+
+ conn1.close();
+ assertTrue(inner1.isClosed());
+ assertTrue(inner2.isClosed());
+
+ assertEquals(0, ds.getNumActive());
+ assertEquals(1, ds.getNumIdle());
+
+ final Connection conn2 = getConnection();
+ assertNotNull(conn2);
+ assertEquals(1, ds.getNumActive());
+ assertEquals(0, ds.getNumIdle());
+
+ final PreparedStatement stmt3 = conn2.prepareStatement("select 'a'
from dual");
+ assertNotNull(stmt3);
+ final Statement inner3 = ((DelegatingPreparedStatement)
stmt3).getInnermostDelegate();
+ assertNotNull(inner3);
+
+ assertNotSame(inner1, inner3); // when aquiring the connection the
next time, statement must be new
+
Review comment:
Nice job finding a way to test if the pool is cleared. I would be +1 to
exposing a property on PoolingConnection that returns the current size of the
statement pool or even a getter for the pool itself (like BDS does). Client
code (and tests) would have to cast to PoolingConnection to get it, but I could
see how it might be useful. With that added, we could also beef up statement
pooling tests like this without reflection hacks.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 454661)
Time Spent: 1h (was: 50m)
> Clear PreparedStatement pool when connection is returned to the pool
> --------------------------------------------------------------------
>
> Key: DBCP-566
> URL: https://issues.apache.org/jira/browse/DBCP-566
> Project: Commons DBCP
> Issue Type: New Feature
> Reporter: Robert Paschek
> Priority: Major
> Time Spent: 1h
> Remaining Estimate: 0h
>
> With the current configuration option poolPreparedStatements true the
> statements are held open for the lifetime of the connection. This results in
> cursors being open and locks in the database for a long time, which could
> cause problems with administrative tasks in the database.
> There should be an additional configuration clearStatementPoolOnReturn. When
> set to true, the pool will be cleared and the statements closed when the
> connection is returned to the pool. Default can be false to retain the
> current behaviour.
> With this the application can still benefit from the Statement-cache in mass
> operations.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)