diff --git a/org.adempiere.base/src/org/compiere/util/DB.java b/org.adempiere.base/src/org/compiere/util/DB.java index 5ea1e72ae8..bed4ba5b29 100644 --- a/org.adempiere.base/src/org/compiere/util/DB.java +++ b/org.adempiere.base/src/org/compiere/util/DB.java @@ -2399,8 +2399,10 @@ public final class DB private static void verifyTrx(String trxName, String sql) { if (trxName != null && Trx.get(trxName, false) == null) { // Using a trx that was previously closed or never opened - // this is equivalent to commit without trx (autocommit) - log.severe("Transaction closed or never opened ("+trxName+") => this is equivalent to commit without trx (autocommit) --> " + sql); // severe? + // probably timed out - throw Exception (IDEMPIERE-644) + String msg = "Transaction closed or never opened ("+trxName+") => (maybe timed out)"; + log.severe(msg); // severe + throw new DBException(msg); } } diff --git a/org.adempiere.base/src/org/compiere/util/Trx.java b/org.adempiere.base/src/org/compiere/util/Trx.java index aa6cb8e03c..3d83006b43 100644 --- a/org.adempiere.base/src/org/compiere/util/Trx.java +++ b/org.adempiere.base/src/org/compiere/util/Trx.java @@ -405,6 +405,36 @@ public class Trx } + /** + * Rollback and End Transaction, Close Connection and Throws an Exception + * @return true if success + */ + public synchronized boolean rollbackAndCloseOnTimeout() { + s_cache.remove(getTrxName()); + + //local + if (m_connection == null) + return true; + + if (isActive()) + rollback(); + + // Close Connection + try + { + m_connection.close(); + m_connection = null; + m_active = false; + fireAfterCloseEvent(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, m_trxName, e); + } + log.config(m_trxName); + return true; + } + /** * End Transaction and Close Connection * @return true if success @@ -651,7 +681,7 @@ public class Trx if (since > trxs[i].getTimeout() * 1000) { trxs[i].log.log(Level.WARNING, "Transaction timeout. Name="+trxs[i].getTrxName() + ", timeout(sec)="+(since / 1000)); - trxs[i].close(); + trxs[i].rollbackAndCloseOnTimeout(); } } }