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;
19 public class StoreIdentifier {
21 /** @todo check if invalidating already to avoid deadlocks
22 * what about concurrency? */
24 private static Logfile storeLog;
25 private static ObjectStore o_store = ObjectStore.getInstance();
27 private StoreContainerType stocType=null;
28 private StorableObject reference=null;
29 private String uniqueIdentifier=null; // id for Entity & sql for EntityList
30 private long timesUsed;
31 private boolean invalidating=false;
33 /** @todo initialize logfile */
35 private StoreIdentifier() {}
37 public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) {
39 if (reference instanceof EntityList)
40 theClass=((EntityList)reference).getStorage().getEntityClass();
42 theClass=reference.getClass();
43 this.uniqueIdentifier=uniqueIdentifier;
44 this.stocType = StoreContainerType.valueOf(theClass, storeType);
45 this.reference=reference;
48 public StoreIdentifier(StorableObject reference, String uniqueIdentifier) {
49 this(reference, StoreContainerType.STOC_TYPE_ENTITY, uniqueIdentifier);
52 public StoreIdentifier(Class theClass, String uniqueIdentifier) {
53 this(theClass, StoreContainerType.STOC_TYPE_ENTITY,uniqueIdentifier);
56 public StoreIdentifier(Class theClass, int storeType, String uniqueIdentifier) {
57 this.uniqueIdentifier=uniqueIdentifier;
58 this.stocType = StoreContainerType.valueOf(theClass, storeType);
66 public void invalidate() {
67 System.out.println("Invalidating: " + toString());
68 // avoid deadlock due to propagation.
71 if ( stocType!=null &&
72 stocType.getStocType()==StoreContainerType.STOC_TYPE_ENTITY )
74 System.out.println("Propagating invalidation to EntityList for " + toString());
75 // we should invalidate related ENTITY_LIST
76 StoreContainerType entityListStocType =
77 StoreContainerType.valueOf( stocType.getStocClass(),
78 StoreContainerType.STOC_TYPE_ENTITYLIST );
79 o_store.invalidate(entityListStocType);
82 // propagate invalidation to Set
83 Set set = reference.getNotifyOnReleaseSet();
85 for (Iterator it = set.iterator(); it.hasNext(); ) {
87 if ( o instanceof StoreIdentifier ) {
88 System.out.println("Propagating invalidation to StoreIdentifier: " + o.toString());
89 // propagate invalidation to a specific StoreIdentifier in cache
90 o_store.invalidate((StoreIdentifier)o);
91 } else if ( o instanceof StoreContainerType ) {
92 System.out.println("Propagating invalidation to StoreContainer: " + o.toString());
93 // propagate invalidation to a whole StoreContainer
94 o_store.invalidate((StoreContainerType)o);
103 public void release() {
105 this.uniqueIdentifier=null;
109 public StorableObject use() {
115 * Method equals for comparison between two identifier
117 * @return true if yes otherwise false
120 public boolean equals(Object sid) {
121 if ( !(sid instanceof StoreIdentifier) ) return false;
122 if ( ((StoreIdentifier)sid).getStoreContainerType()==stocType &&
123 ((StoreIdentifier)sid).getUniqueIdentifier().equals(uniqueIdentifier) ) {
129 public StoreContainerType getStoreContainerType() { return stocType; }
130 public String getUniqueIdentifier() { return uniqueIdentifier; }
131 public boolean hasReference() { return (reference==null) ? false:true; }
133 public String toString() {
134 StringBuffer id = new StringBuffer(uniqueIdentifier);
135 id.append("@storetype: ").append(stocType.toString());
136 if (reference != null) id.append(" ("+timesUsed).append(") times used.");
137 return id.toString();