diff --git a/org.adempiere.base/src/org/compiere/model/MForm.java b/org.adempiere.base/src/org/compiere/model/MForm.java index 4f58748a63..9a1c58c636 100644 --- a/org.adempiere.base/src/org/compiere/model/MForm.java +++ b/org.adempiere.base/src/org/compiere/model/MForm.java @@ -20,6 +20,8 @@ import java.sql.ResultSet; import java.util.Properties; import org.compiere.util.Env; +import org.idempiere.cache.ImmutableIntPOCache; +import org.idempiere.cache.ImmutablePOSupport; /** @@ -28,14 +30,47 @@ import org.compiere.util.Env; * @author Jorg Janke * @version $Id: MForm.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $ */ -public class MForm extends X_AD_Form +public class MForm extends X_AD_Form implements ImmutablePOSupport { - /** * */ - private static final long serialVersionUID = -2013533837940046638L; - + private static final long serialVersionUID = -3617225890452735325L; + + /** Cache */ + private static ImmutableIntPOCache s_cache = new ImmutableIntPOCache(Table_Name, 20); + + /** + * Get MForm from Cache (immutable) + * @param AD_Form_ID id + * @return MForm + */ + public static MForm get (int AD_Form_ID) + { + return get(Env.getCtx(), AD_Form_ID); + } + + /** + * Get MFrom from Cache (immutable) + * @param ctx context + * @param AD_Form_ID id + * @return MForm + */ + public static MForm get (Properties ctx, int AD_Form_ID) + { + Integer key = Integer.valueOf(AD_Form_ID); + MForm retValue = s_cache.get (ctx, key, e -> new MForm(ctx, e)); + if (retValue != null) + return retValue; + + retValue = new MForm (ctx, AD_Form_ID, (String)null); + if (retValue.get_ID () == AD_Form_ID) { + s_cache.put (key, retValue, e -> new MForm(Env.getCtx(), e)); + return retValue; + } + return null; + } // get + /** * Default Constructor * @param ctx context @@ -58,6 +93,27 @@ public class MForm extends X_AD_Form super(ctx, rs, trxName); } // MForm + /** + * + * @param ctx + * @param copy + */ + public MForm(Properties ctx, MForm copy) { + this(ctx, copy, (String) null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MForm(Properties ctx, MForm copy, String trxName) + { + this(ctx, 0, trxName); + copyPO(copy); + } + /** * After Save * @param newRecord new @@ -91,4 +147,12 @@ public class MForm extends X_AD_Form return success; } // afterSave + @Override + public MForm markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } // MForm diff --git a/org.adempiere.base/src/org/compiere/model/MLanguage.java b/org.adempiere.base/src/org/compiere/model/MLanguage.java index 1f3d91ddd5..883d750cd1 100644 --- a/org.adempiere.base/src/org/compiere/model/MLanguage.java +++ b/org.adempiere.base/src/org/compiere/model/MLanguage.java @@ -29,11 +29,12 @@ import java.util.logging.Level; import org.adempiere.exceptions.DBException; import org.adempiere.process.UUIDGenerator; -import org.compiere.Adempiere; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Language; import org.compiere.util.Msg; +import org.idempiere.cache.ImmutablePOCache; +import org.idempiere.cache.ImmutablePOSupport; /** * Language Model @@ -44,12 +45,17 @@ import org.compiere.util.Msg; * @author Teo Sarca, www.arhipac.ro *
  • BF [ 2444851 ] MLanguage should throw an exception if there is an error */ -public class MLanguage extends X_AD_Language -{ +public class MLanguage extends X_AD_Language implements ImmutablePOSupport +{ /** * */ - private static final long serialVersionUID = 6415602943484245447L; + private static final long serialVersionUID = 6553711529361500744L; + + /** + * MLanguage cache key by AD_Language value + */ + private static final ImmutablePOCache s_cache = new ImmutablePOCache(Table_Name, Table_Name+"|AD_Language", 100, false); /** * Get Language Model from Language @@ -70,9 +76,16 @@ public class MLanguage extends X_AD_Language */ public static MLanguage get (Properties ctx, String AD_Language) { - return new Query(ctx, Table_Name, COLUMNNAME_AD_Language+"=?", null) + MLanguage retValue = s_cache.get(ctx, AD_Language, e -> new MLanguage(ctx, e)); + if (retValue != null) + return retValue; + + retValue = new Query(ctx, Table_Name, COLUMNNAME_AD_Language+"=?", null) .setParameters(AD_Language) .firstOnly(); + if (retValue != null) + s_cache.put(AD_Language, retValue, e -> new MLanguage(ctx, e)); + return retValue; } // get /** @@ -147,6 +160,27 @@ public class MLanguage extends X_AD_Language setLanguageISO(LanguageISO); // en } // MLanguage + /** + * + * @param ctx + * @param copy + */ + public MLanguage(Properties ctx, MLanguage copy) { + this(ctx, copy, (String)null); + } + + /** + * + * @param ctx + * @param copy + * @param trxName + */ + public MLanguage(Properties ctx, MLanguage copy, String trxName) { + this(ctx, 0, trxName); + copyPO(copy); + this.m_dateFormat = copy.m_dateFormat != null ? new SimpleDateFormat(copy.m_dateFormat.toPattern()) : null; + } + /** Locale */ private Locale m_locale = null; /** Date Format */ @@ -474,18 +508,13 @@ public class MLanguage extends X_AD_Language return no; } // addTable - - /************************************************************************** - * Setup - * @param args args - */ - public static void main(String[] args) - { - System.out.println("Language"); - Adempiere.startup(true); - - System.out.println(MLanguage.get(Env.getCtx(), "de_DE")); - System.out.println(MLanguage.get(Env.getCtx(), "en_US")); - } // main + @Override + public MLanguage markImmutable() { + if (is_Immutable()) + return this; + + makeImmutable(); + return this; + } } // MLanguage diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java index 109c79bcfb..02dd64400b 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADForm.java @@ -186,7 +186,7 @@ public abstract class ADForm extends Window implements EventListener, IHe public static ADForm openForm (int adFormID, GridTab gridTab, ProcessInfo pi, String predefinedContextVariables, boolean isSOTrx) { ADForm form; - MForm mform = new MForm(Env.getCtx(), adFormID, null); + MForm mform = MForm.get(adFormID); String formName = mform.getClassname(); String name = mform.get_Translation(MForm.COLUMNNAME_Name); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java index 2250aeb1d2..fa64027c88 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java @@ -380,7 +380,7 @@ public class HelpController } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Form)) { - MForm form = new MForm(Env.getCtx(), recordId, null); + MForm form = MForm.get(recordId); if (!Env.isBaseLanguage(Env.getCtx(), "AD_Form")) { nameMsg = form.get_Translation("Name",false);