IDEMPIERE-5204 Cache the list/array of mreflist for AD_Reference_ID (#1202)
* IDEMPIERE-5204 Cache the list/array of mreflist for AD_Reference_ID * IDEMPIERE-5204 Use StringBuilder for better performance
This commit is contained in:
parent
3423e02780
commit
c7465f8121
|
@ -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;
|
|||
* <li>BF [ 1748449 ] Info Account - Posting Type is not translated
|
||||
* <li>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<String,MRefList> s_ref_value_cache = new ImmutablePOCache<String,MRefList>(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
|
||||
|
|
Loading…
Reference in New Issue