FR [ 2214883 ] Remove SQL code and Replace for Query

https://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
This commit is contained in:
teo_sarca 2009-04-14 07:44:47 +00:00
parent 7d5f9d8c71
commit aeaee5d1a0
1 changed files with 16 additions and 49 deletions

View File

@ -1,5 +1,5 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * 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 * * under the terms version 2 of the GNU General Public License as published *
@ -19,9 +19,10 @@ package org.compiere.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -31,6 +32,9 @@ import org.compiere.util.Env;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MInvoiceTax.java,v 1.5 2006/10/06 00:42:24 jjanke Exp $ * @version $Id: MInvoiceTax.java,v 1.5 2006/10/06 00:42:24 jjanke Exp $
*
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2214883 ] Remove SQL code and Replace for Query
*/ */
public class MInvoiceTax extends X_C_InvoiceTax public class MInvoiceTax extends X_C_InvoiceTax
{ {
@ -69,36 +73,9 @@ public class MInvoiceTax extends X_C_InvoiceTax
return null; return null;
} }
String sql = "SELECT * FROM C_InvoiceTax WHERE C_Invoice_ID=? AND C_Tax_ID=?"; retValue = new Query(line.getCtx(), Table_Name, "C_Invoice_ID=? AND C_Tax_ID=?", trxName)
PreparedStatement pstmt = null; .setParameters(new Object[]{line.getC_Invoice_ID(), C_Tax_ID})
try .firstOnly();
{
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, line.getC_Invoice_ID());
pstmt.setInt (2, C_Tax_ID);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
{
retValue = new MInvoiceTax (line.getCtx(), 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;
}
if (retValue != null) if (retValue != null)
{ {
retValue.set_TrxName(trxName); retValue.set_TrxName(trxName);
@ -212,12 +189,13 @@ public class MInvoiceTax extends X_C_InvoiceTax
+ " INNER JOIN C_Invoice i ON (il.C_Invoice_ID=i.C_Invoice_ID) " + " INNER JOIN C_Invoice i ON (il.C_Invoice_ID=i.C_Invoice_ID) "
+ "WHERE il.C_Invoice_ID=? AND il.C_Tax_ID=?"; + "WHERE il.C_Invoice_ID=? AND il.C_Tax_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getC_Invoice_ID()); pstmt.setInt (1, getC_Invoice_ID());
pstmt.setInt (2, getC_Tax_ID()); pstmt.setInt (2, getC_Tax_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
// BaseAmt // BaseAmt
@ -240,27 +218,16 @@ public class MInvoiceTax extends X_C_InvoiceTax
// //
taxAmt = taxAmt.add(amt); taxAmt = taxAmt.add(amt);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (SQLException e)
{ {
log.log(Level.SEVERE, "setTaxBaseAmt", e); throw new DBException(e, sql);
taxBaseAmt = null;
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
} }
catch (Exception e)
{
pstmt = null;
}
if (taxBaseAmt == null)
return false;
// Calculate Tax // Calculate Tax
if (documentLevel || taxAmt.signum() == 0) if (documentLevel || taxAmt.signum() == 0)