IDEMPIERE-4895 Product Cost - Valid Combination Caching (#805)

This commit is contained in:
igorpojzl 2021-08-03 07:00:46 +02:00 committed by GitHub
parent 1fb4067c01
commit 2cee3ff007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 86 additions and 65 deletions

View File

@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -53,6 +54,12 @@ public class ProductCost
m_trxName = trxName;
} // 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 */
private int m_M_Product_ID = 0;
/** ASI */
@ -182,6 +189,10 @@ public class ProductCost
if (m_M_Product_ID == 0)
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
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, " // 5..6
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct," // 7..8
@ -194,7 +205,7 @@ public class ProductCost
+ "FROM M_Product_Acct "
+ "WHERE M_Product_ID=? AND C_AcctSchema_ID=?";
//
int validCombination_ID = 0;
validCombination_ID = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -214,6 +225,9 @@ public class ProductCost
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (validCombination_ID != 0)
s_valid_comb_cache.put(key, validCombination_ID);
}
if (validCombination_ID == 0)
return null;
return MAccount.get(as.getCtx(), validCombination_ID);
@ -231,6 +245,10 @@ public class ProductCost
if (AcctType < ACCTTYPE_P_Revenue || AcctType > ACCTTYPE_P_LandedCostClearing)
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, "
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, "
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct, "
@ -245,7 +263,7 @@ public class ProductCost
+ " AND pca.C_AcctSchema_ID=? "
+ "ORDER BY pc.IsDefault DESC, pc.Created";
//
int validCombination_ID = 0;
validCombination_ID = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -264,6 +282,9 @@ public class ProductCost
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (validCombination_ID != 0)
s_default_valid_comb_cache.put(key, validCombination_ID);
}
if (validCombination_ID == 0)
return null;
return MAccount.get(as.getCtx(), validCombination_ID);