1 19 20 package org.netbeans.mdr.storagemodel.transientimpl; 21 22 import java.lang.ref.ReferenceQueue ; 23 import java.util.HashMap ; 24 import org.netbeans.mdr.persistence.*; 25 import org.netbeans.mdr.storagemodel.TransientStorableObject; 26 import org.netbeans.mdr.storagemodel.TransientStorableClass; 27 31 32 public class TransientObjectResolverIndex extends TransactionalIndex implements SinglevaluedIndex { 33 34 public static final String NAME = "TRANSIENT_OBJECTS_RESOLVER"; 35 36 private HashMap map; 37 private ReferenceQueue queue; 38 39 40 public TransientObjectResolverIndex() { 41 this.map = new HashMap (); 42 this.queue = new ReferenceQueue (); 43 } 44 45 public void add(Object key, Object value) throws StorageException { 46 this.addNoTx (key, value); 47 this.txlog.push (new CompensatingTransaction.AddCTx (key, value)); 48 } 49 50 public void addNoTx (Object key, Object value) throws StorageException { 51 this.map.put (key, new TransientIndex.KeyedReference (value, this.queue, (MOFID)key)); 52 } 53 54 public boolean put (Object key, Object value) throws StorageException { 55 throw new UnsupportedOperationException (); 56 } 57 58 public void replace (Object key, Object value) throws StorageException { 59 throw new UnsupportedOperationException (); 60 } 61 62 public Object get (Object key) throws StorageException { 63 Object result = this.getIfExists (key); 64 if (result == null) 65 throw new StorageBadRequestException (); 66 return result; 67 } 68 69 public Object getIfExists (Object key) throws StorageException { 70 TransientIndex.KeyedReference entry = (TransientIndex.KeyedReference) this.map.get (key); 71 if (entry == null) 72 return null; 73 return entry.get (); 74 } 75 76 public Object getObjectIfExists (Object key, SinglevaluedIndex index) throws StorageException { 77 TransientIndex.KeyedReference entry = (TransientIndex.KeyedReference) this.map.get (key); 78 if (entry == null) 79 return null; 80 Object result = entry.get (); 81 if (result == null) 82 return null; 83 return index.get (result); 84 } 85 86 public Object getObject (Object key, SinglevaluedIndex index) throws StorageException { 87 Object result = this.getObjectIfExists (key, index); 88 if (result == null) 89 throw new StorageBadRequestException (); 90 return result; 91 } 92 93 94 public Storage.EntryType getKeyType() throws StorageException { 95 return Storage.EntryType.MOFID; 96 } 97 98 public String getName () throws StorageException { 99 return NAME; 100 } 101 102 public Storage.EntryType getValueType() throws StorageException { 103 return Storage.EntryType.STREAMABLE; 104 } 105 106 public java.util.Set keySet() throws StorageException { 107 throw new UnsupportedOperationException (); 108 } 109 110 public java.util.Collection values () throws StorageException { 111 throw new UnsupportedOperationException (); 112 } 113 114 public boolean remove(Object key) throws StorageException { 115 Object result = this.removeNoTx (key, null); 116 if (result != null) { 117 this.txlog.push ( new CompensatingTransaction.RemoveCTx (key, result)); 118 return true; 119 } 120 else { 121 return false; 122 } 123 } 124 125 public java.util.Collection queryByKeyPrefix (Object prefix, SinglevaluedIndex repos) { 126 throw new UnsupportedOperationException (); 127 } 128 129 protected Object removeNoTx(Object key, Object value) throws StorageException { 130 return this.map.remove (key); 131 } 132 133 } 134 | Popular Tags |