#50651: Fixed incorrect entering and leaving the transactions. BLD200410241800
authormmatula@netbeans.org
Thu, 21 Oct 2004 23:52:24 +0000
changeset 1605352aac312ec5
parent 1604 a818f68d8338
child 1606 21dba7fc4793
#50651: Fixed incorrect entering and leaving the transactions.
mdr/src/org/netbeans/mdr/handlers/AssociationHandler.java
mdr/src/org/netbeans/mdr/handlers/BaseObjectHandler.java
mdr/src/org/netbeans/mdr/handlers/ClassProxyHandler.java
mdr/src/org/netbeans/mdr/handlers/FeaturedHandler.java
     1.1 --- a/mdr/src/org/netbeans/mdr/handlers/AssociationHandler.java	Mon Oct 18 12:55:54 2004 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/handlers/AssociationHandler.java	Thu Oct 21 23:52:24 2004 +0000
     1.3 @@ -121,21 +121,28 @@
     1.4      }
     1.5      
     1.6      protected final Object _preAdd(RefObject associationEnd1, RefObject associationEnd2) {
     1.7 +        boolean fail = true;
     1.8          _lock(true);
     1.9 -        if (_getMdrStorage().eventsEnabled()) {
    1.10 -            AssociationEvent event = new AssociationEvent(
    1.11 -            this,
    1.12 -            AssociationEvent.EVENT_ASSOCIATION_ADD,
    1.13 -            associationEnd1,
    1.14 -            getAssociationDelegate().getEnd1Name(),
    1.15 -            null,
    1.16 -            associationEnd2,
    1.17 -            AssociationEvent.POSITION_NONE
    1.18 -            );
    1.19 -            _getMdrStorage().getEventNotifier().ASSOCIATION.firePlannedChange(this, event);
    1.20 -            return event;
    1.21 +        try {
    1.22 +            if (_getMdrStorage().eventsEnabled()) {
    1.23 +                AssociationEvent event = new AssociationEvent(
    1.24 +                this,
    1.25 +                AssociationEvent.EVENT_ASSOCIATION_ADD,
    1.26 +                associationEnd1,
    1.27 +                getAssociationDelegate().getEnd1Name(),
    1.28 +                null,
    1.29 +                associationEnd2,
    1.30 +                AssociationEvent.POSITION_NONE
    1.31 +                );
    1.32 +                _getMdrStorage().getEventNotifier().ASSOCIATION.firePlannedChange(this, event);
    1.33 +                fail = false;
    1.34 +                return event;
    1.35 +            }
    1.36 +            fail = false;
    1.37 +            return null;
    1.38 +        } finally {
    1.39 +            if (fail) _unlock(true);
    1.40          }
    1.41 -        return null;
    1.42      }
    1.43      
    1.44      protected final Boolean _handleAdd(RefObject associationEnd1, RefObject associationEnd2) {
    1.45 @@ -159,21 +166,28 @@
    1.46      }
    1.47      
    1.48      protected final Object _preRemove(RefObject associationEnd1, RefObject associationEnd2) {
    1.49 +        boolean fail = true;
    1.50          _lock(true);
    1.51 -        if (_getMdrStorage().eventsEnabled()) {
    1.52 -            AssociationEvent event = new AssociationEvent(
    1.53 -            this,
    1.54 -            AssociationEvent.EVENT_ASSOCIATION_REMOVE,
    1.55 -            associationEnd1,
    1.56 -            getAssociationDelegate().getEnd1Name(),
    1.57 -            associationEnd2,
    1.58 -            null,
    1.59 -            AssociationEvent.POSITION_NONE
    1.60 -            );
    1.61 -            _getMdrStorage().getEventNotifier().ASSOCIATION.firePlannedChange(this, event);
    1.62 -            return event;
    1.63 +        try {
    1.64 +            if (_getMdrStorage().eventsEnabled()) {
    1.65 +                AssociationEvent event = new AssociationEvent(
    1.66 +                this,
    1.67 +                AssociationEvent.EVENT_ASSOCIATION_REMOVE,
    1.68 +                associationEnd1,
    1.69 +                getAssociationDelegate().getEnd1Name(),
    1.70 +                associationEnd2,
    1.71 +                null,
    1.72 +                AssociationEvent.POSITION_NONE
    1.73 +                );
    1.74 +                _getMdrStorage().getEventNotifier().ASSOCIATION.firePlannedChange(this, event);
    1.75 +                fail = false;
    1.76 +                return event;
    1.77 +            }
    1.78 +            fail = false;
    1.79 +            return null;
    1.80 +        } finally {
    1.81 +            if (fail) _unlock(true);
    1.82          }
    1.83 -        return null;
    1.84      }
    1.85      
    1.86      protected final Boolean _handleRemove(RefObject associationEnd1, RefObject associationEnd2) {
    1.87 @@ -401,8 +415,8 @@
    1.88      /* ---------------------------------------------------------------- */
    1.89  
    1.90      protected final Collection _recursiveVerify(Collection violations, Set visited) {
    1.91 +        _lock(false);
    1.92          try {
    1.93 -            _lock(false);
    1.94              _verify(violations);
    1.95              visited.add(this);
    1.96              return violations;
    1.97 @@ -412,8 +426,8 @@
    1.98      }    
    1.99  
   1.100      protected Collection _verify(Collection violations) {
   1.101 +        _lock(false);
   1.102          try {
   1.103 -            _lock(false);
   1.104              getAssociationDelegate().verify(violations);
   1.105              return violations;
   1.106          } catch (StorageException e) {
     2.1 --- a/mdr/src/org/netbeans/mdr/handlers/BaseObjectHandler.java	Mon Oct 18 12:55:54 2004 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/handlers/BaseObjectHandler.java	Thu Oct 21 23:52:24 2004 +0000
     2.3 @@ -287,22 +287,29 @@
     2.4      /* --------------------------------------------------------------------- */
     2.5  
     2.6      public final RefObject refMetaObject() {
     2.7 +        _lock(false);
     2.8          try {
     2.9              return (RefObject) _getRepository().getHandler(_getDelegate().getMetaObject());
    2.10          } catch (StorageException e) {
    2.11              throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
    2.12 +        } finally {
    2.13 +            _unlock();
    2.14          }
    2.15      }
    2.16  
    2.17      public final RefPackage refImmediatePackage() {
    2.18 +        _lock(false);
    2.19          try {
    2.20              return (RefPackage) _getRepository().getHandler(_getDelegate().getImmediatePackage());
    2.21          } catch (StorageException e) {
    2.22              throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
    2.23 +        } finally {
    2.24 +            _unlock();
    2.25          }
    2.26      }
    2.27  
    2.28      public final RefPackage refOutermostPackage() {
    2.29 +        _lock(false);
    2.30          try {
    2.31              StorableBaseObject pkg = _getDelegate().getOutermostPackage();
    2.32              if (pkg.getMofId().equals(_getDelegate().getMofId())) {
    2.33 @@ -312,6 +319,8 @@
    2.34              }
    2.35          } catch (StorageException e) {
    2.36              throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
    2.37 +        } finally {
    2.38 +            _unlock();
    2.39          }
    2.40      }
    2.41  
    2.42 @@ -320,8 +329,13 @@
    2.43      }
    2.44      
    2.45      public final Collection refVerifyConstraints(boolean deepVerify) {
    2.46 -        if (deepVerify) return _recursiveVerify(new ArrayList(), new HashSet());
    2.47 -        else return _verify(new ArrayList());
    2.48 +        _lock(false);
    2.49 +        try {
    2.50 +            if (deepVerify) return _recursiveVerify(new ArrayList(), new HashSet());
    2.51 +            else return _verify(new ArrayList());
    2.52 +        } finally {
    2.53 +            _unlock();
    2.54 +        }
    2.55      }
    2.56      
    2.57      /* --------------------------------------------------------------------- */
     3.1 --- a/mdr/src/org/netbeans/mdr/handlers/ClassProxyHandler.java	Mon Oct 18 12:55:54 2004 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/handlers/ClassProxyHandler.java	Thu Oct 21 23:52:24 2004 +0000
     3.3 @@ -51,15 +51,22 @@
     3.4      /* -------------------------------------------------------------------- */
     3.5      
     3.6      protected final Object _preCreate(Object params[]) {
     3.7 +        boolean fail = true;
     3.8          _lock(true);
     3.9 -        if (_getMdrStorage().eventsEnabled()) {
    3.10 -            CreateInstanceEvent event = new CreateInstanceEvent(
    3.11 -                params == null ? null : new ImmutableList(params)
    3.12 -            );
    3.13 -            _getMdrStorage().getEventNotifier().CLASS.firePlannedChange(this, event);
    3.14 -            return event;
    3.15 +        try {
    3.16 +            if (_getMdrStorage().eventsEnabled()) {
    3.17 +                CreateInstanceEvent event = new CreateInstanceEvent(
    3.18 +                    params == null ? null : new ImmutableList(params)
    3.19 +                );
    3.20 +                _getMdrStorage().getEventNotifier().CLASS.firePlannedChange(this, event);
    3.21 +                fail = false;
    3.22 +                return event;
    3.23 +            }
    3.24 +            fail = false;
    3.25 +            return null;
    3.26 +        } finally {
    3.27 +            if (fail) _unlock(true);
    3.28          }
    3.29 -        return null;
    3.30      }
    3.31  
    3.32      protected final RefObject _handleCreate(Object params[]) {
    3.33 @@ -296,8 +303,8 @@
    3.34      /* ---------------------------------------------------------------- */
    3.35  
    3.36      protected final Collection _recursiveVerify(Collection violations, Set visited) {
    3.37 +        _lock(false);
    3.38          try {
    3.39 -            _lock(false);
    3.40              _verify(violations);
    3.41              visited.add(this);
    3.42              for (Iterator it = refAllOfClass().iterator(); it.hasNext();) {
    3.43 @@ -311,8 +318,8 @@
    3.44      }    
    3.45  
    3.46      protected Collection _verify(Collection violations) {
    3.47 +        _lock(false);
    3.48          try {
    3.49 -            _lock(false);
    3.50              getClassDelegate().verify(violations);
    3.51              return violations;
    3.52          } finally {
     4.1 --- a/mdr/src/org/netbeans/mdr/handlers/FeaturedHandler.java	Mon Oct 18 12:55:54 2004 +0000
     4.2 +++ b/mdr/src/org/netbeans/mdr/handlers/FeaturedHandler.java	Thu Oct 21 23:52:24 2004 +0000
     4.3 @@ -67,28 +67,35 @@
     4.4      }
     4.5      
     4.6      protected final Object _preSet(String featureName, Object newValue) {
     4.7 +        boolean fail = true;
     4.8          _lock(true);
     4.9 -        if (_getMdrStorage().eventsEnabled()) {
    4.10 -            Object oldValue = _getAttribute(featureName);
    4.11 -    //        if (newValue == oldValue || (newValue != null && newValue.equals(oldValue))) {
    4.12 -    //            return null;
    4.13 -    //        } else {
    4.14 -                AttributeEvent event = new AttributeEvent(
    4.15 -                    this, 
    4.16 -                    AttributeEvent.EVENT_ATTRIBUTE_SET, 
    4.17 -                    featureName, 
    4.18 -                    oldValue, 
    4.19 -                    newValue, 
    4.20 -                    AttributeEvent.POSITION_NONE
    4.21 -                );
    4.22 -                if (this instanceof RefObject) {
    4.23 -                    _getMdrStorage().getEventNotifier().INSTANCE.firePlannedChange(this, event);
    4.24 -                } else {
    4.25 -                    _getMdrStorage().getEventNotifier().CLASS.firePlannedChange(this, event);
    4.26 -                }
    4.27 -                return event;
    4.28 +        try {
    4.29 +            if (_getMdrStorage().eventsEnabled()) {
    4.30 +                Object oldValue = _getAttribute(featureName);
    4.31 +        //        if (newValue == oldValue || (newValue != null && newValue.equals(oldValue))) {
    4.32 +        //            return null;
    4.33 +        //        } else {
    4.34 +                    AttributeEvent event = new AttributeEvent(
    4.35 +                        this, 
    4.36 +                        AttributeEvent.EVENT_ATTRIBUTE_SET, 
    4.37 +                        featureName, 
    4.38 +                        oldValue, 
    4.39 +                        newValue, 
    4.40 +                        AttributeEvent.POSITION_NONE
    4.41 +                    );
    4.42 +                    if (this instanceof RefObject) {
    4.43 +                        _getMdrStorage().getEventNotifier().INSTANCE.firePlannedChange(this, event);
    4.44 +                    } else {
    4.45 +                        _getMdrStorage().getEventNotifier().CLASS.firePlannedChange(this, event);
    4.46 +                    }
    4.47 +                    fail = false;
    4.48 +                    return event;
    4.49 +            }
    4.50 +            fail = false;
    4.51 +            return null;
    4.52 +        } finally {
    4.53 +            if (fail) _unlock(true);
    4.54          }
    4.55 -        return null;
    4.56  //        }
    4.57      }
    4.58      
    4.59 @@ -108,8 +115,8 @@
    4.60      }
    4.61  
    4.62      public void refSetValue(String featureName, java.lang.Object value) {
    4.63 +        _lock(true);
    4.64          try {
    4.65 -            _lock(true);
    4.66              _setAttribute(featureName, value); 
    4.67          } finally {
    4.68              _unlock();
    4.69 @@ -117,8 +124,8 @@
    4.70      }
    4.71      
    4.72      public void refSetValue(RefObject feature, Object value) {
    4.73 +        _lock(true);
    4.74          try {
    4.75 -            _lock(true);
    4.76  /*            StorableClass cls = getFeaturedDelegate().getClassProxy();
    4.77              try {
    4.78                  StorableClass.AttributeDescriptor desc = cls.getAttrDesc(((Attribute) feature).getName());
    4.79 @@ -140,8 +147,8 @@
    4.80      }
    4.81  
    4.82      public Object refGetValue(String featureName) {
    4.83 +        _lock(false);
    4.84          try {
    4.85 -            _lock(false);
    4.86              return _getAttribute(featureName);
    4.87          } finally {
    4.88              _unlock();
    4.89 @@ -149,8 +156,8 @@
    4.90      }
    4.91      
    4.92      public Object refGetValue(RefObject feature) {
    4.93 +        _lock(false);
    4.94          try {
    4.95 -            _lock(false);
    4.96              /*
    4.97              StorableClass cls = getFeaturedDelegate().getClassProxy();
    4.98              try {