From 0c2cb2bc5476162d1d4442fb3d73d7cd7246ffcf Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 26 Sep 2007 09:09:13 +0000 Subject: [PATCH] [ 1801842 ] DB connection fix & improvements for concurrent threads. - Integrating contribution from the Posterita Team. --- .../ejb/org/compiere/session/ServerBean.java | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/serverRoot/src/main/ejb/org/compiere/session/ServerBean.java b/serverRoot/src/main/ejb/org/compiere/session/ServerBean.java index bd5526429a..6efe0f7e25 100644 --- a/serverRoot/src/main/ejb/org/compiere/session/ServerBean.java +++ b/serverRoot/src/main/ejb/org/compiere/session/ServerBean.java @@ -143,7 +143,23 @@ public class ServerBean implements SessionBean log.finer("[" + m_no + "]"); m_stmt_rowSetCount++; CPreparedStatement pstmt = new CPreparedStatement(info); - return pstmt.getRowSet(); + RowSet rowset = null; + try + { + rowset = pstmt.getRowSet(); + } + finally + { + try + { + pstmt.close(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, "Could not close prepared statement", ex); + } + } + return rowset; } // pstmt_getRowSet /** @@ -162,7 +178,23 @@ public class ServerBean implements SessionBean log.finer("[" + m_no + "]"); m_stmt_rowSetCount++; CStatement stmt = new CStatement(info); - return stmt.getRowSet(); + RowSet rowset = null; + try + { + rowset = stmt.getRowSet(); + } + finally + { + try + { + stmt.close(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, "Could not close statement", ex); + } + } + return rowset; } // stmt_getRowSet /** @@ -180,13 +212,36 @@ public class ServerBean implements SessionBean //log.finer(m_Context.getCallerPrincipal().getName() + " - " + info.getSql()); log.finer("[" + m_no + "]"); m_stmt_updateCount++; + CStatement stmt = null; + int retVal = -1; if (info.getParameterCount() == 0) { - CStatement stmt = new CStatement(info); - return stmt.remote_executeUpdate(); + stmt = new CStatement(info); } - CPreparedStatement pstmt = new CPreparedStatement(info); - return pstmt.remote_executeUpdate(); + else + { + stmt = new CPreparedStatement(info); + } + + try + { + retVal = stmt.remote_executeUpdate(); + } + finally + { + if (stmt != null) + { + try + { + stmt.close(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, "Could not close statement", ex); + } + } + } + return retVal; } // stmt_executeUpdate /*************************************************************************