IDEMPIERE-4109 Caching Candidate: AD_Table

This commit is contained in:
Diego Ruiz 2019-11-18 21:00:36 +01:00
parent 7c4ccdc739
commit 9a118b03dc
1 changed files with 17 additions and 26 deletions

View File

@ -36,6 +36,7 @@ import org.compiere.db.Database;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Util; import org.compiere.util.Util;
@ -61,7 +62,7 @@ public class MTable extends X_AD_Table
/** /**
* *
*/ */
private static final long serialVersionUID = 4974471096496488963L; private static final long serialVersionUID = 4736882280922026772L;
public final static int MAX_OFFICIAL_ID = 999999; public final static int MAX_OFFICIAL_ID = 999999;
@ -106,6 +107,17 @@ public class MTable extends X_AD_Table
* @return Table * @return Table
*/ */
public static synchronized MTable get (Properties ctx, String tableName) public static synchronized MTable get (Properties ctx, String tableName)
{
return get(ctx, tableName, null);
} // get
/**
* Get Table from Cache
* @param ctx context
* @param tableName case insensitive table name
* @return Table
*/
public static synchronized MTable get (Properties ctx, String tableName, String trxName)
{ {
if (tableName == null) if (tableName == null)
return null; return null;
@ -127,11 +139,11 @@ public class MTable extends X_AD_Table
ResultSet rs = null; ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setString(1, tableName.toUpperCase()); pstmt.setString(1, tableName.toUpperCase());
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next()) if (rs.next())
retValue = new MTable (ctx, rs, null); retValue = new MTable (ctx, rs, trxName);
} }
catch (Exception e) catch (Exception e)
{ {
@ -631,29 +643,8 @@ public class MTable extends X_AD_Table
* @return int retValue * @return int retValue
*/ */
public static int getTable_ID(String tableName, String trxName) { public static int getTable_ID(String tableName, String trxName) {
int retValue = 0; MTable table = get(Env.getCtx(), tableName, trxName);
String SQL = "SELECT AD_Table_ID FROM AD_Table WHERE UPPER(tablename) = ?"; return table != null ? table.getAD_Table_ID() : 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(SQL, trxName);
pstmt.setString(1, tableName.toUpperCase());
rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getInt(1);
}
catch (Exception e)
{
s_log.log(Level.SEVERE, SQL, e);
retValue = -1;
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue;
} }
/** /**