From 1de46accf4e1d46d3aea2fd084e6eb21b0c4466a Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Tue, 12 Feb 2008 11:51:59 +0000 Subject: [PATCH] BF [ 1885496 ] Performance NEEDS - for MTableScriptValidator --- .../compiere/model/MTableScriptValidator.java | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/base/src/org/compiere/model/MTableScriptValidator.java b/base/src/org/compiere/model/MTableScriptValidator.java index ec74af0c37..25f85cfc54 100644 --- a/base/src/org/compiere/model/MTableScriptValidator.java +++ b/base/src/org/compiere/model/MTableScriptValidator.java @@ -17,16 +17,23 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; -import org.compiere.util.*; +import org.compiere.util.CCache; +import org.compiere.util.CLogger; +import org.compiere.util.DB; /** * Table Validator Scripts * @author Carlos Ruiz * @version $Id: MTableScriptValidator.java + * + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *
  • BF [ 1885496 ] Performance NEEDS */ public class MTableScriptValidator extends X_AD_Table_ScriptValidator { @@ -54,11 +61,18 @@ public class MTableScriptValidator extends X_AD_Table_ScriptValidator * @param ctx context * @param table_id AD_Table_ID * @param event Event - * @return array of MTableScriptValidator + * @return array of MTableScriptValidator or null if error or no validators found */ public static ArrayList getModelValidatorRules (Properties ctx, int ad_table_id, String event) { - ArrayList mvrs = new ArrayList(); + // Try cache + String key = ""+ad_table_id+"_"+event; + ArrayList mvrs = s_cacheTableEvent.get(key); + if (mvrs != null) + return mvrs; + // + // Fetch now + mvrs = new ArrayList(); MTableScriptValidator rule = null; String sql = "SELECT * FROM AD_Table_ScriptValidator WHERE AD_Table_ID=? AND EventModelValidator=? AND IsActive='Y' ORDER BY SeqNo"; PreparedStatement pstmt = null; @@ -72,17 +86,24 @@ public class MTableScriptValidator extends X_AD_Table_ScriptValidator while (rs.next ()) { rule = new MTableScriptValidator (ctx, rs, null); mvrs.add(rule); + // Cache + s_cache.put(rule.get_ID(), rule); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); + mvrs = null; } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } + // Store to cache + if (mvrs != null) + s_cacheTableEvent.put(key, mvrs); + // if (mvrs != null && mvrs.size() > 0) return mvrs; else @@ -90,7 +111,11 @@ public class MTableScriptValidator extends X_AD_Table_ScriptValidator } // getModelValidatorLoginRules /** Cache */ - private static CCache s_cache = new CCache("AD_Table_ScriptValidator", 20); + private static CCache s_cache + = new CCache(Table_Name, 20); + /** Cache / Table Event */ + private static CCache> s_cacheTableEvent + = new CCache>(Table_Name+"_TableEvent", 20); /** Static Logger */ private static CLogger s_log = CLogger.getCLogger (MTableScriptValidator.class);