diff --git a/base/src/org/compiere/model/MProject.java b/base/src/org/compiere/model/MProject.java index f42309ac3a..fc0f8a7d5e 100644 --- a/base/src/org/compiere/model/MProject.java +++ b/base/src/org/compiere/model/MProject.java @@ -21,6 +21,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -204,33 +205,12 @@ public class MProject extends X_C_Project */ public MProjectLine[] getLines() { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_ProjectLine WHERE C_Project_ID=? ORDER BY Line"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, getC_Project_ID()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - list.add(new MProjectLine (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (SQLException ex) - { - log.log(Level.SEVERE, sql, ex); - } - try - { - if (pstmt != null) - pstmt.close(); - } - catch (SQLException ex1) - { - } - pstmt = null; + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 + String whereClause = "C_Project_ID=?"; + List list = new Query(getCtx(), I_C_ProjectLine.Table_Name, whereClause, get_TrxName()) + .setParameters(getC_Project_ID()) + .setOrderBy("Line") + .list(); // MProjectLine[] retValue = new MProjectLine[list.size()]; list.toArray(retValue); @@ -243,33 +223,12 @@ public class MProject extends X_C_Project */ public MProjectIssue[] getIssues() { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_ProjectIssue WHERE C_Project_ID=? ORDER BY Line"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, getC_Project_ID()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - list.add(new MProjectIssue (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (SQLException ex) - { - log.log(Level.SEVERE, sql, ex); - } - try - { - if (pstmt != null) - pstmt.close(); - } - catch (SQLException ex1) - { - } - pstmt = null; + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 + String whereClause = "C_Project_ID=?"; + List list = new Query(getCtx(), I_C_ProjectIssue.Table_Name, whereClause, get_TrxName()) + .setParameters(getC_Project_ID()) + .setOrderBy("Line") + .list(); // MProjectIssue[] retValue = new MProjectIssue[list.size()]; list.toArray(retValue); @@ -282,33 +241,12 @@ public class MProject extends X_C_Project */ public MProjectPhase[] getPhases() { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_ProjectPhase WHERE C_Project_ID=? ORDER BY SeqNo"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, getC_Project_ID()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - list.add(new MProjectPhase (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (SQLException ex) - { - log.log(Level.SEVERE, sql, ex); - } - try - { - if (pstmt != null) - pstmt.close(); - } - catch (SQLException ex1) - { - } - pstmt = null; + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 + String whereClause = "C_Project_ID=?"; + List list = new Query(getCtx(), I_C_ProjectPhase.Table_Name, whereClause, get_TrxName()) + .setParameters(getC_Project_ID()) + .setOrderBy("SeqNo") + .list(); // MProjectPhase[] retValue = new MProjectPhase[list.size()]; list.toArray(retValue); diff --git a/extend/src/test/functional/MProjectTest.java b/extend/src/test/functional/MProjectTest.java new file mode 100644 index 0000000000..842351ad04 --- /dev/null +++ b/extend/src/test/functional/MProjectTest.java @@ -0,0 +1,55 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package test.functional; + +import org.compiere.model.MProject; +import org.compiere.model.MProjectIssue; +import org.compiere.model.MProjectLine; +import org.compiere.model.MProjectPhase; +import org.compiere.util.Env; + +import test.AdempiereTestCase; + +/** + * @author Teo Sarca, www.arhipac.ro // used by red1 + */ +public class MProjectTest extends AdempiereTestCase +{ + @Override + protected void setUp() throws Exception + { + super.setUp(); + assertEquals("Client is not GardenWorld", 11, Env.getAD_Client_ID(getCtx())); + } + + public void testQuery() throws Exception + { + MProject proj = new MProject(getCtx(),101,null); + { + //test ProjectLines + MProjectLine[] lines = proj.getLines(); + assertTrue("There should be lines in this project", lines.length > 0); + } + { + //test ProjectIssue + MProjectIssue[] issues = proj.getIssues(); + assertTrue("There are no issues in this project", issues.length == 0); + } + { + //test ProjectPhase + MProjectPhase[] lines = proj.getPhases(); + assertTrue("There are no phases in this project", lines.length == 0); + } + } +}