From c13039cf828cfa79536a82e6ad0a302e2d2f2a2c Mon Sep 17 00:00:00 2001 From: igorpojzl <59439434+igorpojzl@users.noreply.github.com> Date: Fri, 15 Apr 2022 09:51:40 +0200 Subject: [PATCH] IDEMPIERE-5268 Cache PA_DocumentStatus (#1291) * IDEMPIERE-5268 Cache PA_DocumentStatus * IDEMPIERE-5268 Cache PA_DocumentStatus --- .../org/compiere/model/MDocumentStatus.java | 67 ++++++++++++++++++- .../apps/graph/WDocumentStatusIndicator.java | 5 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MDocumentStatus.java b/org.adempiere.base/src/org/compiere/model/MDocumentStatus.java index 3d9b6d873d..a2c29921fd 100644 --- a/org.adempiere.base/src/org/compiere/model/MDocumentStatus.java +++ b/org.adempiere.base/src/org/compiere/model/MDocumentStatus.java @@ -36,8 +36,10 @@ import java.util.Properties; import org.compiere.util.DB; import org.compiere.util.Env; +import org.idempiere.cache.ImmutableIntPOCache; +import org.idempiere.cache.ImmutablePOSupport; -public class MDocumentStatus extends X_PA_DocumentStatus { +public class MDocumentStatus extends X_PA_DocumentStatus implements ImmutablePOSupport { /** * */ @@ -51,6 +53,61 @@ public class MDocumentStatus extends X_PA_DocumentStatus { super(ctx, rs, trxName); } + /** + * + * @param copy + */ + public MDocumentStatus(MDocumentStatus copy) + { + this(Env.getCtx(), copy); + } + + /** + * + * @param ctx + * @param copy + */ + public MDocumentStatus(Properties ctx, MDocumentStatus copy) + { + this(ctx, copy, (String) null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MDocumentStatus(Properties ctx, MDocumentStatus copy, String trxName) + { + this(ctx, 0, trxName); + copyPO(copy); + } + + /** Categopry Cache */ + private static ImmutableIntPOCache s_cache = new ImmutableIntPOCache(Table_Name, 20); + + /** + * Get from Cache (immutable) + * @param ctx context + * @param M_Product_Category_ID id + * @return category + */ + public static MDocumentStatus get (Properties ctx, int PA_DocumentStatus_ID) + { + Integer ii = Integer.valueOf(PA_DocumentStatus_ID); + MDocumentStatus retValue = s_cache.get(ctx, ii, e -> new MDocumentStatus(ctx, e)); + if (retValue != null) + return retValue; + retValue = new MDocumentStatus (ctx, PA_DocumentStatus_ID, (String)null); + if (retValue.get_ID () == PA_DocumentStatus_ID) + { + s_cache.put (PA_DocumentStatus_ID, retValue, e -> new MDocumentStatus(Env.getCtx(), e)); + return retValue; + } + return null; + } // get + /** * Get Document Status Indicators * @param ctx context @@ -171,4 +228,12 @@ public class MDocumentStatus extends X_PA_DocumentStatus { return false; } + @Override + public PO markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WDocumentStatusIndicator.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WDocumentStatusIndicator.java index de3f4798b9..5dca13aced 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WDocumentStatusIndicator.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/graph/WDocumentStatusIndicator.java @@ -162,7 +162,10 @@ public class WDocumentStatusIndicator extends Panel implements EventListener