MPriceList:
BF [ 2073484 ] MPriceList.getDefault is not working correctly BF [ 1874419 ] JDBC Statement not close in a finally block * organized imports
This commit is contained in:
parent
fa481254d7
commit
c3750a2984
|
@ -16,20 +16,29 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.*;
|
import java.math.BigDecimal;
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.sql.Timestamp;
|
||||||
import java.util.logging.*;
|
import java.util.Iterator;
|
||||||
import org.compiere.util.*;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.util.CCache;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Price List Model
|
* Price List Model
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: MPriceList.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
* @version $Id: MPriceList.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>BF [ 2073484 ] MPriceList.getDefault is not working correctly
|
||||||
*/
|
*/
|
||||||
public class MPriceList extends X_M_PriceList
|
public class MPriceList extends X_M_PriceList
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Price List (cached)
|
* Get Price List (cached)
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -60,52 +69,29 @@ public class MPriceList extends X_M_PriceList
|
||||||
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
||||||
MPriceList retValue = null;
|
MPriceList retValue = null;
|
||||||
// Search for it in cache
|
// Search for it in cache
|
||||||
Iterator it = s_cache.values().iterator();
|
Iterator<MPriceList> it = s_cache.values().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
retValue = (MPriceList)it.next();
|
retValue = it.next();
|
||||||
if (retValue.isDefault() && retValue.getAD_Client_ID() == AD_Client_ID)
|
if (retValue.isDefault()
|
||||||
|
&& retValue.getAD_Client_ID() == AD_Client_ID
|
||||||
|
&& retValue.isSOPriceList() == IsSOPriceList)
|
||||||
|
{
|
||||||
return retValue;
|
return retValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get from DB **/
|
// Get from DB
|
||||||
retValue = null;
|
final String whereClause = "AD_Client_ID=? AND IsDefault=? AND IsSOPriceList=?";
|
||||||
String sql = "SELECT * FROM M_PriceList "
|
retValue = new Query(ctx, Table_Name, whereClause, null)
|
||||||
+ "WHERE AD_Client_ID=?"
|
.setParameters(new Object[]{AD_Client_ID, "Y", IsSOPriceList ? "Y" : "N"})
|
||||||
+ " AND IsDefault='Y'"
|
.setOrderBy("M_PriceList_ID")
|
||||||
+ " AND IsSOPriceList='Y'"
|
.first();
|
||||||
+ "ORDER BY M_PriceList_ID";
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
|
||||||
pstmt.setInt(1, AD_Client_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
retValue = new MPriceList (ctx, rs, null);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
// Return value
|
// Return value
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
Integer key = new Integer (retValue.getM_PriceList_ID());
|
s_cache.put(retValue.get_ID(), retValue);
|
||||||
s_cache.put(key, retValue);
|
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getDefault
|
} // getDefault
|
||||||
|
@ -134,10 +120,8 @@ public class MPriceList extends X_M_PriceList
|
||||||
return pl.getPricePrecisionInt();
|
return pl.getPricePrecisionInt();
|
||||||
} // getPricePrecision
|
} // getPricePrecision
|
||||||
|
|
||||||
/** Static Logger */
|
|
||||||
private static CLogger s_log = CLogger.getCLogger(MPriceList.class);
|
|
||||||
/** Cache of Price Lists */
|
/** Cache of Price Lists */
|
||||||
private static CCache<Integer,MPriceList> s_cache = new CCache<Integer,MPriceList>("M_PriceList", 5);
|
private static CCache<Integer,MPriceList> s_cache = new CCache<Integer,MPriceList>(Table_Name, 5);
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
@ -190,40 +174,13 @@ public class MPriceList extends X_M_PriceList
|
||||||
if (m_plv != null && m_plv.getValidFrom().before(valid))
|
if (m_plv != null && m_plv.getValidFrom().before(valid))
|
||||||
return m_plv;
|
return m_plv;
|
||||||
|
|
||||||
String sql = "SELECT * FROM M_PriceList_Version "
|
final String whereClause = "M_PriceList_ID=? AND TRUNC(ValidFrom)<=? AND IsActive=?";
|
||||||
+ "WHERE M_PriceList_ID=?"
|
m_plv = new Query(getCtx(), MPriceListVersion.Table_Name, whereClause, get_TrxName())
|
||||||
+ " AND TRUNC(ValidFrom)<=? AND IsActive='Y'"
|
.setParameters(new Object[]{getM_PriceList_ID(), valid, "Y"})
|
||||||
+ "ORDER BY ValidFrom DESC";
|
.setOrderBy("ValidFrom DESC")
|
||||||
PreparedStatement pstmt = null;
|
.first();
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
|
||||||
pstmt.setInt(1, getM_PriceList_ID());
|
|
||||||
pstmt.setTimestamp(2, valid);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
m_plv = new MPriceListVersion (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;
|
|
||||||
}
|
|
||||||
if (m_plv == null)
|
if (m_plv == null)
|
||||||
log.warning("None found M_PriceList_ID="
|
log.warning("None found M_PriceList_ID=" + getM_PriceList_ID() + " - " + valid);
|
||||||
+ getM_PriceList_ID() + " - " + valid + " - " + sql);
|
|
||||||
else
|
else
|
||||||
log.fine(m_plv.toString());
|
log.fine(m_plv.toString());
|
||||||
return m_plv;
|
return m_plv;
|
||||||
|
@ -250,7 +207,7 @@ public class MPriceList extends X_M_PriceList
|
||||||
*/
|
*/
|
||||||
public void setPricePrecision (int PricePrecision)
|
public void setPricePrecision (int PricePrecision)
|
||||||
{
|
{
|
||||||
setPricePrecision (new BigDecimal(PricePrecision));
|
setPricePrecision (BigDecimal.valueOf(PricePrecision));
|
||||||
} // setPricePrecision
|
} // setPricePrecision
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue