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,15 +38,17 @@ public class AutoCommitConnectionBroker {
*/ */
public static Connection getConnection() { public static Connection getConnection() {
ConnectionReference connReference = threadLocalConnection.get(); ConnectionReference connReference = threadLocalConnection.get();
if (connReference != null) { try {
connReference.referenceCount++; if (connReference != null && !connReference.connection.isClosed()) {
return connReference.connection; connReference.referenceCount++;
} else { return connReference.connection;
Connection connection = DB.createConnection(true, false, Connection.TRANSACTION_READ_COMMITTED); }
connReference = new ConnectionReference(connection); } catch (SQLException e) {}
threadLocalConnection.set(connReference);
return connection; Connection connection = DB.createConnection(true, false, Connection.TRANSACTION_READ_COMMITTED);
} connReference = new ConnectionReference(connection);
threadLocalConnection.set(connReference);
return connection;
} }
/** /**