From 2cd9802c0f998d8efaca86c10d53aeb5eb3c877c Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Wed, 6 Feb 2008 07:55:53 +0000 Subject: [PATCH] BF [ 1874419 ] JDBC Statement not close in a finally block - fixed for org.compiere.model.MGoal --- base/src/org/compiere/model/MGoal.java | 68 ++++++++------------------ 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/base/src/org/compiere/model/MGoal.java b/base/src/org/compiere/model/MGoal.java index 1af2df7628..8c659ccba9 100644 --- a/base/src/org/compiere/model/MGoal.java +++ b/base/src/org/compiere/model/MGoal.java @@ -52,35 +52,28 @@ public class MGoal extends X_PA_Goal + "WHERE g.AD_User_ID=ur.AD_User_ID AND g.AD_Role_ID=ur.AD_Role_ID AND ur.IsActive='Y')) " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, Env.getAD_Client_ID(ctx)); pstmt.setInt (2, AD_User_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MGoal goal = new MGoal (ctx, rs, null); goal.updateGoal(false); list.add (goal); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } MGoal[] retValue = new MGoal[list.size ()]; list.toArray (retValue); @@ -100,33 +93,26 @@ public class MGoal extends X_PA_Goal sql = MRole.getDefault(ctx, false).addAccessSQL(sql, "PA_Goal", false, true); // RW to restrict Access PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MGoal goal = new MGoal (ctx, rs, null); goal.updateGoal(false); list.add (goal); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } MGoal[] retValue = new MGoal[list.size ()]; list.toArray (retValue); @@ -165,30 +151,23 @@ public class MGoal extends X_PA_Goal String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' AND PA_Measure_ID=? " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, PA_Measure_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MGoal (ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } MGoal[] retValue = new MGoal[list.size ()]; list.toArray (retValue); @@ -347,30 +326,23 @@ public class MGoal extends X_PA_Goal + "WHERE PA_Goal_ID=? AND IsActive='Y' " + "ORDER BY Org_ID, C_BPartner_ID, M_Product_ID"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getPA_Goal_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MGoalRestriction (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } // m_restrictions = new MGoalRestriction[list.size ()];