1.1 --- a/mdr/src/org/netbeans/mdr/persistence/Storage.java Wed Sep 25 15:17:25 2002 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/Storage.java Thu Sep 26 14:52:36 2002 +0000
1.3 @@ -207,12 +207,23 @@
1.4 public void dropIndex(String name) throws StorageException;
1.5
1.6 /** Notify the Storage that state of the object associated with this key
1.7 + * will be changed. This must be called before the change.
1.8 + * Storage can use this notification to handle information needed to
1.9 + * perform rollback. Note that the notification does not imply object
1.10 + * change will perform necessary (the planned change can be canceled),
1.11 + * however every performed change (notified by {@link Storage#objectStateChanged})
1.12 + * is supposed to be precedesed by this notification.
1.13 + * @param key key of the object that will be changed
1.14 + */
1.15 + public void objectStateWillChange (Object key) throws StorageException;
1.16 +
1.17 + /** Notify the Storage that state of the object associated with this key
1.18 * was changed. This must be called after the change is made to ensure
1.19 * that the changed state is comitted correctly.
1.20 * @param key key of the object that was changed and must be saved
1.21 */
1.22 - public void objectStateChanged (Object key) throws StorageException;
1.23 -
1.24 + public void objectStateChanged (Object key) throws StorageException;
1.25 +
1.26 /** Save all objects changed since this method was last call.
1.27 * This operation implements transactions on the storage.
1.28 * It must either whole complete or whole fail.
2.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeStorage.java Wed Sep 25 15:17:25 2002 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeStorage.java Thu Sep 26 14:52:36 2002 +0000
2.3 @@ -289,6 +289,13 @@
2.4 btreeDB.dropIndex(name);
2.5 }
2.6
2.7 + /** Notify the Storage that state of the object will be changed.
2.8 + * @param key key of object that will be changed
2.9 + */
2.10 + public void objectStateWillChange(Object key) throws StorageException {
2.11 + // do nothing
2.12 + }
2.13 +
2.14 /** Notify the Storage that state of the object was changed.
2.15 * @param key key of object that was changed
2.16 */
3.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/PrimaryIndexImpl.java Wed Sep 25 15:17:25 2002 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/PrimaryIndexImpl.java Thu Sep 26 14:52:36 2002 +0000
3.3 @@ -115,9 +115,6 @@
3.4 if (value == null) {
3.5 throw new StorageBadRequestException ("Item not found: " + key);
3.6 } else {
3.7 - if (!transLog.isLogged(key)) {
3.8 - transLog.logValue (key, createValueLog(value));
3.9 - }
3.10 return value;
3.11 }
3.12 }
3.13 @@ -129,15 +126,19 @@
3.14 * @throws StorageException
3.15 */
3.16 public Object getIfExists(Object key) throws StorageException {
3.17 - Object value = table.get (key);
3.18 - if ((value != null)&&(!transLog.isLogged(key))) {
3.19 + return table.get (key);
3.20 + }
3.21 +
3.22 + public void willChange (Object key) throws StorageException {
3.23 + if (!transLog.isLogged(key)) {
3.24 + Object value = table.get (key);
3.25 transLog.logValue (key, createValueLog (value));
3.26 }
3.27 - return value;
3.28 + transLog.setDirty(key);
3.29 }
3.30 -
3.31 - public void changed (Object key) {
3.32 - transLog.setDirty(key);
3.33 +
3.34 + public void changed (Object key) {
3.35 + // do nothing
3.36 }
3.37
3.38 private PrimaryValueLog createValueLog (Object value) throws StorageException {
4.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/SinglevaluedIndexImpl.java Wed Sep 25 15:17:25 2002 +0000
4.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/SinglevaluedIndexImpl.java Thu Sep 26 14:52:36 2002 +0000
4.3 @@ -302,19 +302,11 @@
4.4
4.5 /* -------------------------------------------------------------------- */
4.6 /* -- Transaction support --------------------------------------------- */
4.7 - /* -------------------------------------------------------------------- */
4.8 + /* -------------------------------------------------------------------- */
4.9
4.10 - protected boolean debug = false;
4.11 -
4.12 - protected void rollBackChanges () throws StorageException {
4.13 -
4.14 - debug = true;
4.15 -
4.16 + protected void rollBackChanges () throws StorageException {
4.17 transLog.rollBack ();
4.18 - transLog.clear ();
4.19 -
4.20 - debug = false;
4.21 -
4.22 + transLog.clear ();
4.23 }
4.24
4.25 protected void commitChanges () throws StorageException {
5.1 --- a/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageImpl.java Wed Sep 25 15:17:25 2002 +0000
5.2 +++ b/mdr/src/org/netbeans/mdr/persistence/memoryimpl/StorageImpl.java Thu Sep 26 14:52:36 2002 +0000
5.3 @@ -166,6 +166,10 @@
5.4 Logger.getDefault().log("Finished reading document.");
5.5 }
5.6
5.7 + public void objectStateWillChange(Object key) throws StorageException {
5.8 + ((PrimaryIndexImpl) primaryIndex).willChange (key);
5.9 + }
5.10 +
5.11 public void objectStateChanged(Object key) throws StorageException {
5.12 primaryIndex.changed (key);
5.13 }
6.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java Wed Sep 25 15:17:25 2002 +0000
6.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java Thu Sep 26 14:52:36 2002 +0000
6.3 @@ -123,6 +123,7 @@
6.4 public boolean add(Object obj) {
6.5 checkType(obj);
6.6 checkMaxSize(inner.size() + 1);
6.7 + mdrObject.objectWillChange();
6.8 if (isIndexed)
6.9 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
6.10 boolean result = inner.add(obj);
6.11 @@ -182,8 +183,9 @@
6.12 }
6.13
6.14 public boolean remove(Object obj) {
6.15 + mdrObject.objectWillChange();
6.16 if (isIndexed)
6.17 - ((StorableObject) mdrObject).removeFromIndex (metaMofId);
6.18 + ((StorableObject) mdrObject).removeFromIndex (metaMofId);
6.19 boolean result = inner.remove(obj);
6.20 if (result) {
6.21 if (isRefObject) {
6.22 @@ -259,8 +261,9 @@
6.23 }
6.24
6.25 public void remove() {
6.26 + mdrObject.objectWillChange();
6.27 if (isIndexed)
6.28 - ((StorableObject) mdrObject).removeFromIndex (metaMofId);
6.29 + ((StorableObject) mdrObject).removeFromIndex (metaMofId);
6.30 inner.remove();
6.31 if (isRefObject) {
6.32 try {
7.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java Wed Sep 25 15:17:25 2002 +0000
7.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java Thu Sep 26 14:52:36 2002 +0000
7.3 @@ -48,10 +48,11 @@
7.4 public void add(int param, Object obj) {
7.5 checkType(obj);
7.6 checkMaxSize(size() + 1);
7.7 -
7.8 +
7.9 + mdrObject.objectWillChange();
7.10 +
7.11 if (isIndexed)
7.12 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
7.13 -
7.14 innerList.add(param, obj);
7.15 if (isRefObject) {
7.16 try {
7.17 @@ -92,10 +93,11 @@
7.18 return new AttrListIterator(innerList.listIterator(param));
7.19 }
7.20
7.21 - public Object remove(int param) {
7.22 + public Object remove(int param) {
7.23 + mdrObject.objectWillChange();
7.24 if (isIndexed)
7.25 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
7.26 -
7.27 +
7.28 Object result = innerList.remove(param);
7.29 if (isRefObject) {
7.30 try {
7.31 @@ -115,6 +117,7 @@
7.32 public Object set(int param, Object obj) {
7.33 checkType(obj);
7.34
7.35 + mdrObject.objectWillChange();
7.36 if (isIndexed)
7.37 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
7.38
7.39 @@ -151,6 +154,8 @@
7.40 checkType(obj);
7.41 checkMaxSize(innerList.size() + 1);
7.42
7.43 + mdrObject.objectWillChange();
7.44 +
7.45 if (isIndexed)
7.46 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
7.47
7.48 @@ -188,6 +193,8 @@
7.49 public void set(Object obj) {
7.50 checkType(obj);
7.51
7.52 + mdrObject.objectWillChange();
7.53 +
7.54 if (isIndexed)
7.55 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
7.56
8.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Wed Sep 25 15:17:25 2002 +0000
8.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Thu Sep 26 14:52:36 2002 +0000
8.3 @@ -1428,6 +1428,14 @@
8.4 return new org.netbeans.mdr.persistence.MOFID (storage);
8.5 }
8.6
8.7 + public void objectStateWillChange(org.netbeans.mdr.persistence.MOFID mofId) throws StorageException {
8.8 + Storage storage = this.getStorageByMofId(mofId);
8.9 + if (storage == null) {
8.10 + throw new DebugException("Storage not found");
8.11 + }
8.12 + storage.objectStateWillChange(mofId);
8.13 + }
8.14 +
8.15 public void objectStateChanged(org.netbeans.mdr.persistence.MOFID mofId) throws StorageException {
8.16 Storage storage = this.getStorageByMofId(mofId);
8.17 if (storage == null) {
9.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableAssociation.java Wed Sep 25 15:17:25 2002 +0000
9.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableAssociation.java Thu Sep 26 14:52:36 2002 +0000
9.3 @@ -70,6 +70,7 @@
9.4 * @param table Map of old MOFIDs to new MOFIDs.
9.5 */
9.6 protected void replaceValues(Map table) {
9.7 + objectWillChange();
9.8 org.netbeans.mdr.persistence.MOFID backup1 = endAId;
9.9 org.netbeans.mdr.persistence.MOFID backup2 = endBId;
9.10
9.11 @@ -136,6 +137,7 @@
9.12 if (associationSuperclass == null) {
9.13 synchronized (superclassMutex) {
9.14 if (associationSuperclass == null) {
9.15 + objectWillChange();
9.16 associationSuperclass = resolveAssociationSuperclass();
9.17 objectChanged();
9.18 }
10.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableBaseObject.java Wed Sep 25 15:17:25 2002 +0000
10.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableBaseObject.java Thu Sep 26 14:52:36 2002 +0000
10.3 @@ -231,6 +231,7 @@
10.4 public void putProperty (Object key, Object value) {
10.5 if (key == null || value == null || !IOUtils.checkObjectValidity (key) || !IOUtils.checkObjectValidity (value))
10.6 throw new IllegalArgumentException ();
10.7 + this.objectWillChange();
10.8 if (this.handlerProperties == null) {
10.9 this.handlerProperties = new HashMap ();
10.10 }
10.11 @@ -255,6 +256,7 @@
10.12 boolean failed = true;
10.13 try {
10.14 this.mdrStorage.getRepositoryMutex ().enter (true);
10.15 + this.objectWillChange();
10.16 Object result = this.handlerProperties.remove (key);
10.17 if (result != null) {
10.18 this.objectChanged ();
10.19 @@ -287,6 +289,17 @@
10.20 meta = (org.netbeans.mdr.persistence.MOFID) table.get(meta);
10.21 }
10.22
10.23 + /** Signals to the storage that this object will be changed.
10.24 + */
10.25 + protected void objectWillChange() {
10.26 + if (initFinished)
10.27 + try {
10.28 + getMdrStorage().objectStateWillChange(id);
10.29 + } catch (StorageException e) {
10.30 + throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
10.31 + }
10.32 + }
10.33 +
10.34 /** Signals to the storage that this object has been changed.
10.35 */
10.36 protected void objectChanged() {
11.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableClass.java Wed Sep 25 15:17:25 2002 +0000
11.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableClass.java Thu Sep 26 14:52:36 2002 +0000
11.3 @@ -88,6 +88,7 @@
11.4 * @param table Map of old MOFIDs to new MOFIDs.
11.5 */
11.6 protected void replaceValues(Map table) {
11.7 + objectWillChange();
11.8 super.replaceValues(table);
11.9
11.10 // rebuild all attributes
11.11 @@ -149,6 +150,7 @@
11.12 }
11.13
11.14 public void buildAdditionalIndexes(List indexTags, Map associationProxies) throws StorageException {
11.15 + objectWillChange();
11.16 indexDescs = new IndexDescriptor [indexTags.size ()];
11.17 Iterator iter = indexTags.iterator ();
11.18 for (int y = 0; iter.hasNext (); y++) {
11.19 @@ -263,6 +265,7 @@
11.20
11.21 // this is always called from a synchronized section
11.22 public void addSubclass(org.netbeans.mdr.persistence.MOFID mofId) {
11.23 + objectWillChange();
11.24 subclasses.add(mofId);
11.25 objectChanged();
11.26 }
11.27 @@ -272,6 +275,7 @@
11.28 if (attributes != null) {
11.29 throw new DebugException("bad thing in: " + getMofId());
11.30 }
11.31 + objectWillChange();
11.32 superclasses.add(mofId);
11.33 objectChanged();
11.34 }
11.35 @@ -286,6 +290,7 @@
11.36
11.37 // always synchronized
11.38 public void addReferenceDescriptor(org.netbeans.mdr.persistence.MOFID mofId, String name, org.netbeans.mdr.persistence.MOFID assocProxyId, String endName) {
11.39 + objectWillChange();
11.40 references.put(name, new ReferenceDescriptor(mofId, assocProxyId, endName));
11.41 objectChanged();
11.42 }
11.43 @@ -312,6 +317,7 @@
11.44 StorableClass cls = getClsForAttr(name);
11.45 if (cls == null) throw new DebugException("Classifier-level attribute '" + name + "' not found.");
11.46
11.47 + cls.objectWillChange();
11.48 AttributeDescriptor attribute = (AttributeDescriptor) cls.clAttrDescs.get(name);
11.49 Object oldValue = cls.clAttrValues.put(name, value);
11.50
11.51 @@ -467,6 +473,7 @@
11.52 if (classSuperclass == null) {
11.53 synchronized (superclassMutex) {
11.54 if (classSuperclass == null) {
11.55 + objectWillChange();
11.56 classSuperclass = resolveClassSuperclass(new Class[1]).getName();
11.57 objectChanged();
11.58 }
11.59 @@ -487,6 +494,7 @@
11.60 if (instanceSuperclass == null) {
11.61 synchronized (superclassMutex) {
11.62 if (instanceSuperclass == null) {
11.63 + objectWillChange();
11.64 instanceSuperclass = resolveInstanceSuperclass(new Class[1]).getName();
11.65 objectChanged();
11.66 }
12.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java Wed Sep 25 15:17:25 2002 +0000
12.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java Thu Sep 26 14:52:36 2002 +0000
12.3 @@ -47,6 +47,7 @@
12.4 private org.netbeans.mdr.persistence.MOFID attribComposite = null;
12.5
12.6 protected void replaceValues(Map table) {
12.7 + objectWillChange();
12.8 super.replaceValues(table);
12.9 objectChanged();
12.10 }
12.11 @@ -97,7 +98,7 @@
12.12 StorableClass.AttributeDescriptor attribute = getClassProxy().getAttrDesc(attrIndex);
12.13
12.14 Object oldValue = values[attrIndex];
12.15 -
12.16 + objectWillChange();
12.17 values[attrIndex] = value;
12.18
12.19 if (!attribute.isMultivalued() && (value instanceof RefObject)) {
12.20 @@ -232,6 +233,7 @@
12.21 * @param id immediate composite object
12.22 */
12.23 void setComposite(StorableBaseObject composite, org.netbeans.mdr.persistence.MOFID objectId, org.netbeans.mdr.persistence.MOFID elementId) throws StorageException {
12.24 + objectWillChange();
12.25 if (composite == null) {
12.26 attribComposite = null;
12.27 } else {
13.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorablePackage.java Wed Sep 25 15:17:25 2002 +0000
13.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorablePackage.java Thu Sep 26 14:52:36 2002 +0000
13.3 @@ -38,6 +38,7 @@
13.4 * @param table Map of old MOFIDs to new MOFIDs.
13.5 */
13.6 protected void replaceValues(Map table) {
13.7 + objectWillChange();
13.8 super.replaceValues(table);
13.9 objectChanged();
13.10 }
13.11 @@ -63,6 +64,7 @@
13.12 if (packageSuperclass == null) {
13.13 synchronized (superclassMutex) {
13.14 if (packageSuperclass == null) {
13.15 + objectWillChange();
13.16 packageSuperclass = resolvePackageSuperclass();
13.17 objectChanged();
13.18 }
13.19 @@ -97,16 +99,19 @@
13.20 }
13.21
13.22 public void addPackage(String metaName, org.netbeans.mdr.persistence.MOFID mofId) {
13.23 + objectWillChange();
13.24 packageProxies.put(metaName, mofId);
13.25 objectChanged();
13.26 }
13.27
13.28 public void addClass(String metaName, org.netbeans.mdr.persistence.MOFID mofId) {
13.29 + objectWillChange();
13.30 classProxies.put(metaName, mofId);
13.31 objectChanged();
13.32 }
13.33
13.34 public void addAssociation(String metaName, org.netbeans.mdr.persistence.MOFID mofId) {
13.35 + objectWillChange();
13.36 assocProxies.put(metaName, mofId);
13.37 objectChanged();
13.38 }
13.39 @@ -264,6 +269,7 @@
13.40 }
13.41
13.42 private void init(org.netbeans.mdr.persistence.MOFID packageId, String mofContext, Map datatypes) throws StorageException {
13.43 + objectWillChange();
13.44 this.packageProxies = new HashMap();
13.45 this.assocProxies = new HashMap();
13.46 this.classProxies = new HashMap();
14.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/transientimpl/TransientStorage.java Wed Sep 25 15:17:25 2002 +0000
14.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/transientimpl/TransientStorage.java Thu Sep 26 14:52:36 2002 +0000
14.3 @@ -221,7 +221,11 @@
14.4 Object index = this.indexes.remove (name);
14.5 this.indexTxLog.push ( new CompensatingTransaction.DropIndexCTx (name, index));
14.6 }
14.7 -
14.8 +
14.9 + public void objectStateWillChange (Object key) throws StorageException {
14.10 + // do nothing
14.11 + }
14.12 +
14.13 /** Notify the Storage that state of the object associated with this key
14.14 * was changed. This must be called after the change is made to ensure
14.15 * that the changed state is comitted correctly.