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;
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.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
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,
String trxName, String whereClause)
{
ArrayList<MBOM> list = new ArrayList<MBOM>();
String sql = "SELECT * FROM M_BOM WHERE M_Product_ID=?";
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String sql = "M_Product_ID = ?";
if (whereClause != null && whereClause.length() > 0)
sql += " AND " + whereClause;
PreparedStatement pstmt = null;
try
{
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;
}
List <MPayment> list = new Query(ctx, I_M_BOM.Table_Name, sql, trxName)
.setParameters(M_Product_ID)
.list();
MBOM[] retValue = new MBOM[list.size ()];
list.toArray (retValue);

View File

@ -13,6 +13,8 @@
*****************************************************************************/
package test.functional;
import org.compiere.model.MBOM;
import org.compiere.model.MLocation;
import org.compiere.model.MProductBOM;
import org.compiere.util.Env;
@ -36,5 +38,22 @@ public class MProductBOMTest extends AdempiereTestCase
MProductBOM[] lines = MProductBOM.getBOMLines(getCtx(), 145, getTrxName());
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());
}
}
}