From d28e629e750bf1737bf3da92afbb6ef3087df06e Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Tue, 4 Nov 2008 09:08:25 +0000 Subject: [PATCH] FR: [ 2214883 ] Remove SQL code and Replace for Query thanks TRIFON --- base/src/org/compiere/model/MContainer.java | 142 ++++---------------- 1 file changed, 26 insertions(+), 116 deletions(-) diff --git a/base/src/org/compiere/model/MContainer.java b/base/src/org/compiere/model/MContainer.java index e28e74462b..d8e9b37628 100644 --- a/base/src/org/compiere/model/MContainer.java +++ b/base/src/org/compiere/model/MContainer.java @@ -25,7 +25,8 @@ import org.compiere.util.*; * Container Model * * @author Yves Sandfort - * @version $Id: MContainer.java,v 1.20 2006/09/05 23:22:53 comdivision Exp $ + * @version $Id: MContainer.java,v 1.20 2006/09/05 23:22:53 comdivision Exp $ + * FR: [ 2214883 ] Remove SQL code and Replace for Query - red1/trifon */ public class MContainer extends X_CM_Container { @@ -42,35 +43,12 @@ public class MContainer extends X_CM_Container */ public static MContainer get(Properties ctx, String relURL, int CM_WebProject_Id, String trxName) { MContainer thisContainer = null; - String sql = "SELECT * FROM CM_Container WHERE (RelativeURL LIKE ? OR RelativeURL LIKE ?) AND CM_WebProject_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, trxName); - pstmt.setString (1,relURL); - pstmt.setString (2,relURL+"/"); - pstmt.setInt(3, CM_WebProject_Id); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - thisContainer = (new MContainer(ctx, rs, trxName)); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - s_log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1/trifon + String whereClause = "(RelativeURL LIKE ? OR RelativeURL LIKE ?) AND CM_WebProject_ID=?"; + thisContainer = new Query(ctx, MContainer.Table_Name, whereClause, trxName) + .setParameters(new Object[]{relURL, relURL+"/",CM_WebProject_Id}) + .first(); + return thisContainer; } @@ -85,34 +63,12 @@ public class MContainer extends X_CM_Container */ public static MContainer get(Properties ctx, int CM_Container_ID, int CM_WebProject_Id, String trxName) { MContainer thisContainer = null; - String sql = "SELECT * FROM CM_Container WHERE CM_Container_ID=? AND CM_WebProject_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, trxName); - pstmt.setInt(1, CM_Container_ID); - pstmt.setInt(2, CM_WebProject_Id); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - thisContainer = (new MContainer(ctx, rs, trxName)); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - s_log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1/trifon + String whereClause = "CM_Container_ID=? AND CM_WebProject_ID=?"; + thisContainer = new Query(ctx, MContainer.Table_Name, whereClause, trxName) + .setParameters(new Object[]{CM_Container_ID, CM_WebProject_Id}) + .first(); + // return thisContainer; } @@ -153,33 +109,12 @@ public class MContainer extends X_CM_Container String trxName) { MContainer cc = null; - PreparedStatement pstmt = null; - String sql = "SELECT * FROM CM_Container WHERE CM_Container_ID=?"; - try - { - pstmt = DB.prepareStatement (sql, null); - pstmt.setInt (1, CM_Container_ID); - ResultSet rs = pstmt.executeQuery (); - if (rs.next ()) - cc = new MContainer (ctx, rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - s_log.log (Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1/trifon + String whereClause = "CM_Container_ID=?"; + cc = new Query(ctx, MContainer.Table_Name, whereClause, trxName) + .setParameters(new Object[]{CM_Container_ID}) + .first(); + // return cc; } // getDirect @@ -192,37 +127,12 @@ public class MContainer extends X_CM_Container */ public static MContainer[] getContainers (MWebProject project) { - ArrayList list = new ArrayList (); - PreparedStatement pstmt = null; - String sql = "SELECT * FROM CM_Container WHERE CM_WebProject_ID=? ORDER BY CM_Container_ID"; - try - { - pstmt = DB.prepareStatement (sql, project.get_TrxName ()); - pstmt.setInt (1, project.getCM_WebProject_ID ()); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - { - list.add (new MContainer (project.getCtx (), rs, project - .get_TrxName ())); - } - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - s_log.log (Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1/trifon + String whereClause = "CM_WebProject_ID=?"; + List list = new Query(project.getCtx(), MContainer.Table_Name, whereClause, project.get_TrxName()) + .setParameters(new Object[]{project.getCM_WebProject_ID ()}) + .list(); + // MContainer[] retValue = new MContainer[list.size ()]; list.toArray (retValue); return retValue;