summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Velten2014-01-30 11:21:54 (EST)
committerEike Stepper2014-02-04 08:10:24 (EST)
commitea71555dce6453f07583ffffce96381757f776fe (patch)
tree2576496c790ce6a9be5b5199d3acb863ab4bbef3
parent527c1ccea8ae9d9b2b233c3773d332f4ff3c3188 (diff)
downloadcdo-ea71555dce6453f07583ffffce96381757f776fe.zip
cdo-ea71555dce6453f07583ffffce96381757f776fe.tar.gz
cdo-ea71555dce6453f07583ffffce96381757f776fe.tar.bz2
[427358] Wrong behavior when moving an object of containment inside of the same resource (no CDOView attached)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=427358 Signed-off-by: Mathieu Velten <mathieu.velten@atos.net>
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java37
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java4
2 files changed, 39 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
index 2a44cc8..af54cf8 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.model1.Address;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.Supplier;
import org.eclipse.emf.cdo.tests.model2.PersistentContainment;
@@ -40,6 +41,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
/**
* @author Eike Stepper
@@ -601,4 +603,39 @@ public class ContainmentTest extends AbstractCDOTest
transaction.commit();
}
+
+ public void testContainmentChangeInSameResource()
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("model1", new Resource.Factory()
+ {
+ public Resource createResource(URI uri)
+ {
+ return new XMIResourceImpl(uri)
+ {
+ @Override
+ protected boolean useUUIDs()
+ {
+ return true;
+ }
+ };
+ }
+ });
+
+ Category category1 = Model1Factory.eINSTANCE.createCategory();
+ Category category2 = Model1Factory.eINSTANCE.createCategory();
+
+ Company company = Model1Factory.eINSTANCE.createCompany();
+ company.getCategories().add(category1);
+ company.getCategories().add(category2);
+
+ Resource resource = resourceSet.createResource(URI.createURI("test.model1", true));
+ resource.getContents().add(company);
+
+ String originalID = resource.getURIFragment(category2);
+
+ // Change object of containment feature
+ category1.getCategories().add(category2);
+ assertEquals("The id of the object changed while it should not", originalID, resource.getURIFragment(category2));
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index 9e1d137..34aa637 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -794,7 +794,7 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC
: null;
boolean moved = oldView != null && oldView == newView;
- if (!moved && oldResource != null && !isResourceRoot)
+ if (!moved && oldResource != null && oldResource != newResource && !isResourceRoot)
{
oldResource.detached(this);
}
@@ -802,7 +802,7 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC
int oldContainerFeatureID = eContainerFeatureID();
eBasicSetContainer(newContainer, newContainerFeatureID);
- if (!moved && oldResource != newResource && newResource != null)
+ if (!moved && newResource != null && newResource != oldResource)
{
newResource.attached(this);
}