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

-- JUnit test included (no failures). Please clean up M_BOM test record afterwards.
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Redhuan D. Oon 2010-02-26 07:07:32 +00:00
parent 8cd9f28474
commit 7cd1ead853
2 changed files with 25 additions and 32 deletions

View File

@ -16,15 +16,12 @@
*****************************************************************************/ *****************************************************************************/
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.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Msg; import org.compiere.util.Msg;
/** /**
@ -69,36 +66,13 @@ public class MBOM extends X_M_BOM
public static MBOM[] getOfProduct (Properties ctx, int M_Product_ID, public static MBOM[] getOfProduct (Properties ctx, int M_Product_ID,
String trxName, String whereClause) String trxName, String whereClause)
{ {
ArrayList<MBOM> list = new ArrayList<MBOM>(); //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String sql = "SELECT * FROM M_BOM WHERE M_Product_ID=?"; String sql = "M_Product_ID = ?";
if (whereClause != null && whereClause.length() > 0) if (whereClause != null && whereClause.length() > 0)
sql += " AND " + whereClause; sql += " AND " + whereClause;
PreparedStatement pstmt = null; List <MPayment> list = new Query(ctx, I_M_BOM.Table_Name, sql, trxName)
try .setParameters(M_Product_ID)
{ .list();
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, M_Product_ID);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MBOM (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MBOM[] retValue = new MBOM[list.size ()]; MBOM[] retValue = new MBOM[list.size ()];
list.toArray (retValue); list.toArray (retValue);

View File

@ -13,6 +13,8 @@
*****************************************************************************/ *****************************************************************************/
package test.functional; package test.functional;
import org.compiere.model.MBOM;
import org.compiere.model.MLocation;
import org.compiere.model.MProductBOM; import org.compiere.model.MProductBOM;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -36,5 +38,22 @@ public class MProductBOMTest extends AdempiereTestCase
MProductBOM[] lines = MProductBOM.getBOMLines(getCtx(), 145, getTrxName()); MProductBOM[] lines = MProductBOM.getBOMLines(getCtx(), 145, getTrxName());
assertTrue("ProductBOM should have lines", lines.length > 0); assertTrue("ProductBOM should have lines", lines.length > 0);
} }
private MBOM bom = null;
public void testBOMCreation() {
bom = new MBOM(getCtx(), 0, getTrxName());
// BOM load test case of qualified bom parent for testing MBOM.getOfProduct
bom.setM_Product_ID(134);
bom.setBOMType("A");
bom.setName("PatioTable");
boolean saveResult = bom.save(); //
assertTrue("MBOM.save()", saveResult);
try {
commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
} }