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;
25 private StoreContainerType stocType=null;
26 private StorableObject reference=null;
27 private String uniqueIdentifier=null; // id for Entity & sql for EntityList
28 private long timesUsed;
29 private boolean invalidating=false;
31 /** @todo initialize logfile */
33 private StoreIdentifier() {}
35 public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) {
36 this(reference.getClass(), uniqueIdentifier);
37 this.reference=reference;
40 public StoreIdentifier(Class theClass, String uniqueIdentifier) {
41 this(theClass, StoreContainerType.STOC_TYPE_ENTITY,uniqueIdentifier);
44 public StoreIdentifier(Class theClass, int storeType, String uniqueIdentifier) {
45 this.uniqueIdentifier=uniqueIdentifier;
46 this.stocType = StoreContainerType.valueOf(theClass, storeType);
54 public void invalidate() {
55 // avoid deadlock due to propagation.
58 Set set = reference.getNotifyOnReleaseSet();
59 /** @todo here we should propagate the invalidation all members of Set
60 * @see StoreContainer. The set may contain objects of different type.*/
65 public void release() {
67 this.uniqueIdentifier=null;
71 public StorableObject use() {
77 * Method equals for comparison between two identifier
79 * @return true if yes otherwise false
82 public boolean equals(Object sid) {
83 if ( !(sid instanceof StoreIdentifier) ) return false;
84 if ( ((StoreIdentifier)sid).getStoreContainerType()==stocType &&
85 ((StoreIdentifier)sid).getUniqueIdentifier().equals(uniqueIdentifier) )
90 public StoreContainerType getStoreContainerType() { return stocType; }
91 public String getUniqueIdentifier() { return uniqueIdentifier; }
92 public boolean hasReference() { return (reference==null) ? false:true; }
94 public String toString() {
95 StringBuffer id = new StringBuffer(uniqueIdentifier);
96 id.append("@storetype: ").append(stocType.toString());
97 if (reference != null) id.append(" ("+timesUsed).append(") times used.");