From 7cd1ead853e88576d23da559f1ebdbe7e72649e1 Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Fri, 26 Feb 2010 07:07:32 +0000 Subject: [PATCH] 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 --- base/src/org/compiere/model/MBOM.java | 38 +++---------------- .../src/test/functional/MProductBOMTest.java | 19 ++++++++++ 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/base/src/org/compiere/model/MBOM.java b/base/src/org/compiere/model/MBOM.java index a97741ae75..26ba6947ea 100644 --- a/base/src/org/compiere/model/MBOM.java +++ b/base/src/org/compiere/model/MBOM.java @@ -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 list = new ArrayList(); - 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 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); diff --git a/extend/src/test/functional/MProductBOMTest.java b/extend/src/test/functional/MProductBOMTest.java index fbaad90298..112a90ba73 100644 --- a/extend/src/test/functional/MProductBOMTest.java +++ b/extend/src/test/functional/MProductBOMTest.java @@ -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()); + } + } }