tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fra...@apache.org
Subject svn commit: r491909 - in /incubator/tuscany/java/sdo/impl/src: main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java
Date Tue, 02 Jan 2007 19:46:20 GMT
Author: frankb
Date: Tue Jan  2 11:46:19 2007
New Revision: 491909

URL: http://svn.apache.org/viewvc?view=rev&rev=491909
Log:
Fix for TUSCANY-859

Added:
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java
Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java?view=diff&rev=491909&r1=491908&r2=491909
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ChangeSummaryImpl.java
Tue Jan  2 11:46:19 2007
@@ -87,12 +87,14 @@
    * @ordered
    */
   protected DataGraph eDataGraph = null;
-
+  
   protected DataObject dataObject = null;
-
-  protected ChangeRecorder changeRecorder = null;
-  protected EList cachedObjectsToDetach = null;
+  protected SDOChangeRecorder changeRecorder = null;
+  
+  protected Set cachedDeletedObjects = null;
+  protected List cachedCreatedObjects = null;
   protected HashMap cachedSDOObjectChanges = new HashMap();  
+  protected boolean isStale = false;
 
   /**
    * <!-- begin-user-doc -->
@@ -197,8 +199,8 @@
     getObjectsToAttach().clear();
     getObjectChanges().clear();
     getResourceChanges().clear();
-
     oldContainmentInformation = null;
+
     beginRecording();
 //    if (eNotificationRequired())
 //      eNotify(new ENotificationImpl(this, Notification.SET, SDOPackage.ECHANGE_SUMMARY__LOGGING,
false, true));
@@ -238,7 +240,6 @@
     oldContainmentInformation = null;
     
     beginRecording();
-    
 //    if (eNotificationRequired())
 //      eNotify(new ENotificationImpl(this, Notification.SET, SDOPackage.ECHANGE_SUMMARY__LOGGING,
false, true));
   }  
@@ -401,6 +402,13 @@
     return eDynamicIsSet(featureID);
   }
 
+  protected void uncache()
+  {
+    cachedDeletedObjects = null;
+    cachedCreatedObjects = null;
+    cachedSDOObjectChanges.clear();
+  }
+
   protected class SDOChangeRecorder extends ChangeRecorder
   {
     public SDOChangeRecorder()
@@ -410,9 +418,7 @@
     
     public void beginRecording(ChangeDescription changeDescription, Collection rootObjects)
     {
-      deletedObjects = null;
-      cachedObjectsToDetach = null;
-      cachedSDOObjectChanges.clear();
+      uncache();
       super.beginRecording(changeDescription, rootObjects);
     }
 
@@ -439,9 +445,8 @@
     
     protected void consolidateChanges()
     {
-      deletedObjects = null;
-      cachedObjectsToDetach = null;
-      cachedSDOObjectChanges.clear();
+      uncache();
+      isStale = false;
       super.consolidateChanges();
     }
 
@@ -461,6 +466,25 @@
         super.removeAdapter(notifier);
     }
     
+    public void notifyChanged(Notification notification) 
+    { 
+      super.notifyChanged(notification);
+
+      Object notifier = notification.getNotifier();
+      if (notifier instanceof EObject)
+      {
+        cachedSDOObjectChanges.remove(notifier);
+        Object feature = notification.getFeature();
+        if (feature instanceof Property && ((Property)feature).isContainment())
+        {
+          cachedCreatedObjects = null;
+          cachedDeletedObjects = null;
+          oldContainmentInformation = null;
+        }
+        isStale = true;
+      }
+    }
+
   } 
 
   /**
@@ -489,7 +513,7 @@
    */
   public boolean isCreated(DataObject dataObject)
   {
-    return getObjectsToDetach().contains(dataObject);
+    return getCachedCreatedObjects().contains(dataObject);
   }
 
   /**
@@ -499,7 +523,48 @@
    */
   public boolean isDeleted(DataObject dataObject)
   {
-    return getDeletedObjects().contains(dataObject);
+    return getCachedDeletedObjects().contains(dataObject);
+  }
+
+  protected Set getCachedDeletedObjects()
+  {
+    if (cachedDeletedObjects == null)
+    {
+      if (isStale()) changeRecorder.consolidateChanges();
+      cachedDeletedObjects = new HashSet();
+      for (Iterator i = EcoreUtil.getAllContents(getObjectsToAttach()); i.hasNext(); )
+      {
+        cachedDeletedObjects.add(i.next());
+      }
+    }
+    return cachedDeletedObjects;
+  }
+
+  protected List getCachedCreatedObjects()
+  {
+    if (cachedCreatedObjects == null)
+    {
+      if (isStale()) changeRecorder.consolidateChanges();
+      cachedCreatedObjects = super.getObjectsToDetach();
+    }
+    return cachedCreatedObjects;
+  }
+  
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated NOT
+   */
+  public List getChangedDataObjects()
+  {
+    EList result = new UniqueEList.FastCompare(getCachedDeletedObjects());
+    result.addAll(getCachedCreatedObjects());
+    for (Iterator i = getObjectChanges().iterator(); i.hasNext(); )
+    {
+      Map.Entry entry = (Map.Entry)i.next();
+      result.add(entry.getKey());
+    }
+    return result;
   }
 
   /**
@@ -514,7 +579,8 @@
     {
       return sdoSettings;
     }
-    
+
+    if (isStale()) changeRecorder.consolidateChanges();
     List settings = (List)getObjectChanges().get(dataObject);
     if (settings == null)
     {
@@ -634,16 +700,11 @@
     {
       changeRecorder.summarize();
     }
-    apply();
-  }
-
-  public EList getObjectsToDetach()
-  {
-    if (cachedObjectsToDetach == null)
+    else
     {
-      cachedObjectsToDetach = super.getObjectsToDetach();
+      uncache();
     }
-    return cachedObjectsToDetach;
+    apply();
   }
 
   /**
@@ -656,43 +717,19 @@
     return getEDataGraph();
   }
   
-
-  protected Set deletedObjects;
-
-  protected void preApply(boolean reverse)
+  protected Map getOldContainmentInformation()
   {
-    super.preApply(reverse);
-    deletedObjects = null;
-  }
-
-  protected Set getDeletedObjects()
-  {
-    if (deletedObjects == null)
+    if (oldContainmentInformation == null)
     {
-      deletedObjects = new HashSet();
-      for (Iterator i = EcoreUtil.getAllContents(getObjectsToAttach()); i.hasNext(); )
-      {
-        deletedObjects.add(i.next());
-      }
+      if (isStale()) changeRecorder.consolidateChanges();
+      super.getOldContainmentInformation();
     }
-    return deletedObjects;
+    return oldContainmentInformation;
   }
 
-  /**
-   * <!-- begin-user-doc -->
-   * <!-- end-user-doc -->
-   * @generated NOT
-   */
-  public List getChangedDataObjects()
+  protected boolean isStale()
   {
-    EList result = new UniqueEList.FastCompare(getDeletedObjects());
-    result.addAll(getObjectsToDetach());
-    for (Iterator i = getObjectChanges().iterator(); i.hasNext(); )
-    {
-      Map.Entry entry = (Map.Entry)i.next();
-      result.add(entry.getKey());
-    }
-    return result;
+    return isLogging() && isStale;
   }
 
   /**
@@ -713,4 +750,4 @@
     return null;
   }
 
-} //EChangeSummaryImpl
+} //ChangeSummaryImpl

Added: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java?view=auto&rev=491909
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java
(added)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java
Tue Jan  2 11:46:19 2007
@@ -0,0 +1,76 @@
+/**
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.tuscany.sdo.test;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import commonj.sdo.ChangeSummary;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class NeverStaleChangeSummaryTestCase extends TestCase {
+    private final String TEST_MODEL = "/simpleWithChangeSummary.xsd";
+    private final String TEST_NAMESPACE = "http://www.example.com/simpleCS";
+
+    /**
+     * Simple ChangeSummary test.
+     */
+    public void testChangeSummary() throws Exception {
+        Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "RootQuote");
+        DataObject quote = DataFactory.INSTANCE.create(quoteType);
+
+        ChangeSummary cs = quote.getChangeSummary();
+
+        // Begin logging changes
+        //
+        cs.beginLogging();
+
+        DataObject child = quote.createDataObject("quotes");
+        cs.isCreated(child);
+        child = quote.createDataObject("quotes");
+        assertTrue(cs.isCreated(child));
+
+        // Stop logging changes and print the resulting data graph to stdout
+        //
+        cs.endLogging();
+
+        cs.isCreated(child);
+
+        cs.undoChanges();
+
+        assertFalse(cs.isCreated(child));
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // Populate the meta data for the test (Stock Quote) model
+        URL url = getClass().getResource(TEST_MODEL);
+        InputStream inputStream = url.openStream();
+        XSDHelper.INSTANCE.define(inputStream, url.toString());
+        inputStream.close();
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message