From 0725d135a912f56f710634e3cbb828d254e3ceec Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 26 Feb 2010 00:29:57 +0000 Subject: [PATCH] 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 --- base/src/org/compiere/model/MPInstance.java | 6 +++--- base/src/org/compiere/model/MPaySelection.java | 2 +- base/src/org/compiere/model/MPayment.java | 8 +++----- base/src/org/compiere/model/MProductBOM.java | 8 ++------ base/src/org/compiere/model/Query.java | 10 ++++++++++ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/base/src/org/compiere/model/MPInstance.java b/base/src/org/compiere/model/MPInstance.java index 176a79c05f..d2ec3b7b85 100644 --- a/base/src/org/compiere/model/MPInstance.java +++ b/base/src/org/compiere/model/MPInstance.java @@ -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 @@ -127,8 +127,8 @@ public class MPInstance extends X_AD_PInstance return m_parameters; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 String whereClause = "AD_PInstance_ID=?"; - List list = new Query(getCtx(), MPInstancePara.Table_Name, whereClause, null) - .setParameters(new Object[]{getAD_PInstance_ID()}) + List list = new Query(getCtx(), MPInstancePara.Table_Name, whereClause, null) // @TODO: Review implications of using transaction + .setParameters(getAD_PInstance_ID()) .list(); // diff --git a/base/src/org/compiere/model/MPaySelection.java b/base/src/org/compiere/model/MPaySelection.java index fa215909f6..ea5d25de54 100644 --- a/base/src/org/compiere/model/MPaySelection.java +++ b/base/src/org/compiere/model/MPaySelection.java @@ -86,7 +86,7 @@ public class MPaySelection extends X_C_PaySelection //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 String whereClause = "C_PaySelection_ID=?"; List list = new Query(getCtx(), MPaySelectionLine.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getC_PaySelection_ID()}) + .setParameters(getC_PaySelection_ID()) .setOrderBy("Line") .list() ; diff --git a/base/src/org/compiere/model/MPayment.java b/base/src/org/compiere/model/MPayment.java index 5ffd0c99db..0cc66bb91a 100644 --- a/base/src/org/compiere/model/MPayment.java +++ b/base/src/org/compiere/model/MPayment.java @@ -22,12 +22,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Properties; -import java.util.logging.Level; import java.util.List; import java.util.Properties; +import java.util.logging.Level; import org.adempiere.exceptions.AdempiereException; 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 @@ -96,7 +94,7 @@ public final class MPayment extends X_C_Payment //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 String whereClause = "C_BPartner_ID=?"; List list = new Query(ctx, MPayment.Table_Name, whereClause, trxName) - .setParameters(new Object[]{C_BPartner_ID}) + .setParameters(C_BPartner_ID) .list(); // diff --git a/base/src/org/compiere/model/MProductBOM.java b/base/src/org/compiere/model/MProductBOM.java index 5cc6134a58..d7136f9c4c 100644 --- a/base/src/org/compiere/model/MProductBOM.java +++ b/base/src/org/compiere/model/MProductBOM.java @@ -16,15 +16,11 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.util.ArrayList; import java.util.List; import java.util.Properties; -import java.util.logging.Level; import org.compiere.util.CLogger; -import org.compiere.util.DB; 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 final String whereClause = "M_Product_ID=?"; - List list = new Query(ctx, I_M_Product_BOM.Table_Name, whereClause, trxName) - .setParameters(new Object[]{M_Product_ID}) + List list = new Query(ctx, MProductBOM.Table_Name, whereClause, trxName) + .setParameters(M_Product_ID) .setOrderBy("Line") .list(); diff --git a/base/src/org/compiere/model/Query.java b/base/src/org/compiere/model/Query.java index 263c38a9f1..20fdf9e9f4 100644 --- a/base/src/org/compiere/model/Query.java +++ b/base/src/org/compiere/model/Query.java @@ -132,6 +132,15 @@ public class Query 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 * @param parameters collection of parameters @@ -754,4 +763,5 @@ public class Query } return retValue; } // get_IDs + }