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

-- JUnit test included (no failures)
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Redhuan D. Oon 2010-02-26 11:39:31 +00:00
parent dd7b9b1341
commit 8df91cee04
2 changed files with 74 additions and 81 deletions

View File

@ -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<MProjectLine> list = new ArrayList<MProjectLine>();
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 <MProjectLine> 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<MProjectIssue> list = new ArrayList<MProjectIssue>();
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 <MProjectIssue> 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<MProjectPhase> list = new ArrayList<MProjectPhase>();
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 <MProjectPhase> 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);

View File

@ -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);
}
}
}