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-03-02 15:43:25 +00:00
parent d2333e9026
commit 7fb5e6b54d
17 changed files with 59 additions and 60 deletions

View File

@ -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();
}

View File

@ -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<MAccount> rs = new Query(getCtx(), MAccount.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
POResultSet<MAccount> rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName())
.setParameters(get_ID())
.scroll();
try {
while(rs.hasNext()) {

View File

@ -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<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
.setParameters(new Object[]{M_InOutLine_ID, C_InvoiceLine_ID})
List<MMatchInv> 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<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
.setParameters(new Object[]{C_InvoiceLine_ID})
List<MMatchInv> 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<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
.setParameters(new Object[]{M_InOut_ID})
List<MMatchInv> 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<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
.setParameters(new Object[]{C_Invoice_ID})
List<MMatchInv> 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<MMatchInv> list = new Query(ctx, MMatchInv.Table_Name, whereClause, trxName)
.setParameters(new Object[]{M_InOutLine_ID})
List<MMatchInv> list = new Query(ctx, I_M_MatchInv.Table_Name, whereClause, trxName)
.setParameters(M_InOutLine_ID)
.list();
return list.toArray (new MMatchInv[list.size()]);
} // getInOutLine

View File

@ -102,8 +102,8 @@ public class MMovement extends X_M_Movement implements DocAction
}
//
final String whereClause = "M_Movement_ID=?";
List<MMovement> list = new Query(getCtx(), MMovementLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getM_Movement_ID()})
List<MMovement> 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<MMovementConfirm> list = new Query(getCtx(), MMovementConfirm.Table_Name, "M_Movement_ID=?", get_TrxName())
.setParameters(new Object[]{get_ID()})
List<MMovementConfirm> 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;

View File

@ -335,7 +335,7 @@ public class MMovementLine extends X_M_MovementLine
whereClause += " AND (" + where + ")";
//
List<MMovementLine> 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

View File

@ -645,8 +645,8 @@ public class MOrder extends X_C_Order implements DocAction
if (orderClause.length() == 0)
orderClause = MOrderLine.COLUMNNAME_Line;
//
List<MOrderLine> list = new Query(getCtx(), MOrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName())
.setParameters(new Object[]{get_ID()})
List<MOrderLine> 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<MOrderTax> list = new Query(getCtx(), MOrderTax.Table_Name, "C_Order_ID=?", get_TrxName())
.setParameters(new Object[]{get_ID()})
List<MOrderTax> 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<MInvoice> list = new Query(getCtx(), MInvoice.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
List<MInvoice> 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<MInvoice> list = new Query(getCtx(), MInOut.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
List<MInvoice> 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()]);

View File

@ -48,7 +48,7 @@ public class MOrg extends X_AD_Org
List<MOrg> 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)
{

View File

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

View File

@ -64,7 +64,7 @@ public class MPOS extends X_C_POS
{
String whereClause = field+"=?";
List<MPOS> list = new Query(ctx, Table_Name, whereClause, null)
.setParameters(new Object[]{ID})
.setParameters(ID)
.setOnlyActiveRecords(true)
.setOrderBy(COLUMNNAME_Name)
.list();

View File

@ -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<MPaymentAllocate> list = query.list();
return list.toArray(new MPaymentAllocate[list.size()]);
} // get

View File

@ -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<MPeriod> periods = query.list();

View File

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

View File

@ -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<MProcessPara> list = new Query(getCtx(), MProcessPara.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
final String whereClause = MProcessPara.COLUMNNAME_AD_Process_ID+"=?";
List<MProcessPara> list = new Query(getCtx(), I_AD_Process_Para.Table_Name, whereClause, get_TrxName())
.setParameters(get_ID())
.setOrderBy(MProcessPara.COLUMNNAME_SeqNo)
.list();
//

View File

@ -88,7 +88,7 @@ public class MProduct extends X_M_Product
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
List<MProduct> 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<MProduct> 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<MProductDownload> list = new Query(getCtx(), MProductDownload.Table_Name, "M_Product_ID=?", get_TrxName())
List<MProductDownload> 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)
{

View File

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

View File

@ -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<MProductCosting> costs =new Query(ctx, MProductCosting.Table_Name,whereClause, trxName )
.setParameters(new Object[]{M_Product_ID})
List<MProductCosting> 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

View File

@ -45,7 +45,7 @@ public class MProductPO extends X_M_Product_PO
{
final String whereClause = "M_Product_ID=? AND IsActive=?";
List<MProductPO> 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()]);