FR [ 2214883 ] Remove SQL code and Replace for Query
https://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
(integrate red1 changes)
This commit is contained in:
teo_sarca 2009-04-14 08:34:06 +00:00
parent 1a647462fd
commit 75ab64f977
1 changed files with 41 additions and 121 deletions

View File

@ -17,15 +17,11 @@
package org.compiere.model; package org.compiere.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.ArrayList; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.TimeUtil; import org.compiere.util.TimeUtil;
@ -34,6 +30,7 @@ import org.compiere.util.TimeUtil;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MTax.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $ * @version $Id: MTax.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
* red1 - FR: [ 2214883 ] Remove SQL code and Replace for Query
*/ */
public class MTax extends X_C_Tax public class MTax extends X_C_Tax
{ {
@ -51,51 +48,23 @@ public class MTax extends X_C_Tax
public static MTax[] getAll (Properties ctx) public static MTax[] getAll (Properties ctx)
{ {
int AD_Client_ID = Env.getAD_Client_ID(ctx); int AD_Client_ID = Env.getAD_Client_ID(ctx);
Integer key = new Integer (AD_Client_ID); MTax[] retValue = (MTax[])s_cacheAll.get(AD_Client_ID);
MTax[] retValue = (MTax[])s_cacheAll.get(key);
if (retValue != null) if (retValue != null)
return retValue; return retValue;
// Create it // Create it
String sql = "SELECT * FROM C_Tax WHERE AD_Client_ID=?" //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
+ "ORDER BY C_Country_ID, C_Region_ID, To_Country_ID, To_Region_ID"; String whereClause = "AD_Client_ID=?";
ArrayList<MTax> list = new ArrayList<MTax>(); List<MTax> list = new Query(ctx, MTax.Table_Name, whereClause, null)
PreparedStatement pstmt = null; .setParameters(new Object[]{AD_Client_ID})
try .setOrderBy("C_Country_ID, C_Region_ID, To_Country_ID, To_Region_ID")
.list();
for (MTax tax : list)
{ {
pstmt = DB.prepareStatement (sql, null); s_cache.put(tax.get_ID(), tax);
pstmt.setInt (1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
MTax tax = new MTax(ctx, rs, null);
s_cache.put (new Integer(tax.getC_Tax_ID()), tax);
list.add (tax);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
} }
try retValue = list.toArray(new MTax[list.size()]);
{ s_cacheAll.put(AD_Client_ID, retValue);
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
// Create Array
retValue = new MTax[list.size ()];
list.toArray (retValue);
//
s_cacheAll.put(key, retValue);
return retValue; return retValue;
} // getAll } // getAll
@ -119,12 +88,9 @@ public class MTax extends X_C_Tax
} // get } // get
/** Cache */ /** Cache */
private static CCache<Integer,MTax> s_cache = new CCache<Integer,MTax>("C_Tax", 5); private static CCache<Integer,MTax> s_cache = new CCache<Integer,MTax>(Table_Name, 5);
/** Cache of Client */ /** Cache of Client */
private static CCache<Integer,MTax[]> s_cacheAll = new CCache<Integer,MTax[]>("C_Tax", 5); private static CCache<Integer,MTax[]> s_cacheAll = new CCache<Integer,MTax[]>(Table_Name, 5);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MTax.class);
/************************************************************************** /**************************************************************************
* Standard Constructor * Standard Constructor
@ -199,79 +165,37 @@ public class MTax extends X_C_Tax
if (m_childTaxes != null && !requery) if (m_childTaxes != null && !requery)
return m_childTaxes; return m_childTaxes;
// //
String sql = "SELECT * FROM C_Tax WHERE Parent_Tax_ID=?"; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
ArrayList<MTax> list = new ArrayList<MTax>(); String whereClause = COLUMNNAME_Parent_Tax_ID+"=?";
PreparedStatement pstmt = null; List<MTax> list = new Query(getCtx(), MTax.Table_Name, whereClause, get_TrxName())
try .setParameters(new Object[]{getC_Tax_ID()})
{ .list();
pstmt = DB.prepareStatement (sql, get_TrxName()); //red1 - end -
pstmt.setInt (1, getC_Tax_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MTax(getCtx(), rs, get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
m_childTaxes = new MTax[list.size ()]; m_childTaxes = new MTax[list.size ()];
list.toArray (m_childTaxes); list.toArray (m_childTaxes);
return m_childTaxes; return m_childTaxes;
} // getChildTaxes } // getChildTaxes
/** /**
* Get Postal Qualifiers * Get Postal Qualifiers
* @param requery requery * @param requery requery
* @return array of postal codes * @return array of postal codes
*/ */
public MTaxPostal[] getPostals (boolean requery) public MTaxPostal[] getPostals (boolean requery)
{ {
if (m_postals != null && !requery) if (m_postals != null && !requery)
return m_postals; return m_postals;
String sql = "SELECT * FROM C_TaxPostal WHERE IsActive='Y' AND C_Tax_ID=? ORDER BY Postal, Postal_To"; //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1
ArrayList<MTaxPostal> list = new ArrayList<MTaxPostal>(); String whereClause = MTaxPostal.COLUMNNAME_C_Tax_ID+"=?";
PreparedStatement pstmt = null; List<MTaxPostal> list = new Query(getCtx(), MTaxPostal.Table_Name, whereClause, get_TrxName())
try .setParameters(new Object[]{getC_Tax_ID()})
{ .setOnlyActiveRecords(true)
pstmt = DB.prepareStatement (sql, get_TrxName()); .setOrderBy(MTaxPostal.COLUMNNAME_Postal+", "+MTaxPostal.COLUMNNAME_Postal_To)
pstmt.setInt (1, getC_Tax_ID()); .list();
ResultSet rs = pstmt.executeQuery (); //red1 - end -
while (rs.next ())
{
MTaxPostal taxpostal = new MTaxPostal(getCtx(), rs, null);
list.add (taxpostal);
}
rs.close ();
pstmt.close ();
pstmt = null;
} catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
} catch (Exception e)
{
pstmt = null;
}
if (list.size() > 0) { if (list.size() > 0) {
m_postals = new MTaxPostal[list.size ()]; m_postals = new MTaxPostal[list.size ()];
list.toArray (m_postals); list.toArray (m_postals);
@ -280,8 +204,8 @@ public class MTax extends X_C_Tax
} // getPostals } // getPostals
/** /**
* Do we have Postal Codes * Do we have Postal Codes
* @return true if postal codes exist * @return true if postal codes exist
*/ */
public boolean isPostal() public boolean isPostal()
{ {
@ -292,18 +216,14 @@ public class MTax extends X_C_Tax
} // isPostal } // isPostal
/** /**
* Is Zero Tax * Is Zero Tax
* @return true if tax rate is 0 * @return true if tax rate is 0
*/ */
public boolean isZeroTax() public boolean isZeroTax()
{ {
return Env.ZERO.compareTo(getRate()) == 0; return getRate().signum() == 0;
} // isZeroTax } // isZeroTax
/**
* String Representation
* @return info
*/
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer("MTax["); StringBuffer sb = new StringBuffer("MTax[");