IDEMPIERE-4959 Performance improvement for the opening of form window (#875)

* IDEMPIERE-4959 Performance improvement for the opening of form window

* IDEMPIERE-4959 Performance improvement for the opening of form window

minor cache name change.
This commit is contained in:
hengsin 2021-09-14 21:04:06 +08:00 committed by GitHub
parent eedc3c6e35
commit ab12354cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 24 deletions

View File

@ -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<Integer,MForm> s_cache = new ImmutableIntPOCache<Integer,MForm>(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

View File

@ -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
* <li>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<String, MLanguage> s_cache = new ImmutablePOCache<String, MLanguage>(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

View File

@ -186,7 +186,7 @@ public abstract class ADForm extends Window implements EventListener<Event>, 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);

View File

@ -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);