1 19 package org.openharmonise.rm.dsi; 20 21 import java.util.logging.*; 22 23 import org.openharmonise.commons.cache.*; 24 import org.openharmonise.commons.dsi.*; 25 import org.openharmonise.rm.metadata.Profile; 26 27 28 45 public class ColumnRefCache extends AbstractCache { 46 47 50 private static final String CACHE_NAME = "columnref"; 51 52 55 private static ColumnRefCache m_instance = null; 56 57 60 private static final Logger m_logger = Logger.getLogger(ColumnRefCache.class.getName()); 61 62 67 private ColumnRefCache() throws CacheException { 68 super(CACHE_NAME); 69 } 70 71 77 static public ColumnRefCache getInstance() throws CacheException { 78 if (m_instance == null) { 79 m_instance = new ColumnRefCache(); 80 } 81 82 return m_instance; 83 } 84 85 105 public ColumnRef getColumnRef( 106 DataStoreObject dsObj, 107 String sColumn, 108 boolean bIsHist) 109 throws CacheException { 110 String sCacheKey = null; 111 112 if(dsObj instanceof Profile) { 114 sCacheKey = getCacheKey(dsObj.getDBTableName(), sColumn, bIsHist); 115 } else { 116 sCacheKey = getCacheKey(dsObj.getClass(), sColumn, bIsHist); 117 } 118 119 ColumnRef colref = (ColumnRef) getObject(sCacheKey); 120 121 if (colref == null) { 122 try { 123 colref = dsObj.getInstanceColumnRef(sColumn, bIsHist); 124 } catch (DataStoreException e) { 125 throw new CacheException("Error occured getting column ref", e); 126 } 127 128 super.addToCache(sCacheKey, colref); 129 } 130 131 return colref; 132 133 } 134 135 138 public Object getObject(final Object key) { 139 140 Object cached_object = null; 141 try { 142 cached_object = super.getObject(key); 143 } catch (CacheException e) { 144 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 145 } 146 return cached_object; 147 } 148 149 160 public ColumnRef getColumnRef(Class clss, String sColumn, boolean bIsHist) 161 throws CacheException { 162 163 String sCacheKey = getCacheKey(clss, sColumn, bIsHist); 164 ColumnRef colref = (ColumnRef) getObject(sCacheKey); 165 166 return colref; 167 } 168 169 179 public void addToCache( 180 Class clss, 181 String sColumn, 182 boolean bIsHist, 183 ColumnRef colref) { 184 String sCacheKey = getCacheKey(clss, sColumn, bIsHist); 185 super.addToCache(sCacheKey, colref); 186 } 187 188 191 protected Object getCacheableObject(Object key) throws Exception { 192 193 return null; 194 } 195 196 205 protected String getCacheKey(Class clss, String sColumn, boolean bIsHist) { 206 StringBuffer strbuf = new StringBuffer (); 207 strbuf.append(clss.getName()).append(sColumn).append( 208 String.valueOf(bIsHist)); 209 return strbuf.toString(); 210 } 211 212 221 protected String getCacheKey(String sTable, String sColumn, boolean bIsHist) { 222 StringBuffer strbuf = new StringBuffer (); 223 strbuf.append(sTable).append(sColumn).append( 224 String.valueOf(bIsHist)); 225 return strbuf.toString(); 226 } 227 228 } 229 | Popular Tags |