From 7fb5e6b54d8b9a79c3bc7ec45393c1efbfc88ebe Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Tue, 2 Mar 2010 15:43:25 +0000 Subject: [PATCH] Review FR: [ 2214883 ] Remove SQL code and Replace for Query >> to incorporate Best Practice. No unit testing done but compiler tested OK. Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883 --- base/src/org/compiere/model/MDunningRun.java | 2 +- .../src/org/compiere/model/MElementValue.java | 4 ++-- base/src/org/compiere/model/MMatchInv.java | 20 +++++++++---------- base/src/org/compiere/model/MMovement.java | 8 ++++---- .../src/org/compiere/model/MMovementLine.java | 2 +- base/src/org/compiere/model/MOrder.java | 16 +++++++-------- base/src/org/compiere/model/MOrg.java | 2 +- base/src/org/compiere/model/MOrgInfo.java | 2 +- base/src/org/compiere/model/MPOS.java | 2 +- .../org/compiere/model/MPaymentAllocate.java | 2 +- base/src/org/compiere/model/MPeriod.java | 4 ++-- base/src/org/compiere/model/MPriceList.java | 9 ++++----- base/src/org/compiere/model/MProcess.java | 12 +++++------ base/src/org/compiere/model/MProduct.java | 18 ++++++++--------- .../compiere/model/MProductCategoryAcct.java | 2 +- .../org/compiere/model/MProductCosting.java | 12 +++++------ base/src/org/compiere/model/MProductPO.java | 2 +- 17 files changed, 59 insertions(+), 60 deletions(-) diff --git a/base/src/org/compiere/model/MDunningRun.java b/base/src/org/compiere/model/MDunningRun.java index 1d3d2ec3ac..eb16da2123 100644 --- a/base/src/org/compiere/model/MDunningRun.java +++ b/base/src/org/compiere/model/MDunningRun.java @@ -100,7 +100,7 @@ public class MDunningRun extends X_C_DunningRun "C_Dunning_ID=?", get_TrxName()) .setOnlyActiveRecords(true) - .setParameters(new Object[]{getC_Dunning_ID()}) + .setParameters(getC_Dunning_ID()) .setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID") .list(); } diff --git a/base/src/org/compiere/model/MElementValue.java b/base/src/org/compiere/model/MElementValue.java index 14f997a68d..767f86bb3f 100644 --- a/base/src/org/compiere/model/MElementValue.java +++ b/base/src/org/compiere/model/MElementValue.java @@ -223,8 +223,8 @@ public class MElementValue extends X_C_ElementValue // // Check Valid Combinations - teo_sarca FR [ 1883533 ] String whereClause = MAccount.COLUMNNAME_Account_ID+"=?"; - POResultSet rs = new Query(getCtx(), MAccount.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) + POResultSet rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName()) + .setParameters(get_ID()) .scroll(); try { while(rs.hasNext()) { diff --git a/base/src/org/compiere/model/MMatchInv.java b/base/src/org/compiere/model/MMatchInv.java index ea5665ecb3..ef1867605c 100644 --- a/base/src/org/compiere/model/MMatchInv.java +++ b/base/src/org/compiere/model/MMatchInv.java @@ -66,8 +66,8 @@ public class MMatchInv extends X_M_MatchInv return new MMatchInv[]{}; // final String whereClause = "M_InOutLine_ID=? AND C_InvoiceLine_ID=?"; - List list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_InOutLine_ID, C_InvoiceLine_ID}) + List list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName) + .setParameters(M_InOutLine_ID, C_InvoiceLine_ID) .list(); return list.toArray (new MMatchInv[list.size()]); } // get @@ -86,8 +86,8 @@ public class MMatchInv extends X_M_MatchInv return new MMatchInv[]{}; // String whereClause = "C_InvoiceLine_ID=?"; - List list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName) - .setParameters(new Object[]{C_InvoiceLine_ID}) + List list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName) + .setParameters(C_InvoiceLine_ID) .list(); return list.toArray (new MMatchInv[list.size()]); } // getInvoiceLine @@ -107,8 +107,8 @@ public class MMatchInv extends X_M_MatchInv // final String whereClause = "EXISTS (SELECT 1 FROM M_InOutLine l" +" WHERE M_MatchInv.M_InOutLine_ID=l.M_InOutLine_ID AND l.M_InOut_ID=?)"; - List list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_InOut_ID}) + List list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName) + .setParameters(M_InOut_ID) .list(); return list.toArray (new MMatchInv[list.size()]); } // getInOut @@ -128,8 +128,8 @@ public class MMatchInv extends X_M_MatchInv // final String whereClause = " EXISTS (SELECT 1 FROM C_InvoiceLine il" +" WHERE M_MatchInv.C_InvoiceLine_ID=il.C_InvoiceLine_ID AND il.C_Invoice_ID=?)"; - List list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName) - .setParameters(new Object[]{C_Invoice_ID}) + List list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName) + .setParameters(C_Invoice_ID) .list(); return list.toArray (new MMatchInv[list.size()]); } // getInvoice @@ -470,8 +470,8 @@ public class MMatchInv extends X_M_MatchInv } // final String whereClause = MMatchInv.COLUMNNAME_M_InOutLine_ID+"=?"; - List list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_InOutLine_ID}) + List list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName) + .setParameters(M_InOutLine_ID) .list(); return list.toArray (new MMatchInv[list.size()]); } // getInOutLine diff --git a/base/src/org/compiere/model/MMovement.java b/base/src/org/compiere/model/MMovement.java index f8e1f9fbf1..5006e0512a 100644 --- a/base/src/org/compiere/model/MMovement.java +++ b/base/src/org/compiere/model/MMovement.java @@ -102,8 +102,8 @@ public class MMovement extends X_M_Movement implements DocAction } // final String whereClause = "M_Movement_ID=?"; - List list = new Query(getCtx(), MMovementLine.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getM_Movement_ID()}) + List list = new Query(getCtx(), I_M_MovementLine.Table_Name, whereClause, get_TrxName()) + .setParameters(getM_Movement_ID()) .setOrderBy(MMovementLine.COLUMNNAME_Line) .list(); m_lines = new MMovementLine[list.size ()]; @@ -121,8 +121,8 @@ public class MMovement extends X_M_Movement implements DocAction if (m_confirms != null && !requery) return m_confirms; - List list = new Query(getCtx(), MMovementConfirm.Table_Name, "M_Movement_ID=?", get_TrxName()) - .setParameters(new Object[]{get_ID()}) + List list = new Query(getCtx(), I_M_MovementConfirm.Table_Name, "M_Movement_ID=?", get_TrxName()) + .setParameters(get_ID()) .list(); m_confirms = list.toArray(new MMovementConfirm[list.size()]); return m_confirms; diff --git a/base/src/org/compiere/model/MMovementLine.java b/base/src/org/compiere/model/MMovementLine.java index d6989c15c0..b47398df55 100644 --- a/base/src/org/compiere/model/MMovementLine.java +++ b/base/src/org/compiere/model/MMovementLine.java @@ -335,7 +335,7 @@ public class MMovementLine extends X_M_MovementLine whereClause += " AND (" + where + ")"; // List list = new Query(ctx, Table_Name, whereClause, trxName) - .setParameters(new Object[]{DD_OrderLine_ID}) + .setParameters(DD_OrderLine_ID) .list(); return list.toArray(new MMovementLine[list.size()]); } // getOfOrderLine diff --git a/base/src/org/compiere/model/MOrder.java b/base/src/org/compiere/model/MOrder.java index 79e2772ce4..02aaa9fad1 100644 --- a/base/src/org/compiere/model/MOrder.java +++ b/base/src/org/compiere/model/MOrder.java @@ -645,8 +645,8 @@ public class MOrder extends X_C_Order implements DocAction if (orderClause.length() == 0) orderClause = MOrderLine.COLUMNNAME_Line; // - List list = new Query(getCtx(), MOrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName()) - .setParameters(new Object[]{get_ID()}) + List list = new Query(getCtx(), I_C_OrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName()) + .setParameters(get_ID()) .setOrderBy(orderClause) .list(); for (MOrderLine ol : list) { @@ -731,8 +731,8 @@ public class MOrder extends X_C_Order implements DocAction if (m_taxes != null && !requery) return m_taxes; // - List list = new Query(getCtx(), MOrderTax.Table_Name, "C_Order_ID=?", get_TrxName()) - .setParameters(new Object[]{get_ID()}) + List list = new Query(getCtx(), I_C_OrderTax.Table_Name, "C_Order_ID=?", get_TrxName()) + .setParameters(get_ID()) .list(); m_taxes = list.toArray(new MOrderTax[list.size()]); return m_taxes; @@ -749,8 +749,8 @@ public class MOrder extends X_C_Order implements DocAction +" WHERE il.C_Invoice_ID=C_Invoice.C_Invoice_ID" +" AND il.C_OrderLine_ID=ol.C_OrderLine_ID" +" AND ol.C_Order_ID=?)"; - List list = new Query(getCtx(), MInvoice.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) + List list = new Query(getCtx(), I_C_Invoice.Table_Name, whereClause, get_TrxName()) + .setParameters(get_ID()) .setOrderBy("C_Invoice_ID DESC") .list(); return list.toArray(new MInvoice[list.size()]); @@ -780,8 +780,8 @@ public class MOrder extends X_C_Order implements DocAction +" WHERE iol.M_InOut_ID=M_InOut.M_InOut_ID" +" AND iol.C_OrderLine_ID=ol.C_OrderLine_ID" +" AND ol.C_Order_ID=?)"; - List list = new Query(getCtx(), MInOut.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) + List list = new Query(getCtx(), I_M_InOut.Table_Name, whereClause, get_TrxName()) + .setParameters(get_ID()) .setOrderBy("M_InOut_ID DESC") .list(); return list.toArray(new MInOut[list.size()]); diff --git a/base/src/org/compiere/model/MOrg.java b/base/src/org/compiere/model/MOrg.java index e102263840..79ae84fd2b 100644 --- a/base/src/org/compiere/model/MOrg.java +++ b/base/src/org/compiere/model/MOrg.java @@ -48,7 +48,7 @@ public class MOrg extends X_AD_Org List list = new Query(po.getCtx(), Table_Name, "AD_Client_ID=?", null) .setOrderBy(COLUMNNAME_Value) .setOnlyActiveRecords(true) - .setParameters(new Object[]{po.getAD_Client_ID()}) + .setParameters(po.getAD_Client_ID()) .list(); for (MOrg org : list) { diff --git a/base/src/org/compiere/model/MOrgInfo.java b/base/src/org/compiere/model/MOrgInfo.java index 1910178e80..88c4647c71 100644 --- a/base/src/org/compiere/model/MOrgInfo.java +++ b/base/src/org/compiere/model/MOrgInfo.java @@ -52,7 +52,7 @@ public class MOrgInfo extends X_AD_OrgInfo return retValue; } retValue = new Query(ctx, Table_Name, "AD_Org_ID=?", null) - .setParameters(new Object[]{AD_Org_ID}) + .setParameters(AD_Org_ID) .firstOnly(); if (retValue != null) { diff --git a/base/src/org/compiere/model/MPOS.java b/base/src/org/compiere/model/MPOS.java index b405ba7d1b..556f5dfa04 100644 --- a/base/src/org/compiere/model/MPOS.java +++ b/base/src/org/compiere/model/MPOS.java @@ -64,7 +64,7 @@ public class MPOS extends X_C_POS { String whereClause = field+"=?"; List list = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{ID}) + .setParameters(ID) .setOnlyActiveRecords(true) .setOrderBy(COLUMNNAME_Name) .list(); diff --git a/base/src/org/compiere/model/MPaymentAllocate.java b/base/src/org/compiere/model/MPaymentAllocate.java index af6cc3aee2..730106c538 100644 --- a/base/src/org/compiere/model/MPaymentAllocate.java +++ b/base/src/org/compiere/model/MPaymentAllocate.java @@ -46,7 +46,7 @@ public class MPaymentAllocate extends X_C_PaymentAllocate { final String whereClause = "C_Payment_ID=? AND IsActive=?"; Query query = MTable.get(parent.getCtx(), Table_ID).createQuery(whereClause, parent.get_TrxName()); - query.setParameters(new Object[]{parent.getC_Payment_ID(), "Y"}); + query.setParameters(parent.getC_Payment_ID(), "Y"); List list = query.list(); return list.toArray(new MPaymentAllocate[list.size()]); } // get diff --git a/base/src/org/compiere/model/MPeriod.java b/base/src/org/compiere/model/MPeriod.java index 4fbce5554a..f3866d2153 100644 --- a/base/src/org/compiere/model/MPeriod.java +++ b/base/src/org/compiere/model/MPeriod.java @@ -589,9 +589,9 @@ public class MPeriod extends X_C_Period " AND (? BETWEEN StartDate AND EndDate" + " OR ? BETWEEN StartDate AND EndDate)" + " AND PeriodType=?",get_TrxName()); - query.setParameters(new Object[] {year.getC_Calendar_ID(), + query.setParameters(year.getC_Calendar_ID(), getStartDate(), getEndDate(), - getPeriodType()}); + getPeriodType()); List periods = query.list(); diff --git a/base/src/org/compiere/model/MPriceList.java b/base/src/org/compiere/model/MPriceList.java index c92a1042a6..2abc6bb706 100644 --- a/base/src/org/compiere/model/MPriceList.java +++ b/base/src/org/compiere/model/MPriceList.java @@ -16,7 +16,6 @@ *****************************************************************************/ package org.compiere.model; -import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.Timestamp; import java.util.Iterator; @@ -87,7 +86,7 @@ public class MPriceList extends X_M_PriceList // Get from DB final String whereClause = "AD_Client_ID=? AND IsDefault=? AND IsSOPriceList=?"; retValue = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N"}) + .setParameters(AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N") .setOrderBy("M_PriceList_ID") .first(); @@ -134,7 +133,7 @@ public class MPriceList extends X_M_PriceList // Get from DB final String whereClause = "AD_Client_ID=? AND IsDefault=? AND IsSOPriceList=? AND C_Currency_ID=?"; retValue = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N", Integer.valueOf(M_Currency_ID)}) + .setParameters(AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N", Integer.valueOf(M_Currency_ID)) .setOrderBy("M_PriceList_ID") .first(); @@ -244,8 +243,8 @@ public class MPriceList extends X_M_PriceList return m_plv; final String whereClause = "M_PriceList_ID=? AND TRUNC(ValidFrom)<=? AND IsActive=?"; - m_plv = new Query(getCtx(), MPriceListVersion.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getM_PriceList_ID(), valid, "Y"}) + m_plv = new Query(getCtx(), I_M_PriceList_Version.Table_Name, whereClause, get_TrxName()) + .setParameters(getM_PriceList_ID(), valid, "Y") .setOrderBy("ValidFrom DESC") .first(); if (m_plv == null) diff --git a/base/src/org/compiere/model/MProcess.java b/base/src/org/compiere/model/MProcess.java index 122c53e22b..5fff8b5c20 100644 --- a/base/src/org/compiere/model/MProcess.java +++ b/base/src/org/compiere/model/MProcess.java @@ -71,10 +71,10 @@ public class MProcess extends X_AD_Process */ public static MProcess getFromMenu (Properties ctx, int AD_Menu_ID) { - String whereClause = "EXISTS (SELECT 1 FROM AD_Menu m" + final String whereClause = "EXISTS (SELECT 1 FROM AD_Menu m" +" WHERE m.AD_Process_ID=AD_Process.AD_Process_ID AND m.AD_Menu_ID=?)"; - MProcess p = new Query(ctx, MProcess.Table_Name, whereClause, null) - .setParameters(new Object[]{AD_Menu_ID}) + MProcess p = new Query(ctx, I_AD_Process.Table_Name, whereClause, null) + .setParameters(AD_Menu_ID) .firstOnly(); if (p != null) { @@ -133,9 +133,9 @@ public class MProcess extends X_AD_Process if (m_parameters != null) return m_parameters; // - String whereClause = MProcessPara.COLUMNNAME_AD_Process_ID+"=?"; - List list = new Query(getCtx(), MProcessPara.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) + final String whereClause = MProcessPara.COLUMNNAME_AD_Process_ID+"=?"; + List list = new Query(getCtx(), I_AD_Process_Para.Table_Name, whereClause, get_TrxName()) + .setParameters(get_ID()) .setOrderBy(MProcessPara.COLUMNNAME_SeqNo) .list(); // diff --git a/base/src/org/compiere/model/MProduct.java b/base/src/org/compiere/model/MProduct.java index 75ebd521c6..ad73e41b59 100644 --- a/base/src/org/compiere/model/MProduct.java +++ b/base/src/org/compiere/model/MProduct.java @@ -88,7 +88,7 @@ public class MProduct extends X_M_Product { int AD_Client_ID = Env.getAD_Client_ID(ctx); List list = new Query(ctx, Table_Name, "AD_Client_ID=? AND "+whereClause, trxName) - .setParameters(new Object[]{AD_Client_ID}) + .setParameters(AD_Client_ID) .list(); return list.toArray(new MProduct[list.size()]); } // get @@ -102,9 +102,9 @@ public class MProduct extends X_M_Product */ public static List getByUPC(Properties ctx, String upc, String trxName) { - String whereClause = "AD_Client_ID=? AND UPC=?"; + final String whereClause = "AD_Client_ID=? AND UPC=?"; Query q = new Query(ctx, Table_Name, whereClause, trxName); - q.setParameters(new Object[]{Env.getAD_Client_ID(ctx), upc}); + q.setParameters(Env.getAD_Client_ID(ctx), upc); return(q.list()); } @@ -533,10 +533,10 @@ public class MProduct extends X_M_Product if (m_downloads != null && !requery) return m_downloads; // - List list = new Query(getCtx(), MProductDownload.Table_Name, "M_Product_ID=?", get_TrxName()) + List list = new Query(getCtx(), I_M_ProductDownload.Table_Name, "M_Product_ID=?", get_TrxName()) .setOnlyActiveRecords(true) - .setOrderBy(MProductDownload.COLUMNNAME_Name) - .setParameters(new Object[]{get_ID()}) + .setOrderBy(I_M_ProductDownload.COLUMNNAME_Name) + .setParameters(get_ID()) .list(); m_downloads = list.toArray(new MProductDownload[list.size()]); return m_downloads; @@ -646,10 +646,10 @@ public class MProduct extends X_M_Product } //check if it has cost - boolean hasCosts = new Query(getCtx(), MCostDetail.Table_Name, - MCostDetail.COLUMNNAME_M_Product_ID+"=?", get_TrxName()) + boolean hasCosts = new Query(getCtx(), I_M_CostDetail.Table_Name, + I_M_CostDetail.COLUMNNAME_M_Product_ID+"=?", get_TrxName()) .setOnlyActiveRecords(true) - .setParameters(new Object[]{get_ID()}) + .setParameters(get_ID()) .match(); if (hasCosts) { diff --git a/base/src/org/compiere/model/MProductCategoryAcct.java b/base/src/org/compiere/model/MProductCategoryAcct.java index 2a993a74a7..594b7567aa 100644 --- a/base/src/org/compiere/model/MProductCategoryAcct.java +++ b/base/src/org/compiere/model/MProductCategoryAcct.java @@ -54,7 +54,7 @@ public class MProductCategoryAcct extends X_M_Product_Category_Acct final String whereClause = "M_Product_Category_ID=? AND C_AcctSchema_ID=?"; acct = new Query(ctx, Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_Product_Category_ID, C_AcctSchema_ID}) + .setParameters(M_Product_Category_ID, C_AcctSchema_ID) .firstOnly(); if (acct != null) { diff --git a/base/src/org/compiere/model/MProductCosting.java b/base/src/org/compiere/model/MProductCosting.java index 773a488f31..9c2e93dc1d 100644 --- a/base/src/org/compiere/model/MProductCosting.java +++ b/base/src/org/compiere/model/MProductCosting.java @@ -46,10 +46,10 @@ public class MProductCosting extends X_M_Product_Costing */ public static MProductCosting[] getOfProduct (Properties ctx, int M_Product_ID, String trxName) { - String whereClause = "M_Product_ID=?"; + final String whereClause = "M_Product_ID=?"; - List costs =new Query(ctx, MProductCosting.Table_Name,whereClause, trxName ) - .setParameters(new Object[]{M_Product_ID}) + List costs =new Query(ctx, I_M_Product_Costing.Table_Name,whereClause, trxName ) + .setParameters(M_Product_ID) .list(); return costs.toArray(new MProductCosting[costs.size()]); } // getOfProduct @@ -65,10 +65,10 @@ public class MProductCosting extends X_M_Product_Costing public static MProductCosting get (Properties ctx, int M_Product_ID, int C_AcctSchema_ID, String trxName) { - String whereClause = "M_Product_ID=? AND C_AcctSchema_ID=?"; + final String whereClause = "M_Product_ID=? AND C_AcctSchema_ID=?"; - return new Query(ctx, MProductCosting.Table_Name,whereClause, trxName ) - .setParameters(new Object[]{M_Product_ID, C_AcctSchema_ID}) + return new Query(ctx, I_M_Product_Costing.Table_Name,whereClause, trxName ) + .setParameters(M_Product_ID, C_AcctSchema_ID) .firstOnly(); } // get diff --git a/base/src/org/compiere/model/MProductPO.java b/base/src/org/compiere/model/MProductPO.java index 76837c59c3..1877c7825e 100644 --- a/base/src/org/compiere/model/MProductPO.java +++ b/base/src/org/compiere/model/MProductPO.java @@ -45,7 +45,7 @@ public class MProductPO extends X_M_Product_PO { final String whereClause = "M_Product_ID=? AND IsActive=?"; List list = new Query(ctx, Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_Product_ID, "Y"}) + .setParameters(M_Product_ID, "Y") .setOrderBy("IsCurrentVendor DESC") .list(); return list.toArray(new MProductPO[list.size()]);