details: https://code.openbravo.com/erp/devel/pi/rev/205fdc530e40
changeset: 25153:205fdc530e40
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Tue Oct 28 16:14:40 2014 +0100
summary: Fixed issue 27878. Changed DalConnectionProvider so that it won't
leak connections when using a transaction connection:
> - Now getTransactionConnection won't create a new StatelessSession every time
> it is called, because this created a new connection pool, and connections for
> this pool weren't reused. Instead, now the Hibernate ConnectionProvider in
> the DalSessionFactory is exposed, and used, to get a valid connection which
> belongs to the right pool.
- Additionally, now the connections are actually closed when the
releaseCommitConnection or the releaseRollbackConnection methods are used.
diffstat:
src/org/openbravo/dal/core/DalSessionFactory.java | 6 ++++
src/org/openbravo/service/db/DalConnectionProvider.java | 21 +++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)
diffs (76 lines):
diff -r d7cf69d29673 -r 205fdc530e40
src/org/openbravo/dal/core/DalSessionFactory.java
--- a/src/org/openbravo/dal/core/DalSessionFactory.java Tue Oct 28 13:18:33
2014 +0100
+++ b/src/org/openbravo/dal/core/DalSessionFactory.java Tue Oct 28 16:14:40
2014 +0100
@@ -37,7 +37,9 @@
import org.hibernate.StatelessSession;
import org.hibernate.TypeHelper;
import org.hibernate.classic.Session;
+import org.hibernate.connection.ConnectionProvider;
import org.hibernate.engine.FilterDefinition;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.jdbc.BorrowedConnectionProxy;
import org.hibernate.metadata.ClassMetadata;
@@ -304,4 +306,8 @@
public TypeHelper getTypeHelper() {
return delegateSessionFactory.getTypeHelper();
}
+
+ public ConnectionProvider getConnectionProvider() {
+ return ((SessionFactoryImplementor)
delegateSessionFactory).getConnectionProvider();
+ }
}
diff -r d7cf69d29673 -r 205fdc530e40
src/org/openbravo/service/db/DalConnectionProvider.java
--- a/src/org/openbravo/service/db/DalConnectionProvider.java Tue Oct 28
13:18:33 2014 +0100
+++ b/src/org/openbravo/service/db/DalConnectionProvider.java Tue Oct 28
16:14:40 2014 +0100
@@ -27,9 +27,9 @@
import java.sql.Statement;
import java.util.Properties;
-import org.hibernate.StatelessSession;
import org.openbravo.base.session.OBPropertiesProvider;
import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.dal.core.DalSessionFactory;
import org.openbravo.dal.service.OBDal;
import org.openbravo.database.ConnectionProvider;
import org.openbravo.exception.NoConnectionAvailableException;
@@ -95,10 +95,21 @@
return getProperties().getProperty("bbdd.rdbms");
}
+ private boolean closeConnection(Connection conn) {
+ if (conn == null)
+ return false;
+ try {
+ conn.setAutoCommit(true);
+ conn.close();
+ } catch (Exception ex) {
+ return false;
+ }
+ return true;
+ }
+
public Connection getTransactionConnection() throws
NoConnectionAvailableException, SQLException {
- final StatelessSession session =
SessionFactoryController.getInstance().getSessionFactory()
- .openStatelessSession();
- Connection conn = session.connection();
+ Connection conn = ((DalSessionFactory)
SessionFactoryController.getInstance()
+ .getSessionFactory()).getConnectionProvider().getConnection();
if (conn == null) {
throw new NoConnectionAvailableException("Couldn“t get an available
connection");
@@ -111,12 +122,14 @@
if (conn == null)
return;
conn.commit();
+ closeConnection(conn);
}
public void releaseRollbackConnection(Connection conn) throws SQLException {
if (conn == null)
return;
conn.rollback();
+ closeConnection(conn);
}
public PreparedStatement getPreparedStatement(String SQLPreparedStatement)
throws Exception {
------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits