From af0d7d9cc4c3dd4123b1d6f1fdb23f6e71767685 Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Thu, 18 Mar 2010 11:28:31 +0000 Subject: [PATCH] FR: [ 2214883 ] Remove SQL code and Replace for Query -- JUnit test in next commit (no failures) Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883 --- base/src/org/compiere/model/MAsset.java | 56 +++++-------------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/base/src/org/compiere/model/MAsset.java b/base/src/org/compiere/model/MAsset.java index 386dbdb521..68bbcea7ba 100644 --- a/base/src/org/compiere/model/MAsset.java +++ b/base/src/org/compiere/model/MAsset.java @@ -20,9 +20,8 @@ import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; -import java.util.ArrayList; +import java.util.List; import java.util.Properties; -import java.util.logging.Level; import javax.servlet.http.HttpServletRequest; @@ -37,6 +36,7 @@ import org.compiere.util.TimeUtil; * * @author Jorg Janke * @version $Id: MAsset.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $ + * @author red1 - FR: [ 2214883 ] Remove SQL code and Replace for Query */ public class MAsset extends X_A_Asset { @@ -55,27 +55,10 @@ public class MAsset extends X_A_Asset */ public static MAsset getFromShipment (Properties ctx, int M_InOutLine_ID, String trxName) { - MAsset retValue = null; - String sql = "SELECT * FROM A_Asset WHERE M_InOutLine_ID=?"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt (1, M_InOutLine_ID); - rs = pstmt.executeQuery (); - if (rs.next ()) - retValue = new MAsset (ctx, rs, trxName); - } - catch (Exception e) - { - s_log.log (Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } + final String whereClause = I_A_Asset.COLUMNNAME_M_InOutLine_ID+"=?"; + MAsset retValue = new Query(ctx,I_A_Asset.Table_Name,whereClause,trxName) + .setParameters(M_InOutLine_ID) + .first(); return retValue; } // getFromShipment @@ -264,28 +247,11 @@ public class MAsset extends X_A_Asset */ public MAssetDelivery[] getDeliveries() { - ArrayList list = new ArrayList(); - - String sql = "SELECT * FROM A_Asset_Delivery WHERE A_Asset_ID=? ORDER BY Created DESC"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, getA_Asset_ID()); - rs = pstmt.executeQuery(); - while (rs.next()) - list.add(new MAssetDelivery(getCtx(), rs, get_TrxName())); - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } + final String whereClause = I_A_Asset_Delivery.COLUMNNAME_A_Asset_ID+"=?"; + List list = new Query(getCtx(),I_A_Asset_Delivery.Table_Name,whereClause,get_TrxName()) + .setParameters(getA_Asset_ID()) + .setOrderBy("Created DESC") + .list(); // MAssetDelivery[] retValue = new MAssetDelivery[list.size()]; list.toArray(retValue);