From b690a934d3396478563749d0a26fa77f7573530d Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Sun, 28 Feb 2010 09:55:38 +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 --- .../adempiere/process/InOutGenerateRMA.java | 7 ++--- base/src/org/compiere/model/MAccount.java | 6 ++--- .../org/compiere/model/MAccountLookup.java | 8 +++--- base/src/org/compiere/model/MAlert.java | 4 +-- .../org/compiere/model/MAllocationHdr.java | 6 ++--- base/src/org/compiere/process/InvoiceNGL.java | 4 +-- .../compiere/process/M_Production_Run.java | 4 +-- .../functional/inventory/InventoryUtil.java | 26 +++++++++++-------- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/base/src/org/adempiere/process/InOutGenerateRMA.java b/base/src/org/adempiere/process/InOutGenerateRMA.java index e7e5c8513c..89ee0b41fc 100644 --- a/base/src/org/adempiere/process/InOutGenerateRMA.java +++ b/base/src/org/adempiere/process/InOutGenerateRMA.java @@ -23,6 +23,7 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.logging.Level; +import org.compiere.model.I_C_InvoiceLine; import org.compiere.model.MInOut; import org.compiere.model.MInOutLine; import org.compiere.model.MInvoiceLine; @@ -204,10 +205,10 @@ public class InOutGenerateRMA extends SvrProcess // // Link to corresponding Invoice Line (if any) - teo_sarca [ 2818523 ] // The MMatchInv records will be automatically generated on MInOut.completeIt() - final MInvoiceLine invoiceLine = new Query(shipment.getCtx(), MInvoiceLine.Table_Name, - MInvoiceLine.COLUMNNAME_M_RMALine_ID+"=?", + final MInvoiceLine invoiceLine = new Query(shipment.getCtx(), I_C_InvoiceLine.Table_Name, + I_C_InvoiceLine.COLUMNNAME_M_RMALine_ID+"=?", shipment.get_TrxName()) - .setParameters(new Object[]{rmaLine.getM_RMALine_ID()}) + .setParameters(rmaLine.getM_RMALine_ID()) .firstOnly(); if (invoiceLine != null) { diff --git a/base/src/org/compiere/model/MAccount.java b/base/src/org/compiere/model/MAccount.java index 9c221ecdf9..5204580ba0 100644 --- a/base/src/org/compiere/model/MAccount.java +++ b/base/src/org/compiere/model/MAccount.java @@ -242,9 +242,9 @@ public class MAccount extends X_C_ValidCombination */ public static MAccount get (Properties ctx, int C_AcctSchema_ID, String alias) { - String whereClause = "C_AcctSchema_ID=? AND Alias=?"; - MAccount retValue = new Query(ctx,MAccount.Table_Name,whereClause.toString(),null) - .setParameters(new Object[]{C_AcctSchema_ID,alias}) + final String whereClause = "C_AcctSchema_ID=? AND Alias=?"; + MAccount retValue = new Query(ctx,I_C_ValidCombination.Table_Name,whereClause.toString(),null) + .setParameters(C_AcctSchema_ID,alias) .firstOnly(); return retValue; } // get diff --git a/base/src/org/compiere/model/MAccountLookup.java b/base/src/org/compiere/model/MAccountLookup.java index 1aa584edac..8d04c03d0f 100644 --- a/base/src/org/compiere/model/MAccountLookup.java +++ b/base/src/org/compiere/model/MAccountLookup.java @@ -139,8 +139,8 @@ public final class MAccountLookup extends Lookup implements Serializable return true; String whereClause = "C_ValidCombination_ID=?"; - MAccount account = new Query(Env.getCtx(),MAccount.Table_Name,whereClause,null) - .setParameters(new Object[]{ID}) + MAccount account = new Query(Env.getCtx(),I_C_ValidCombination.Table_Name,whereClause,null) + .setParameters(ID) .firstOnly(); if(account == null) @@ -178,12 +178,12 @@ public final class MAccountLookup extends Lookup implements Serializable list.add(new KeyNamePair (-1, "")); // ArrayList params = new ArrayList(); - String whereClause = "AD_Client_ID=?"; + final String whereClause = "AD_Client_ID=?"; params.add(Env.getAD_Client_ID(m_ctx)); List accounts = new Query(Env.getCtx(),I_C_ValidCombination.Table_Name,whereClause,null) .setParameters(params) - .setOrderBy(MAccount.COLUMNNAME_Combination) + .setOrderBy(I_C_ValidCombination.COLUMNNAME_Combination) .setOnlyActiveRecords(onlyActive) .list(); diff --git a/base/src/org/compiere/model/MAlert.java b/base/src/org/compiere/model/MAlert.java index 1c1bb465fc..016b2a43e6 100644 --- a/base/src/org/compiere/model/MAlert.java +++ b/base/src/org/compiere/model/MAlert.java @@ -88,7 +88,7 @@ public class MAlert extends X_AD_Alert if (m_rules != null && !reload) return m_rules; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 - String whereClause = "AD_Alert_ID=?"; + final String whereClause = "AD_Alert_ID=?"; List list = new Query(getCtx(), MAlertRule.Table_Name, whereClause, null) .setParameters(new Object[]{getAD_Alert_ID()}) .setOrderBy("Name, AD_AlertRule_ID") @@ -115,7 +115,7 @@ public class MAlert extends X_AD_Alert if (m_recipients != null && !reload) return m_recipients; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 - String whereClause = "AD_Alert_ID=?"; + final String whereClause = "AD_Alert_ID=?"; List list = new Query(getCtx(), MAlertRecipient.Table_Name, whereClause, null) .setParameters(new Object[]{getAD_Alert_ID()}) .setOnlyActiveRecords(true) diff --git a/base/src/org/compiere/model/MAllocationHdr.java b/base/src/org/compiere/model/MAllocationHdr.java index 266ffa33e7..ab1c0b0617 100644 --- a/base/src/org/compiere/model/MAllocationHdr.java +++ b/base/src/org/compiere/model/MAllocationHdr.java @@ -144,13 +144,13 @@ public final class MAllocationHdr extends X_C_AllocationHdr implements DocAction */ public static MAllocationHdr[] getOfCash (Properties ctx, int C_Cash_ID, String trxName) { - String whereClause = "IsActive='Y'" + final String whereClause = "IsActive='Y'" + " AND EXISTS (SELECT 1 FROM C_CashLine cl, C_AllocationLine al " + "where cl.C_Cash_ID=? and al.C_CashLine_ID=cl.C_CashLine_ID " + "and C_AllocationHdr.C_AllocationHdr_ID=al.C_AllocationHdr_ID)"; - Query query = MTable.get(ctx, MAllocationHdr.Table_ID) + Query query = MTable.get(ctx, I_C_AllocationHdr.Table_ID) .createQuery(whereClause, trxName); - query.setParameters(new Object[]{C_Cash_ID}); + query.setParameters(C_Cash_ID); List list = query.list(); MAllocationHdr[] retValue = new MAllocationHdr[list.size()]; list.toArray(retValue); diff --git a/base/src/org/compiere/process/InvoiceNGL.java b/base/src/org/compiere/process/InvoiceNGL.java index dff54f7406..c8dc64b95c 100644 --- a/base/src/org/compiere/process/InvoiceNGL.java +++ b/base/src/org/compiere/process/InvoiceNGL.java @@ -220,9 +220,9 @@ public class InvoiceNGL extends SvrProcess private String createGLJournal() { //FR: [ 2214883 ] Remove SQL code and Replace for Query - String whereClause = "AD_PInstance_ID=?"; + final String whereClause = "AD_PInstance_ID=?"; List list = new Query(getCtx(), X_T_InvoiceGL.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getAD_PInstance_ID()}) + .setParameters(getAD_PInstance_ID()) .setOrderBy("AD_Org_ID") .list(); //FR: [ 2214883 ] Remove SQL code and Replace for Query diff --git a/base/src/org/compiere/process/M_Production_Run.java b/base/src/org/compiere/process/M_Production_Run.java index 237fbf78c3..e5634be136 100644 --- a/base/src/org/compiere/process/M_Production_Run.java +++ b/base/src/org/compiere/process/M_Production_Run.java @@ -95,7 +95,7 @@ public class M_Production_Run extends SvrProcess { String whereClause = "M_Production_ID=? "; List lines = new Query(getCtx(), X_M_ProductionPlan.Table_Name , whereClause, get_TrxName()) - .setParameters(new Object[]{p_Record_ID }) + .setParameters(p_Record_ID) .setOrderBy("Line, M_Product_ID") .list(); for (X_M_ProductionPlan pp :lines) @@ -125,7 +125,7 @@ public class M_Production_Run extends SvrProcess { { whereClause = "M_ProductionPlan_ID= ? "; List production_lines = new Query(getCtx(), X_M_ProductionLine.Table_Name , whereClause, get_TrxName()) - .setParameters(new Object[]{pp.getM_ProductionPlan_ID()}) + .setParameters(pp.getM_ProductionPlan_ID()) .setOrderBy("Line") .list(); diff --git a/extend/src/test/functional/inventory/InventoryUtil.java b/extend/src/test/functional/inventory/InventoryUtil.java index bb2ccf5411..1812d714b7 100644 --- a/extend/src/test/functional/inventory/InventoryUtil.java +++ b/extend/src/test/functional/inventory/InventoryUtil.java @@ -18,6 +18,10 @@ import java.sql.Timestamp; import java.util.Properties; import org.adempiere.exceptions.AdempiereException; +import org.compiere.model.I_C_BPartner; +import org.compiere.model.I_M_Product; +import org.compiere.model.I_M_Product_Category; +import org.compiere.model.I_M_Warehouse; import org.compiere.model.MBPGroup; import org.compiere.model.MBPartner; import org.compiere.model.MBPartnerLocation; @@ -56,8 +60,8 @@ public final class InventoryUtil public static MProduct getCreateProduct(String value, String MMPolicy) { Properties ctx = Env.getCtx(); - MProduct product = new Query(ctx, MProduct.Table_Name, "Value=?", null) - .setParameters(new Object[]{value}) + MProduct product = new Query(ctx, I_M_Product.Table_Name, "Value=?", null) + .setParameters(value) .setOnlyActiveRecords(true) .setClient_ID() .firstOnly(); @@ -104,9 +108,9 @@ public final class InventoryUtil if (MMPolicy == null) MMPolicy = MProductCategory.MMPOLICY_FiFo; Properties ctx = Env.getCtx(); - String whereClause = MProductCategory.COLUMNNAME_Value+"=?"; - MProductCategory pc = new Query(ctx, MProductCategory.Table_Name, whereClause, null) - .setParameters(new Object[]{value}) + final String whereClause = I_M_Product_Category.COLUMNNAME_Value+"=?"; + MProductCategory pc = new Query(ctx, I_M_Product_Category.Table_Name, whereClause, null) + .setParameters(value) .setOnlyActiveRecords(true) .setClient_ID() .firstOnly(); @@ -136,9 +140,9 @@ public final class InventoryUtil public static MBPartner getCreatePartner(String value) { Properties ctx = Env.getCtx(); - String whereClause = MBPartner.COLUMNNAME_Value+"=?"; - MBPartner bp = new Query(ctx, MBPartner.Table_Name, whereClause, null) - .setParameters(new Object[]{value}) + final String whereClause = MBPartner.COLUMNNAME_Value+"=?"; + MBPartner bp = new Query(ctx, I_C_BPartner.Table_Name, whereClause, null) + .setParameters(value) .setClient_ID() .firstOnly(); if (bp == null) @@ -339,9 +343,9 @@ public final class InventoryUtil if (AD_Org_ID <= 0) AD_Org_ID = getFirst_Org_ID(); Properties ctx = Env.getCtx(); - String whereClause = "AD_Org_ID=? AND Value=?"; - MWarehouse wh = new Query(ctx, MWarehouse.Table_Name, whereClause, null) - .setParameters(new Object[]{AD_Org_ID, value}) + final String whereClause = "AD_Org_ID=? AND Value=?"; + MWarehouse wh = new Query(ctx, I_M_Warehouse.Table_Name, whereClause, null) + .setParameters(AD_Org_ID, value) .setClient_ID() .firstOnly(); if (wh != null)