summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-05-18 07:16:46 (EDT)
committerCaspar De Groot2011-05-18 07:16:46 (EDT)
commit9d325ccea8a27355eeac519ca4e9258c2b3212f3 (patch)
treee2a63c0a0a0620a43d7fd8582010a7710aa0d57d
parentb76d3bb8a670f97703b15b2e5c470832dd1fdaa1 (diff)
downloadcdo-9d325ccea8a27355eeac519ca4e9258c2b3212f3.zip
cdo-9d325ccea8a27355eeac519ca4e9258c2b3212f3.tar.gz
cdo-9d325ccea8a27355eeac519ca4e9258c2b3212f3.tar.bz2
[Bug 343471] CommitIntegrityCheck fails for object moved to different resource
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343471
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343471_Test.java88
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java45
4 files changed, 134 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 157961c..707776c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -226,5 +226,6 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_342130_Test.class);
testClasses.add(Bugzilla_342135_Test.class);
testClasses.add(Bugzilla_343332_Test.class);
+ testClasses.add(Bugzilla_343471_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343471_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343471_Test.java
new file mode 100644
index 0000000..37fc998
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343471_Test.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Caspar De Groot
+ */
+public class Bugzilla_343471_Test extends AbstractCDOTest
+{
+ public void test() throws CommitException
+ {
+ skipLegacy();
+
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+
+ CDOResource resource1 = tx.createResource(getResourcePath("test1"));
+ CDOResource resource2 = tx.createResource(getResourcePath("test2"));
+
+ Category c1 = getModel1Factory().createCategory();
+ resource1.getContents().add(c1);
+
+ Category c2 = getModel1Factory().createCategory();
+ c1.getCategories().add(c2);
+
+ // c3 serves only to make the later commit partial
+ Category c3 = getModel1Factory().createCategory();
+ resource2.getContents().add(c3);
+
+ tx.commit();
+
+ msg("c1 = " + c1);
+ msg("c2 = " + c2);
+ msg("c3 = " + c3);
+
+ msg("resource1 = " + resource1);
+ msg("resource2 = " + resource2);
+
+ msg("");
+ msg("c1's container? " + c1.eContainer());
+ msg("c2 contained in c1? " + c1.getCategories().contains(c2));
+ msg("c2 contained in c1? " + (c2.eContainer() == c1));
+ msg("c2's resource is r2? " + (c2.eResource() == resource2));
+
+ // Move c2 from resource1 to resource2
+ resource2.getContents().add(c2);
+
+ // assertSame(c1, c2.eContainer());
+
+ msg("");
+ msg("c1's container? " + c1.eContainer());
+ msg("c2 contained in c1? " + c1.getCategories().contains(c2));
+ msg("c2 contained in c1? " + (c2.eContainer() == c1));
+ msg("c2's resource is r2? " + (c2.eResource() == resource2));
+
+ // Make c3 dirty so that we can create a partial commit
+ c3.setName("X");
+
+ Set<EObject> committables = new HashSet<EObject>();
+ committables.add(c2);
+ committables.add(resource2);
+
+ tx.setCommittables(committables);
+ tx.commit();
+
+ session.close();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTest.java
index c613080..c1d690f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/ConfigTest.java
@@ -612,6 +612,11 @@ public abstract class ConfigTest extends AbstractOMTest implements IConstants
skipConfig("Hibernate");
}
+ protected void skipLegacy()
+ {
+ skipTest(getModelConfig() instanceof ModelConfig.Legacy);
+ }
+
protected void skipExternalReferences()
{
skipTest(getRepository().getStore() instanceof NoExternalReferences);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
index 0480949..296a402 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
@@ -156,11 +156,46 @@ public class CommitIntegrityCheck
EStructuralFeature feat = featureDelta.getFeature();
if (feat == CDOContainerFeatureDelta.CONTAINER_FEATURE)
{
- // Object is dirty with respect to its container; this means it was moved;
- // We must ensure that both the old and new containers are included
- checkContainerIncluded(dirtyObject, "moved");
- CDOID containerOrResourceID = getContainerOrResourceID(cleanRev);
- checkIncluded(containerOrResourceID, "former container (or resource) of moved", dirtyObject);
+ // Three possibilities here:
+ // 1. Object's container has changed
+ // 2. Object's containment feature has changed
+ // 3. Object's resource has changed
+ // (or several of the above)
+
+ // @1
+ CDOID currentContainerID = (CDOID)transaction.convertObjectToID(dirtyRev.getContainerID());
+ CDOID cleanContainerID = (CDOID)transaction.convertObjectToID(cleanRev.getContainerID());
+ if (currentContainerID != cleanContainerID)
+ {
+ if (currentContainerID != CDOID.NULL)
+ {
+ checkIncluded(currentContainerID, "container of moved", dirtyObject);
+ }
+
+ if (cleanContainerID != CDOID.NULL)
+ {
+ checkIncluded(cleanContainerID, "former container of moved", dirtyObject);
+ }
+ }
+
+ // @2
+ // Nothing to be done. (I think...)
+
+ // @3
+ CDOID currentResourceID = (CDOID)transaction.convertObjectToID(dirtyRev.getResourceID());
+ CDOID cleanResourceID = (CDOID)transaction.convertObjectToID(cleanRev.getResourceID());
+ if (currentResourceID != cleanResourceID)
+ {
+ if (currentResourceID != CDOID.NULL)
+ {
+ checkIncluded(currentResourceID, "resource of moved", dirtyObject);
+ }
+
+ if (cleanResourceID != CDOID.NULL)
+ {
+ checkIncluded(cleanResourceID, "former resource of moved", dirtyObject);
+ }
+ }
}
else if (feat instanceof EReference)
{