1 19 20 package org.netbeans.mdr.storagemodel; 21 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import org.netbeans.mdr.persistence.MOFID; 26 import org.netbeans.mdr.persistence.StorageException; 27 import org.netbeans.mdr.storagemodel.transientimpl.TransientStorage; 28 import org.netbeans.mdr.util.DebugException; 29 import org.netbeans.mdr.util.Logger; 30 31 35 public class TransientStorableObject extends StorableObject implements Transient { 36 37 private ArrayList referentQueue; 38 private HashMap attrTxLog; 39 40 41 public TransientStorableObject() { 42 super (); 43 this.attrTxLog = new HashMap (); 44 } 45 46 public TransientStorableObject (MdrStorage mdrStorage, MOFID immediatePackage, MOFID meta, MOFID classProxy) throws StorageException { 47 this (mdrStorage, immediatePackage, meta, classProxy, null); 48 } 49 50 public TransientStorableObject (MdrStorage mdrStorage, MOFID immediatePackage, MOFID meta, MOFID classProxy, Object [] params) throws StorageException { 51 super (mdrStorage, immediatePackage, meta, classProxy, params, TransientStorage.STORAGE_ID); 52 this.attrTxLog = new HashMap (); 53 } 54 55 56 public void delete () throws StorageException { 57 this.deleteRecursive (); 58 } 59 60 public void write(java.io.OutputStream outputStream) { 61 throw new DebugException ("Trying to write tranient object"); 62 } 63 64 public void read (java.io.InputStream inputStream) { 65 throw new DebugException ("Trying to read transient object"); 66 } 67 68 public void addReferent (TransientStorableObject referent) { 69 if (this.referentQueue == null) 70 this.referentQueue = new ArrayList (); 71 this.referentQueue.add (referent); 72 } 73 74 public void removeReferent (TransientStorableObject referent) { 75 if (this.referentQueue == null) 76 return; 77 this.referentQueue.remove (referent); 78 } 79 80 84 public void setAttribute (int index, Object value) throws StorageException { 85 check (); 86 Object oldValue = values[index]; 87 super.setAttribute (index, value); 88 Integer key = new Integer (index); 89 if (!attrTxLog.containsKey (key)) { 90 this.attrTxLog.put (key, oldValue); 91 } 92 } 93 94 97 public void commit () { 98 this.attrTxLog.clear (); 99 } 100 101 104 public void rollBack () { 105 for (Iterator it = this.attrTxLog.keySet ().iterator (); it.hasNext ();) { 106 Integer key = (Integer ) it.next (); 107 Object value = this.attrTxLog.get (key); 108 it.remove (); 109 try { 110 super.setAttribute (key.intValue (), value); 111 } catch (StorageException se) { 112 Logger.getDefault().notify(Logger.INFORMATIONAL, se); 113 } 114 } 115 } 116 117 protected void deleteRecursive () throws StorageException { 118 this.getMdrStorage().removeInstance (this); 119 } 120 121 124 125 protected void modifyIndex (int attrIdx, Object oldValue, Object newValue) throws StorageException { 126 } 127 128 void addToIndex (String proxyId, String endId) throws StorageException { 129 } 130 131 void removeFromIndex (String proxyId, String endId) throws StorageException { 132 } 133 134 } 135 | Popular Tags |