IDEMPIERE-4895 Product Cost - Valid Combination Caching (#805)
This commit is contained in:
parent
1fb4067c01
commit
2cee3ff007
|
|
@ -23,6 +23,7 @@ import java.sql.SQLException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.util.CCache;
|
||||||
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;
|
||||||
|
|
@ -53,6 +54,12 @@ public class ProductCost
|
||||||
m_trxName = trxName;
|
m_trxName = trxName;
|
||||||
} // ProductCost
|
} // ProductCost
|
||||||
|
|
||||||
|
/** Valid Combination Cache */
|
||||||
|
private static CCache<String, Integer> s_valid_comb_cache = new CCache<String, Integer>("ProductCost_ValidCombination", 40);
|
||||||
|
|
||||||
|
/** Default Valid Compbination Cache */
|
||||||
|
private static CCache<String, Integer> s_default_valid_comb_cache = new CCache<String, Integer>("ProductCost_DefaultValidCombination", 40);
|
||||||
|
|
||||||
/** The ID */
|
/** The ID */
|
||||||
private int m_M_Product_ID = 0;
|
private int m_M_Product_ID = 0;
|
||||||
/** ASI */
|
/** ASI */
|
||||||
|
|
@ -182,6 +189,10 @@ public class ProductCost
|
||||||
if (m_M_Product_ID == 0)
|
if (m_M_Product_ID == 0)
|
||||||
return getAccountDefault(AcctType, as);
|
return getAccountDefault(AcctType, as);
|
||||||
|
|
||||||
|
String key = m_M_Product_ID + "_" + as.getC_AcctSchema_ID() + "_" + AcctType;
|
||||||
|
Integer validCombination_ID = s_valid_comb_cache.get(key);
|
||||||
|
|
||||||
|
if(validCombination_ID == null || validCombination_ID == 0) {
|
||||||
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, " // 1..4
|
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, " // 1..4
|
||||||
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, " // 5..6
|
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, " // 5..6
|
||||||
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct," // 7..8
|
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct," // 7..8
|
||||||
|
|
@ -194,7 +205,7 @@ public class ProductCost
|
||||||
+ "FROM M_Product_Acct "
|
+ "FROM M_Product_Acct "
|
||||||
+ "WHERE M_Product_ID=? AND C_AcctSchema_ID=?";
|
+ "WHERE M_Product_ID=? AND C_AcctSchema_ID=?";
|
||||||
//
|
//
|
||||||
int validCombination_ID = 0;
|
validCombination_ID = 0;
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
|
|
@ -214,6 +225,9 @@ public class ProductCost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
if (validCombination_ID != 0)
|
||||||
|
s_valid_comb_cache.put(key, validCombination_ID);
|
||||||
|
}
|
||||||
if (validCombination_ID == 0)
|
if (validCombination_ID == 0)
|
||||||
return null;
|
return null;
|
||||||
return MAccount.get(as.getCtx(), validCombination_ID);
|
return MAccount.get(as.getCtx(), validCombination_ID);
|
||||||
|
|
@ -231,6 +245,10 @@ public class ProductCost
|
||||||
if (AcctType < ACCTTYPE_P_Revenue || AcctType > ACCTTYPE_P_LandedCostClearing)
|
if (AcctType < ACCTTYPE_P_Revenue || AcctType > ACCTTYPE_P_LandedCostClearing)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
String key = as.getC_AcctSchema_ID()+ "_" + AcctType;
|
||||||
|
Integer validCombination_ID = s_default_valid_comb_cache.get(key);
|
||||||
|
|
||||||
|
if(validCombination_ID == null || validCombination_ID == 0) {
|
||||||
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, "
|
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, "
|
||||||
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, "
|
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, "
|
||||||
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct, "
|
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct, "
|
||||||
|
|
@ -245,7 +263,7 @@ public class ProductCost
|
||||||
+ " AND pca.C_AcctSchema_ID=? "
|
+ " AND pca.C_AcctSchema_ID=? "
|
||||||
+ "ORDER BY pc.IsDefault DESC, pc.Created";
|
+ "ORDER BY pc.IsDefault DESC, pc.Created";
|
||||||
//
|
//
|
||||||
int validCombination_ID = 0;
|
validCombination_ID = 0;
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
|
|
@ -264,6 +282,9 @@ public class ProductCost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
if (validCombination_ID != 0)
|
||||||
|
s_default_valid_comb_cache.put(key, validCombination_ID);
|
||||||
|
}
|
||||||
if (validCombination_ID == 0)
|
if (validCombination_ID == 0)
|
||||||
return null;
|
return null;
|
||||||
return MAccount.get(as.getCtx(), validCombination_ID);
|
return MAccount.get(as.getCtx(), validCombination_ID);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue