IDEMPIERE-4961 Minor performance enhancement for AD Window (#878)

* IDEMPIERE-4961 Minor performance enhancement for AD Window

* IDEMPIERE-4961 Minor performance enhancement for AD Window

Fix potential mtab not found issue with 2pack import.
This commit is contained in:
hengsin 2021-09-15 19:00:28 +08:00 committed by GitHub
parent e78496e954
commit 5f22f7f495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 5 deletions

View File

@ -331,7 +331,7 @@ public class GridTabCSVExporter implements IGridTabExporter
private String isValidTabToExport(GridTab gridTab){
String result=null;
MTab tab = new MTab(Env.getCtx(), gridTab.getAD_Tab_ID(), null);
MTab tab = MTab.get(gridTab.getAD_Tab_ID());
if (tab.isReadOnly())
result = Msg.getMsg(Env.getCtx(),"FieldIsReadOnly", new Object[] {gridTab.getName()});

View File

@ -171,7 +171,7 @@ public class GenericZoomProvider implements IZoomProvider {
int tabIDLoop = AD_Tab_ID;
int levelUp = 0;
while (true) {
MTab tab = new MTab(ctx, tabIDLoop, null);
MTab tab = MTab.get(tabIDLoop);
String whereCtx = tab.getWhereClause();
if (!Util.isEmpty(whereCtx, true)) {
if (whereCtx.indexOf("@") != -1)

View File

@ -28,6 +28,7 @@ import org.adempiere.exceptions.FillMandatoryException;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -46,6 +47,29 @@ public class MTab extends X_AD_Tab implements ImmutablePOSupport
*/
private static final long serialVersionUID = -8111075325920938135L;
/** Cache */
private static ImmutableIntPOCache<Integer,MTab> s_cache = new ImmutableIntPOCache<Integer,MTab>(Table_Name, 20);
/**
*
* @param AD_Tab_ID
* @return {@link MTab}
*/
public static MTab get(int AD_Tab_ID)
{
Integer key = Integer.valueOf(AD_Tab_ID);
MTab retValue = s_cache.get (Env.getCtx(), key, e -> new MTab(Env.getCtx(), e));
if (retValue != null)
return retValue;
retValue = new MTab (Env.getCtx(), AD_Tab_ID, (String)null);
if (retValue.get_ID () == AD_Tab_ID) {
s_cache.put (key, retValue);
return retValue;
}
return null;
}
/**
* Standard Constructor
* @param ctx context

View File

@ -30,6 +30,7 @@ import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.action.Actions;
import org.adempiere.webui.action.IAction;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Combobox;
import org.adempiere.webui.component.FToolbar;
import org.adempiere.webui.component.Tabpanel;
@ -1213,6 +1214,10 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
}
public void refreshUserQuery(int AD_Tab_ID, int AD_UserQuery_ID) {
if (AEnv.getOrSetExecutionAttribute(getClass().getName()+".refreshUserQuery")) {
return;
}
fQueryName.getItems().clear();
userQueries = MUserQuery.get(Env.getCtx(), AD_Tab_ID);
fQueryName.appendItem("");

View File

@ -816,4 +816,17 @@ public final class AEnv
return getApplicationUrl() + "?Action=Zoom&TableName" + po.get_TableName() + "&Record_ID=" + po.get_ID();
}
/**
*
* @param attribute
* @return true if attribute have been set for current executions
*/
public static boolean getOrSetExecutionAttribute(String attribute) {
if (Executions.getCurrent() != null) {
if (Executions.getCurrent().getAttribute(attribute) != null)
return true;
Executions.getCurrent().setAttribute(attribute, Boolean.TRUE);
}
return false;
}
} // AEnv

View File

@ -352,7 +352,7 @@ public class CustomizeGridViewPanel extends Panel
{
List<MField> lsFieldsOfGrid = query.list();
HashMap<Integer, ListElement> curTabSel = new HashMap<Integer, CustomizeGridViewPanel.ListElement>();
MTab tab = new MTab(Env.getCtx(), m_AD_Tab_ID, null);
MTab tab = MTab.get(m_AD_Tab_ID);
for (MField field : lsFieldsOfGrid)
{

View File

@ -285,7 +285,7 @@ public class HelpController
if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Tab))
{
MTab tab = new MTab(Env.getCtx(), recordId, null);
MTab tab = MTab.get(recordId);
if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab")) {
nameMsg = tab.get_Translation("Name", false);

View File

@ -237,7 +237,7 @@ public class QuickCustomizeGridViewPanel extends Panel {
try {
List<MField> lsFieldsOfGrid = query.list();
HashMap<Integer, ListElement> curTabSel = new HashMap<Integer, QuickCustomizeGridViewPanel.ListElement>();
MTab tab = new MTab(Env.getCtx(), m_AD_Tab_ID, null);
MTab tab = MTab.get(m_AD_Tab_ID);
for (MField field : lsFieldsOfGrid) {
if (!MRole.getDefault(Env.getCtx(), false).isColumnAccess(tab.getAD_Table_ID(), field.getAD_Column_ID(),