From 9cca6c08bef625a3ed763550ac5a79aa6a34e8ae Mon Sep 17 00:00:00 2001 From: igorpojzl <59439434+igorpojzl@users.noreply.github.com> Date: Thu, 24 Sep 2020 14:06:51 +0200 Subject: [PATCH] IDEMPIERE-4467 Window Customisation has not implemented caching (#268) * IDEMPIERE-4467 Add caching to UserDefTab and UserDefField * IDEMPIERE-4467 Change CCache to ImutablePOCache * IDEMPIERE-4467 Window Customisation - Change cache Get and Put Methods Change cache Get and Put methods to have consistency with ctx parameter. --- .../src/org/compiere/model/MUserDefField.java | 56 ++++++++++++++++- .../src/org/compiere/model/MUserDefTab.java | 63 ++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MUserDefField.java b/org.adempiere.base/src/org/compiere/model/MUserDefField.java index 4013b68e9a..339ef38f2d 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserDefField.java +++ b/org.adempiere.base/src/org/compiere/model/MUserDefField.java @@ -22,7 +22,10 @@ import java.util.logging.Level; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.Env; import org.compiere.util.Msg; +import org.idempiere.cache.ImmutablePOCache; +import org.idempiere.cache.ImmutablePOSupport; /** @@ -30,13 +33,16 @@ import org.compiere.util.Msg; * @author Dirk Niemeyer, action42 GmbH * @version $Id$ */ -public class MUserDefField extends X_AD_UserDef_Field +public class MUserDefField extends X_AD_UserDef_Field implements ImmutablePOSupport { /** * */ private static final long serialVersionUID = 2522038599257589829L; + /** Cache of selected MUserDefField entries **/ + private static ImmutablePOCache s_cache = new ImmutablePOCache(Table_Name, 10); + /** * Standard constructor. * You must implement this constructor for Adempiere Persistency @@ -64,6 +70,37 @@ public class MUserDefField extends X_AD_UserDef_Field super (ctx, rs, trxName); } // MyModelExample + /** + * + * @param copy + */ + public MUserDefField(MUserDefField copy) + { + this(Env.getCtx(), copy); + } + + /** + * + * @param ctx + * @param copy + */ + public MUserDefField(Properties ctx, MUserDefField copy) + { + this(ctx, copy, (String) null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MUserDefField(Properties ctx, MUserDefField copy, String trxName) + { + this(ctx, 0, trxName); + copyPO(copy); + } + /** * Get matching MUserDefField related to current field and user definition for window and tab * @param ctx @@ -82,6 +119,13 @@ public class MUserDefField extends X_AD_UserDef_Field if (userdefTab == null) return null; + // Check Cache + String key = new StringBuilder().append(AD_Field_ID).append("_") + .append(userdefTab.getAD_UserDef_Tab_ID()) + .toString(); + if (s_cache.containsKey(key)) + return s_cache.get(ctx, key, e -> new MUserDefField(ctx, e)); + MUserDefField retValue = null; StringBuilder sql = new StringBuilder("SELECT * " @@ -103,6 +147,7 @@ public class MUserDefField extends X_AD_UserDef_Field { retValue = new MUserDefField(ctx,rs,null); } + s_cache.put(key, retValue, e -> new MUserDefField(Env.getCtx(), e)); } catch (SQLException ex) { @@ -141,5 +186,14 @@ public class MUserDefField extends X_AD_UserDef_Field } return true; } + + @Override + public PO markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } // MUserDefField diff --git a/org.adempiere.base/src/org/compiere/model/MUserDefTab.java b/org.adempiere.base/src/org/compiere/model/MUserDefTab.java index b31af703d5..257ca4fb1d 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserDefTab.java +++ b/org.adempiere.base/src/org/compiere/model/MUserDefTab.java @@ -14,12 +14,17 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; import java.util.logging.Level; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.Env; +import org.idempiere.cache.ImmutablePOCache; +import org.idempiere.cache.ImmutablePOSupport; /** @@ -28,13 +33,16 @@ import org.compiere.util.DB; * @version $Id$ * */ -public class MUserDefTab extends X_AD_UserDef_Tab +public class MUserDefTab extends X_AD_UserDef_Tab implements ImmutablePOSupport { /** * */ private static final long serialVersionUID = 20120403111900L; + /** Cache of selected MUserDefTab entries **/ + private static ImmutablePOCache s_cache = new ImmutablePOCache(Table_Name, 10); + /** * Standard constructor. * You must implement this constructor for Adempiere Persistency @@ -62,6 +70,37 @@ public class MUserDefTab extends X_AD_UserDef_Tab super (ctx, rs, trxName); } // MUserDefTab + /** + * + * @param copy + */ + public MUserDefTab(MUserDefTab copy) + { + this(Env.getCtx(), copy); + } + + /** + * + * @param ctx + * @param copy + */ + public MUserDefTab(Properties ctx, MUserDefTab copy) + { + this(ctx, copy, (String) null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MUserDefTab(Properties ctx, MUserDefTab copy, String trxName) + { + this(ctx, 0, trxName); + copyPO(copy); + } + /** * Get matching MUserDefTab related to current tab and user definition for window * @param ctx @@ -73,6 +112,14 @@ public class MUserDefTab extends X_AD_UserDef_Tab { MUserDefTab retValue = null; + + // Check Cache + String key = new StringBuilder().append(AD_Tab_ID).append("_") + .append(AD_UserDefWin_ID) + .toString(); + if (s_cache.containsKey(key)) + return s_cache.get(ctx, key, e -> new MUserDefTab(ctx, e)); + StringBuilder sql = new StringBuilder("SELECT * " + " FROM AD_UserDef_Tab " @@ -93,6 +140,7 @@ public class MUserDefTab extends X_AD_UserDef_Tab { retValue = new MUserDefTab(ctx,rs,null); } + s_cache.put(key, retValue, e -> new MUserDefTab(Env.getCtx(), e)); } catch (SQLException ex) { @@ -125,5 +173,14 @@ public class MUserDefTab extends X_AD_UserDef_Tab return getMatch(ctx, AD_Tab_ID, userdefWin.getAD_UserDef_Win_ID()); } + + @Override + public PO markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } // MUserDefTab