1 2 12 package com.versant.core.ejb; 13 14 import com.versant.core.common.OID; 15 import com.versant.core.common.State; 16 import com.versant.core.common.BindingSupportImpl; 17 import com.versant.core.ejb.common.EntrySet; 18 19 import java.util.Iterator ; 20 21 25 public class LocalCache { 26 29 private EntrySet set = new EntrySet(); 30 31 38 public StateManagerImp add(OID oid, StateManagerImp sm) { 39 CacheEntry e = (CacheEntry) set.get(oid); 40 if (e == null) { 41 set.addEntry(createEntry(oid, sm)); 42 } else { 43 if (e.val == null) { 44 throw BindingSupportImpl.getInstance().internal("Cache entry with no value"); 45 } else if (!(e.val instanceof State)) { 46 50 throw new RuntimeException ("There is already an instance in the cache with same id"); 51 } else { 52 e.val = sm; 53 } 54 } 55 return sm; 56 } 57 58 public void add(OID oid, State state) { 59 CacheEntry e = (CacheEntry) set.get(oid); 60 if (e == null) { 61 set.addEntry(createEntry(oid, state)); 62 } else { 63 Object value = e.val; 64 if (value instanceof StateManagerImp) { 65 StateManagerImp sm = (StateManagerImp) value; 66 sm.updateState(state); 67 } else { 68 ((State) value).updateNonFilled(state); 69 } 70 } 71 } 72 73 public Object get(OID oid) { 74 CacheEntry e = (CacheEntry) set.get(oid); 75 if (e != null) { 76 return e.getValue(); 77 } 78 return null; 79 } 80 81 87 private CacheEntry createEntry(OID oid, Object value) { 88 return new CacheEntry(oid, value); 89 } 90 91 public void clear() { 92 set.clear(); 93 } 94 95 96 97 public class CacheEntry extends EntrySet.Entry { 98 private Object val; 99 100 public CacheEntry(OID key, Object val) { 101 super(key); 102 this.val = val; 103 } 104 105 public Object getValue() { 106 return val; 107 } 108 } 109 110 public void processReferenceQueue() { 111 } 112 113 public Iterator getCacheIterator() { 114 processReferenceQueue(); 115 return set.newEntryIterator(); 116 } 117 } 118 | Popular Tags |