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
This commit is contained in:
Redhuan D. Oon 2010-03-18 11:28:31 +00:00
parent afc5065246
commit af0d7d9cc4
1 changed files with 11 additions and 45 deletions

View File

@ -20,9 +20,8 @@ import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -37,6 +36,7 @@ import org.compiere.util.TimeUtil;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MAsset.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $ * @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 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) public static MAsset getFromShipment (Properties ctx, int M_InOutLine_ID, String trxName)
{ {
MAsset retValue = null; final String whereClause = I_A_Asset.COLUMNNAME_M_InOutLine_ID+"=?";
String sql = "SELECT * FROM A_Asset WHERE M_InOutLine_ID=?"; MAsset retValue = new Query(ctx,I_A_Asset.Table_Name,whereClause,trxName)
PreparedStatement pstmt = null; .setParameters(M_InOutLine_ID)
ResultSet rs = null; .first();
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;
}
return retValue; return retValue;
} // getFromShipment } // getFromShipment
@ -264,28 +247,11 @@ public class MAsset extends X_A_Asset
*/ */
public MAssetDelivery[] getDeliveries() public MAssetDelivery[] getDeliveries()
{ {
ArrayList<MAssetDelivery> list = new ArrayList<MAssetDelivery>(); final String whereClause = I_A_Asset_Delivery.COLUMNNAME_A_Asset_ID+"=?";
List<MAssetDelivery> list = new Query(getCtx(),I_A_Asset_Delivery.Table_Name,whereClause,get_TrxName())
String sql = "SELECT * FROM A_Asset_Delivery WHERE A_Asset_ID=? ORDER BY Created DESC"; .setParameters(getA_Asset_ID())
PreparedStatement pstmt = null; .setOrderBy("Created DESC")
ResultSet rs = null; .list();
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;
}
// //
MAssetDelivery[] retValue = new MAssetDelivery[list.size()]; MAssetDelivery[] retValue = new MAssetDelivery[list.size()];
list.toArray(retValue); list.toArray(retValue);