Author: jleroux
Date: Fri Jun 17 11:51:13 2016
New Revision: 1748837
URL: http://svn.apache.org/viewvc?rev=1748837&view=rev
Log:
A patch from Gareth Carter for "connection pooling not working"
https://issues.apache.org/jira/browse/OFBIZ-7346
Connection pooling does not seem to work. Connections are created fine but as
the close() method is called (outside of transaction) or the transaction is
committed the connections are closed to the db server and not returned to the
pool.
I believe the issue is with org.apache.commons.dbcp2.PoolableConnectionFactory
passivateObject method. This will call rollback() when rollbackOnReturn is set
to true even if the transaction is committed. This is because any connection
wrappers extending org.apache.commons.dbcp2.DelegatingConnection cache
autoCommit status. At some point, this cached autoCommit is different from the
underlying connection autoCommit. The rollback() method will throw an exception
and the connection is destroyed rather than put back to the pool
Environment this has been tested on:
ofbiz: rev 1725574 and latest trunk (as of 2016-06-14)
db: postgresql 9.1
jdbc driver: postgresql-9.3-1101.jdbc4
os: linux and windows
jleroux: this issue doest not exist with Derby, it's a matter of driver (DBMS
actually) see Derby vs Postgres
https://db.apache.org/derby/docs/10.9/devguide/cdevconcepts29416.html
https://www.postgresql.org/docs/9.1/static/ecpg-sql-set-autocommit.html
Another solution would be to force Postgres to autocommit but I'd not do that,
better not change this DBMS dependent behaviour.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1748837&r1=1748836&r2=1748837&view=diff
==============================================================================
---
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
(original)
+++
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
Fri Jun 17 11:51:13 2016
@@ -109,6 +109,8 @@ public class DBCPConnectionFactory imple
PoolableConnectionFactory factory = new
PoolableManagedConnectionFactory(xacf, null);
factory.setValidationQuery(jdbcElement.getPoolJdbcTestStmt());
factory.setDefaultReadOnly(false);
+ factory.setRollbackOnReturn(false);
+ factory.setEnableAutoCommitOnReturn(false);
String transIso = jdbcElement.getIsolationLevel();
if (!transIso.isEmpty()) {
if ("Serializable".equals(transIso)) {