Peer review of FR: [ 2214883 ] Remove SQL code and Replace for Query

revisions 11482, 11484, 11485, 11487, 11488, 11489, 11490
- Added method Query.getParameters(int) to improve readability (if most of the replacements just use one int parameter it makes sense to avoid the declaration of new Object[] all the times)
- drop unused imports
- check serialVersionUID
- what is the advantage of using I_M_Product_BOM.Table_Name instead of MProductBOM.Table_Name when defining a list of MProductBOM objects? and it's intended that MProductBOM must always implement the interface

Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Carlos Ruiz 2010-02-26 00:29:57 +00:00
parent 47c6baa245
commit 0725d135a9
5 changed files with 19 additions and 15 deletions

View File

@ -43,7 +43,7 @@ public class MPInstance extends X_AD_PInstance
/** /**
* *
*/ */
private static final long serialVersionUID = 209806970824523840L; private static final long serialVersionUID = -5848424269552679604L;
/** /**
* Standard Constructor * Standard Constructor
@ -127,8 +127,8 @@ public class MPInstance extends X_AD_PInstance
return m_parameters; return m_parameters;
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String whereClause = "AD_PInstance_ID=?"; String whereClause = "AD_PInstance_ID=?";
List <MPInstancePara> list = new Query(getCtx(), MPInstancePara.Table_Name, whereClause, null) List <MPInstancePara> list = new Query(getCtx(), MPInstancePara.Table_Name, whereClause, null) // @TODO: Review implications of using transaction
.setParameters(new Object[]{getAD_PInstance_ID()}) .setParameters(getAD_PInstance_ID())
.list(); .list();
// //

View File

@ -86,7 +86,7 @@ public class MPaySelection extends X_C_PaySelection
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String whereClause = "C_PaySelection_ID=?"; String whereClause = "C_PaySelection_ID=?";
List <MPaySelectionLine> list = new Query(getCtx(), MPaySelectionLine.Table_Name, whereClause, get_TrxName()) List <MPaySelectionLine> list = new Query(getCtx(), MPaySelectionLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{getC_PaySelection_ID()}) .setParameters(getC_PaySelection_ID())
.setOrderBy("Line") .setOrderBy("Line")
.list() .list()
; ;

View File

@ -22,12 +22,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
@ -82,7 +80,7 @@ public final class MPayment extends X_C_Payment
/** /**
* *
*/ */
private static final long serialVersionUID = 5273805787122033169L; private static final long serialVersionUID = 6200327948230438741L;
/** /**
* Get Payments Of BPartner * Get Payments Of BPartner
@ -96,7 +94,7 @@ public final class MPayment extends X_C_Payment
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String whereClause = "C_BPartner_ID=?"; String whereClause = "C_BPartner_ID=?";
List <MPayment> list = new Query(ctx, MPayment.Table_Name, whereClause, trxName) List <MPayment> list = new Query(ctx, MPayment.Table_Name, whereClause, trxName)
.setParameters(new Object[]{C_BPartner_ID}) .setParameters(C_BPartner_ID)
.list(); .list();
// //

View File

@ -16,15 +16,11 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
/** /**
@ -65,8 +61,8 @@ public class MProductBOM extends X_M_Product_BOM
{ {
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
final String whereClause = "M_Product_ID=?"; final String whereClause = "M_Product_ID=?";
List <MProductBOM> list = new Query(ctx, I_M_Product_BOM.Table_Name, whereClause, trxName) List <MProductBOM> list = new Query(ctx, MProductBOM.Table_Name, whereClause, trxName)
.setParameters(new Object[]{M_Product_ID}) .setParameters(M_Product_ID)
.setOrderBy("Line") .setOrderBy("Line")
.list(); .list();

View File

@ -132,6 +132,15 @@ public class Query
return this; return this;
} }
/**
* Set query parameters (one integer)
* @int_param integer parameter
*/
public Query setParameters(int int_param) {
this.parameters = new Object[]{int_param};
return this;
}
/** /**
* Set query parameters * Set query parameters
* @param parameters collection of parameters * @param parameters collection of parameters
@ -754,4 +763,5 @@ public class Query
} }
return retValue; return retValue;
} // get_IDs } // get_IDs
} }