1 package mir.storage.store;
4 * Title: Class StoreIdentifier
5 * Description: StoreIdentifier has two functions.
6 * A) StoreIdenfier holds a reference to a @see StorableObject
7 * or B) StoreIdentifier is used too search for a @see StorableObject
8 * in the @see StoreContainer that matches its
10 * Copyright: Copyright (c) 2002
16 import mir.misc.Logfile;
18 public class StoreIdentifier {
20 /** @todo check if invalidating already to avoid deadlocks
21 * what about concurrency? */
23 private static Logfile storeLog;
24 private static ObjectStore o_store = ObjectStore.getInstance();
26 private StoreContainerType stocType=null;
27 private StorableObject reference=null;
28 private String uniqueIdentifier=null; // id for Entity & sql for EntityList
29 private long timesUsed;
30 private boolean invalidating=false;
32 /** @todo initialize logfile */
34 private StoreIdentifier() {}
36 public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) {
37 this(reference.getClass(), uniqueIdentifier);
38 this.reference=reference;
41 public StoreIdentifier(Class theClass, String uniqueIdentifier) {
42 this(theClass, StoreContainerType.STOC_TYPE_ENTITY,uniqueIdentifier);
45 public StoreIdentifier(Class theClass, int storeType, String uniqueIdentifier) {
46 this.uniqueIdentifier=uniqueIdentifier;
47 this.stocType = StoreContainerType.valueOf(theClass, storeType);
55 public void invalidate() {
56 System.out.println("Invalidating: " + toString());
57 // avoid deadlock due to propagation.
60 if ( stocType!=null &&
61 stocType.getStocType()==StoreContainerType.STOC_TYPE_ENTITY )
63 System.out.println("Propagating invalidation to EntityList for " + toString());
64 // we should invalidate related ENTITY_LIST
65 StoreContainerType entityListStocType =
66 StoreContainerType.valueOf( stocType.getStocClass(),
67 StoreContainerType.STOC_TYPE_ENTITYLIST );
68 o_store.invalidate(entityListStocType);
71 // propagate invalidation to Set
72 Set set = reference.getNotifyOnReleaseSet();
74 for (Iterator it = set.iterator(); it.hasNext(); ) {
76 if ( o instanceof StoreIdentifier ) {
77 System.out.println("Propagating invalidation to StoreIdentifier: " + o.toString());
78 // propagate invalidation to a specific StoreIdentifier in cache
79 o_store.invalidate((StoreIdentifier)o);
80 } else if ( o instanceof StoreContainerType ) {
81 System.out.println("Propagating invalidation to StoreContainer: " + o.toString());
82 // propagate invalidation to a whole StoreContainer
83 o_store.invalidate((StoreContainerType)o);
92 public void release() {
94 this.uniqueIdentifier=null;
98 public StorableObject use() {
104 * Method equals for comparison between two identifier
106 * @return true if yes otherwise false
109 public boolean equals(Object sid) {
110 if ( !(sid instanceof StoreIdentifier) ) return false;
111 if ( ((StoreIdentifier)sid).getStoreContainerType()==stocType &&
112 ((StoreIdentifier)sid).getUniqueIdentifier().equals(uniqueIdentifier) )
117 public StoreContainerType getStoreContainerType() { return stocType; }
118 public String getUniqueIdentifier() { return uniqueIdentifier; }
119 public boolean hasReference() { return (reference==null) ? false:true; }
121 public String toString() {
122 StringBuffer id = new StringBuffer(uniqueIdentifier);
123 id.append("@storetype: ").append(stocType.toString());
124 if (reference != null) id.append(" ("+timesUsed).append(") times used.");
125 return id.toString();