1 30 package com.genimen.djeneric.repository; 31 32 import java.lang.ref.SoftReference ; 33 import java.util.Hashtable ; 34 35 import com.genimen.djeneric.repository.exceptions.DjenericException; 36 37 public class DjObjectCache 38 { 39 protected Hashtable objectTable = null; 40 41 public DjObjectCache() 42 { 43 objectTable = new Hashtable (); 44 } 45 46 public void clear() 47 { 48 objectTable.clear(); 49 } 50 51 public void cache(DjObject obj) throws DjenericException 52 { 53 if ((obj != null)) 54 { 55 SoftReference ref = new SoftReference (obj); 56 objectTable.put(new Long (obj.getObjectId()), ref); 57 } 58 } 59 60 public DjObject lookup(long objectId) 61 { 62 return lookup(new Long (objectId)); 63 } 64 65 public DjObject lookup(Long objectId) 66 { 67 DjObject obj = null; 68 SoftReference ref = (SoftReference ) objectTable.get(objectId); 69 if (ref != null) 70 { 71 obj = (DjObject) ref.get(); 72 } 73 return obj; 74 } 75 76 public void remove(long objectId) 77 { 78 remove(new Long (objectId)); 79 } 80 81 public void remove(Long objectId) 82 { 83 objectTable.remove(objectId); 84 } 85 86 public void remove(DjObject obj) throws DjenericException 87 { 88 remove(obj.getObjectId()); 89 } 90 91 } | Popular Tags |