From 64021ec448b4dc23ec5c5991f4b1b6a381606238 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 7 Dec 2009 09:33:29 +0000 Subject: [PATCH] https://sourceforge.net/tracker/?func=detail&aid=2909908&group_id=176962&atid=879332 - trx connection management enhancement --- base/src/org/compiere/util/Trx.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/base/src/org/compiere/util/Trx.java b/base/src/org/compiere/util/Trx.java index 566db8a6d6..8505a70a3f 100644 --- a/base/src/org/compiere/util/Trx.java +++ b/base/src/org/compiere/util/Trx.java @@ -138,15 +138,37 @@ public class Trx implements VetoableChangeListener private long m_startTime; /** - * Get Connection - * @return connection + * Get connection + * @return connection */ public Connection getConnection() + { + return getConnection(true); + } + + /** + * Get Connection + * @param createNew if true, create new connection if the trx does not have one created yet + * @return connection + */ + public Connection getConnection(boolean createNew) { log.log(Level.ALL, "Active=" + isActive() + ", Connection=" + m_connection); if (m_connection == null) // get new Connection - setConnection(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); + { + if (createNew) + { + if (s_cache == null || !s_cache.containsKey(m_trxName)) + { + new Exception("Illegal to getConnection for Trx that is not register.").printStackTrace(); + return null; + } + setConnection(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); + } + else + return null; + } if (!isActive()) start(); return m_connection; @@ -444,6 +466,7 @@ public class Trx implements VetoableChangeListener throws PropertyVetoException { log.info(evt.toString()); + throw new PropertyVetoException("Skip reset for trx entries cache", evt); } // vetoableChange /**