1 19 20 package org.openharmonise.rm.sessions; 21 22 import org.openharmonise.commons.cache.*; 23 import org.openharmonise.commons.dsi.*; 24 25 26 27 33 public final class SessionCache extends AbstractCache { 34 private static SessionCache m_instance = null; 35 private static String CACHE_NAME = "SESSION"; 36 37 protected AbstractDataStoreInterface m_dbinterf = null; 38 39 45 private SessionCache(AbstractDataStoreInterface dbinterf) throws CacheException { 46 super(CACHE_NAME); 47 48 m_dbinterf = dbinterf; 49 } 50 51 58 public synchronized static SessionCache getInstance(AbstractDataStoreInterface dbinterf) 59 throws CacheException { 60 if (m_instance == null) { 61 m_instance = new SessionCache(dbinterf); 62 } 63 64 return m_instance; 65 } 66 67 74 public Session getSession(String session_id) throws CacheException { 75 final Session cached_session = (Session) getObject(session_id); 76 77 return cached_session; 78 } 79 80 81 84 public Object getObject(final Object key) throws CacheException { 85 Object cached_object = super.getObject(key); 87 if (cached_object == null) { 88 try { 89 cached_object = new Session(m_dbinterf,(String )key); 90 addToCache(key, cached_object); 91 } catch (SessionException e) { 92 cached_object = null; 93 } 94 } 95 return cached_object; 96 } 97 98 101 protected Object getCacheableObject(Object session_id) 102 throws Exception { 103 if (session_id == null) { 104 throw new IllegalArgumentException ("Session id must be passed " + 105 " to GetCacheableObject user_id:" + 106 session_id); 107 } 108 109 Session session = null; 110 111 try { 112 session = new Session(m_dbinterf, (String ) session_id); 113 } catch (InvalidSessionIdException e) { 114 session = null; 115 } 116 117 return session; 118 } 119 } | Popular Tags |