From c5fe2c98734a5b64c3f01bd931aff41a0a6017ee Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Mon, 25 Aug 2008 07:46:08 +0000 Subject: [PATCH] MProductPO: BF [ 1874419 ] JDBC Statement not close in a finally block organized imports --- base/src/org/compiere/model/MProductPO.java | 53 +++++---------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/base/src/org/compiere/model/MProductPO.java b/base/src/org/compiere/model/MProductPO.java index ad513c0d87..644bdd9b69 100644 --- a/base/src/org/compiere/model/MProductPO.java +++ b/base/src/org/compiere/model/MProductPO.java @@ -16,10 +16,9 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.sql.ResultSet; +import java.util.List; +import java.util.Properties; /** * Product PO Model @@ -29,6 +28,9 @@ import org.compiere.util.*; */ public class MProductPO extends X_M_Product_PO { + private static final long serialVersionUID = 1L; + + /** * Get current PO of Product * @param ctx context @@ -38,45 +40,14 @@ public class MProductPO extends X_M_Product_PO */ public static MProductPO[] getOfProduct (Properties ctx, int M_Product_ID, String trxName) { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM M_Product_PO " - + "WHERE M_Product_ID=? AND IsActive='Y' " - + "ORDER BY IsCurrentVendor DESC"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt (1, M_Product_ID); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - list.add(new MProductPO (ctx, rs, trxName)); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (SQLException ex) - { - s_log.log(Level.SEVERE, sql, ex); - } - try - { - if (pstmt != null) - pstmt.close (); - } - catch (SQLException ex1) - { - } - pstmt = null; - // - MProductPO[] retValue = new MProductPO[list.size()]; - list.toArray(retValue); - return retValue; + final String whereClause = "M_Product_ID=? AND IsActive=?"; + List list = new Query(ctx, Table_Name, whereClause, trxName) + .setParameters(new Object[]{M_Product_ID, "Y"}) + .setOrderBy("IsCurrentVendor DESC") + .list(); + return list.toArray(new MProductPO[list.size()]); } // getOfProduct - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger(MProductPO.class); - /** * Persistency Constructor * @param ctx context