IDEMPIERE-1235 Add API to support the sharing of non-transactional connection within a single execution thread. Added simple sanity check ( isclosed ) for connection.

This commit is contained in:
Heng Sin Low 2013-08-05 20:48:09 +08:00
parent 40e569e0cb
commit 25d58a3f8d
1 changed files with 11 additions and 9 deletions

View File

@ -38,16 +38,18 @@ public class AutoCommitConnectionBroker {
*/ */
public static Connection getConnection() { public static Connection getConnection() {
ConnectionReference connReference = threadLocalConnection.get(); ConnectionReference connReference = threadLocalConnection.get();
if (connReference != null) { try {
if (connReference != null && !connReference.connection.isClosed()) {
connReference.referenceCount++; connReference.referenceCount++;
return connReference.connection; return connReference.connection;
} else { }
} catch (SQLException e) {}
Connection connection = DB.createConnection(true, false, Connection.TRANSACTION_READ_COMMITTED); Connection connection = DB.createConnection(true, false, Connection.TRANSACTION_READ_COMMITTED);
connReference = new ConnectionReference(connection); connReference = new ConnectionReference(connection);
threadLocalConnection.set(connReference); threadLocalConnection.set(connReference);
return connection; return connection;
} }
}
/** /**
* Release connection. The connection goes back to pool if reference count is zero. * Release connection. The connection goes back to pool if reference count is zero.