1 51 52 package org.bsf.listOfValues.util; 53 54 import java.util.HashMap ; 55 import java.util.Iterator ; 56 import java.util.List ; 57 58 68 public class LovDefinitionCache { 69 73 77 class LovEntityCacheItem { 78 private List _types; 79 private String _lovName; 80 private String _lovRequest; 81 82 public LovEntityCacheItem( String p_lovName, String p_lovRequest, List p_metaData ) { 83 _types = p_metaData; 84 _lovName = p_lovName; 85 _lovRequest = p_lovRequest; 86 } 87 88 public String getRequest() { 89 return _lovRequest; 90 } 91 92 public String getLovName() { 93 return _lovName; 94 } 95 96 public List getTypes() { 97 return _types; 98 } 99 } 100 101 105 private static LovDefinitionCache _lovCacheInstance = null; 106 107 112 public static LovDefinitionCache getInstance() { 113 if ( _lovCacheInstance == null ) { 114 synchronized( LovDefinitionCache.class ) { 115 if ( _lovCacheInstance == null ) 116 _lovCacheInstance = new LovDefinitionCache(); 117 } 118 } 119 120 return _lovCacheInstance; 121 } 122 123 127 133 private HashMap _cache = new HashMap ( 50 ); 134 135 private LovDefinitionCache() { 136 } 138 139 149 public String getRequestForLovOID( Long p_lovOID ) { 150 String request = null; 151 LovEntityCacheItem item = (LovEntityCacheItem) _cache.get( p_lovOID ); 152 153 if ( item != null ) { 154 request = item.getRequest(); 156 } 157 158 return request; 159 } 160 161 172 public List getTypesForLovOID( Long p_lovOID ) { 173 List types = null; 174 LovEntityCacheItem item = (LovEntityCacheItem) _cache.get( p_lovOID ); 175 176 if ( item != null ) { 177 types = item.getTypes(); 179 } 180 181 return types; 182 } 183 184 193 public boolean isOIDInCache( Long p_lovOID ) { 194 return _cache.containsKey( p_lovOID ); 195 } 196 197 206 public boolean isNameInCache( String p_lovName ) { 207 boolean isNameInCache = true; 208 209 if ( p_lovName == null || getLovOID( p_lovName ) == null ) { 210 isNameInCache = false; 211 } 212 213 return isNameInCache; 214 } 215 216 226 public void addToCache( Long p_lovOID, String p_lovName, String p_lovRequest, List p_metaData ) { 227 if ( p_lovOID == null || p_lovName == null || p_lovRequest == null ) { 228 String msg = "Need non null (LovOID,LovName,LovRequest) to store them in cache"; 229 230 throw new IllegalArgumentException ( msg ); 231 } 232 233 _cache.put( p_lovOID, new LovEntityCacheItem( p_lovName, p_lovRequest, p_metaData ) ); 234 } 235 236 245 public Long getLovOID( String p_lovName ) { 246 Iterator iter = _cache.keySet().iterator(); 247 248 while ( iter.hasNext() ) { 249 Long OID = (Long ) iter.next(); 250 251 LovEntityCacheItem item = (LovEntityCacheItem) _cache.get( OID ); 252 253 if ( item.getLovName().equals( p_lovName ) ) { 254 return OID; 255 } 256 } 257 258 return null; 259 } 260 } 261 | Popular Tags |