FR [ 2093551 ] Refactor/Add org.compiere.model.MProduct.getCostingLevel
FR [ 2093569 ] Refactor/Add org.compiere.model.MProduct.getCostingMethod * forget to commit: MProductCategoryAcct.get should cache objects to speed things up
This commit is contained in:
parent
dae6866242
commit
cb0e8a06c7
|
@ -16,11 +16,10 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.util.Properties;
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
import org.compiere.util.*;
|
import org.compiere.util.CCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product Category Account Model
|
* Product Category Account Model
|
||||||
|
@ -29,6 +28,12 @@ import org.compiere.util.*;
|
||||||
*/
|
*/
|
||||||
public class MProductCategoryAcct extends X_M_Product_Category_Acct
|
public class MProductCategoryAcct extends X_M_Product_Category_Acct
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** Static cache */
|
||||||
|
private static CCache<String, MProductCategoryAcct>
|
||||||
|
s_cache = new CCache<String, MProductCategoryAcct>(Table_Name, 40, 5);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Category Acct
|
* Get Category Acct
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -40,41 +45,21 @@ public class MProductCategoryAcct extends X_M_Product_Category_Acct
|
||||||
public static MProductCategoryAcct get (Properties ctx,
|
public static MProductCategoryAcct get (Properties ctx,
|
||||||
int M_Product_Category_ID, int C_AcctSchema_ID, String trxName)
|
int M_Product_Category_ID, int C_AcctSchema_ID, String trxName)
|
||||||
{
|
{
|
||||||
MProductCategoryAcct retValue = null;
|
String key = ""+M_Product_Category_ID+"#"+C_AcctSchema_ID;
|
||||||
PreparedStatement pstmt = null;
|
MProductCategoryAcct acct = s_cache.get(key);
|
||||||
String sql = "SELECT * FROM M_Product_Category_Acct "
|
if (acct != null)
|
||||||
+ "WHERE M_Product_Category_ID=? AND C_AcctSchema_ID=?";
|
return acct;
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, trxName);
|
|
||||||
pstmt.setInt (1, M_Product_Category_ID);
|
|
||||||
pstmt.setInt (2, C_AcctSchema_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
if (rs.next ())
|
|
||||||
retValue = new MProductCategoryAcct (ctx, 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;
|
|
||||||
}
|
|
||||||
return retValue;
|
|
||||||
} // get
|
|
||||||
|
|
||||||
/** Logger */
|
final String whereClause = "M_Product_Category_ID=? AND C_AcctSchema_ID=?";
|
||||||
private static CLogger s_log = CLogger.getCLogger (MProductCategoryAcct.class);
|
acct = new Query(ctx, Table_Name, whereClause, trxName)
|
||||||
|
.setParameters(new Object[]{M_Product_Category_ID, C_AcctSchema_ID})
|
||||||
|
.first();
|
||||||
|
if (acct != null)
|
||||||
|
{
|
||||||
|
s_cache.put(key, acct);
|
||||||
|
}
|
||||||
|
return acct;
|
||||||
|
} // get
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Standard Constructor
|
* Standard Constructor
|
||||||
|
|
Loading…
Reference in New Issue