diff --git a/org.adempiere.base/src/org/compiere/model/MRefList.java b/org.adempiere.base/src/org/compiere/model/MRefList.java index 4aa7e9f4e1..596a2fe582 100644 --- a/org.adempiere.base/src/org/compiere/model/MRefList.java +++ b/org.adempiere.base/src/org/compiere/model/MRefList.java @@ -28,6 +28,8 @@ import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Util; import org.compiere.util.ValueNamePair; +import org.idempiere.cache.ImmutablePOCache; +import org.idempiere.cache.ImmutablePOSupport; /** * Reference List Value @@ -39,13 +41,16 @@ import org.compiere.util.ValueNamePair; *
  • BF [ 1748449 ] Info Account - Posting Type is not translated *
  • FR [ 2694043 ] Query. first/firstOnly usage best practice */ -public class MRefList extends X_AD_Ref_List +public class MRefList extends X_AD_Ref_List implements ImmutablePOSupport { /** * */ private static final long serialVersionUID = 2342762307330992884L; + /** RefList Value Cache */ + private static ImmutablePOCache s_ref_value_cache = new ImmutablePOCache(Table_Name, 40); + /** * Get Reference List * @param ctx context @@ -54,12 +59,47 @@ public class MRefList extends X_AD_Ref_List * @param trxName transaction * @return List or null */ - public static MRefList get (Properties ctx, int AD_Reference_ID, String Value, String trxName) + public static synchronized MRefList get (Properties ctx, int AD_Reference_ID, String Value, String trxName) { - return new Query(ctx, Table_Name, "AD_Reference_ID=? AND Value=?", trxName) + StringBuilder sb = new StringBuilder(AD_Reference_ID) + .append("|") + .append(Value); + String key = sb.toString(); + MRefList rl = s_ref_value_cache.get(ctx, key, e -> new MRefList(ctx, e)); + if (rl == null) + { + rl = new Query(ctx, Table_Name, "AD_Reference_ID=? AND Value=?", trxName) .setParameters(AD_Reference_ID, Value) - .firstOnly(); + .first(); + if (rl != null) + { + s_ref_value_cache.put(key, rl, e -> new MRefList(Env.getCtx(), e)); + } + } + return rl; } // get + + /** + * + * @param ctx + * @param copy + */ + public MRefList(Properties ctx, MRefList copy) + { + this(ctx, copy, (String) null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MRefList(Properties ctx, MRefList copy, String trxName) + { + this(ctx, 0, trxName); + copyPO(copy); + } /** * Get Reference List Value Name (cached) @@ -304,5 +344,13 @@ public class MRefList extends X_AD_Ref_List return getName(); } // toString + @Override + public PO markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } // MRef_List