From 2c4be7b8bc4d4f8c1a0da899d73cf74df35f1870 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Thu, 24 Jan 2008 08:38:48 +0000 Subject: [PATCH] BF [ 1874419 ] JDBC Statement not close in a finally block - only for SvrProcess BF [ 1877935 ] SvrProcess.process should catch all throwables FR [ 1877937 ] SvrProcess: added commitEx method * fixed minor java 5 generics warning --- base/src/org/compiere/process/SvrProcess.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/base/src/org/compiere/process/SvrProcess.java b/base/src/org/compiere/process/SvrProcess.java index 0b285215f8..2a40056b1d 100644 --- a/base/src/org/compiere/process/SvrProcess.java +++ b/base/src/org/compiere/process/SvrProcess.java @@ -26,14 +26,14 @@ import org.compiere.util.*; /** * Server Process Template - *

- * Change log: - *

* * @author Jorg Janke * @version $Id: SvrProcess.java,v 1.4 2006/08/10 01:00:44 jjanke Exp $ + * + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *
  • FR [ 1646891 ] SvrProcess - post process support + *
  • BF [ 1877935 ] SvrProcess.process should catch all throwables + *
  • FR [ 1877937 ] SvrProcess: added commitEx method */ public abstract class SvrProcess implements ProcessCall { @@ -132,7 +132,7 @@ public abstract class SvrProcess implements ProcessCall prepare(); msg = doIt(); } - catch (Exception e) + catch (Throwable e) { msg = e.getLocalizedMessage(); if (msg == null) @@ -210,6 +210,16 @@ public abstract class SvrProcess implements ProcessCall m_trx.commit(); } // commit + /** + * Commit and throw exception if error + * @throws SQLException on commit error + */ + protected void commitEx() throws SQLException + { + if (m_trx != null) + m_trx.commit(true); + } + /** * Rollback */ @@ -329,23 +339,27 @@ public abstract class SvrProcess implements ProcessCall if (m_pi.getAD_User_ID() == null || m_pi.getAD_Client_ID() == null) { String sql = "SELECT AD_User_ID, AD_Client_ID FROM AD_PInstance WHERE AD_PInstance_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName()); + pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, m_pi.getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_pi.setAD_User_ID (rs.getInt (1)); m_pi.setAD_Client_ID (rs.getInt(2)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } } if (m_pi.getAD_User_ID() == null) return 0; @@ -419,7 +433,7 @@ public abstract class SvrProcess implements ProcessCall { try { - Class clazz = Class.forName(className); + Class clazz = Class.forName(className); Object object = clazz.newInstance(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++)