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
This commit is contained in:
Redhuan D. Oon 2010-02-28 09:55:38 +00:00
parent 042083872b
commit b690a934d3
8 changed files with 35 additions and 30 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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<Object> params = new ArrayList<Object>();
String whereClause = "AD_Client_ID=?";
final String whereClause = "AD_Client_ID=?";
params.add(Env.getAD_Client_ID(m_ctx));
List<MAccount> 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();

View File

@ -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 <MAlertRule> 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 <MAlertRecipient> list = new Query(getCtx(), MAlertRecipient.Table_Name, whereClause, null)
.setParameters(new Object[]{getAD_Alert_ID()})
.setOnlyActiveRecords(true)

View File

@ -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<MAllocationHdr> list = query.list();
MAllocationHdr[] retValue = new MAllocationHdr[list.size()];
list.toArray(retValue);

View File

@ -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 <X_T_InvoiceGL> 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

View File

@ -95,7 +95,7 @@ public class M_Production_Run extends SvrProcess {
String whereClause = "M_Production_ID=? ";
List<X_M_ProductionPlan> 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<X_M_ProductionLine> 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();

View File

@ -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)