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

-- I am begining to use JUnit test and commit them as i go along also. Please advice where need be, or
-- If OK, i shall remove more SQLs from ADempiere :)
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883
This commit is contained in:
Redhuan D. Oon 2010-02-25 08:12:39 +00:00
parent 4b3d5de150
commit 8aaa009751
2 changed files with 52 additions and 22 deletions

View File

@ -26,6 +26,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.List;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.process.DocAction;
@ -91,28 +93,11 @@ public final class MPayment extends X_C_Payment
*/
public static MPayment[] getOfBPartner (Properties ctx, int C_BPartner_ID, String trxName)
{
ArrayList<MPayment> list = new ArrayList<MPayment>();
String sql = "SELECT * FROM C_Payment WHERE C_BPartner_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, C_BPartner_ID);
rs = pstmt.executeQuery();
while (rs.next())
list.add(new MPayment(ctx,rs, trxName));
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
String whereClause = "C_BPartner_ID=?";
List <MPayment> list = new Query(ctx, MPayment.Table_Name, whereClause, null)
.setParameters(new Object[]{C_BPartner_ID})
.list();
//
MPayment[] retValue = new MPayment[list.size()];

View File

@ -0,0 +1,45 @@
/******************************************************************************
* 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.MInvoice;
import org.compiere.model.MPayment;
import org.compiere.util.Env;
import test.AdempiereTestCase;
/**
* @author Teo Sarca, www.arhipac.ro // copied by red1 from MInvoiceTest
*/
public class MPaymentTest extends AdempiereTestCase
{
public static final int BPARTNER_Standard = 112;
@Override
protected void setUp() throws Exception
{
super.setUp();
assertEquals("Client is not GardenWorld", 11, Env.getAD_Client_ID(getCtx()));
}
public void testQuery() throws Exception
{
MPayment.getOfBPartner(getCtx(), BPARTNER_Standard, getTrxName());
MPayment[] payments = MPayment.getOfBPartner(getCtx(), BPARTNER_Standard, getTrxName());
assertTrue("Partner "+BPARTNER_Standard+" should have payments", payments.length > 0);
//testquery
}
}