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.
This commit is contained in:
igorpojzl 2020-09-24 14:06:51 +02:00 committed by GitHub
parent 02a450a660
commit 9cca6c08be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 4 deletions

View File

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

View File

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