summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-04-18 05:18:16 (EDT)
committerCaspar De Groot2011-04-18 05:18:16 (EDT)
commit5f51e7aac7b0f96eb97ae670db73120ae41c7485 (patch)
treeee00fa5101935a9b00ce2890e301bfcda9206440
parentd8413145ac65027e08b9d8b1905a17731e61a8b4 (diff)
downloadcdo-5f51e7aac7b0f96eb97ae670db73120ae41c7485.zip
cdo-5f51e7aac7b0f96eb97ae670db73120ae41c7485.tar.gz
cdo-5f51e7aac7b0f96eb97ae670db73120ae41c7485.tar.bz2
[Bug 341875] Unsetting container ref not working correctly for NEW objects if resolveProxies=true
https://bugs.eclipse.org/bugs/show_bug.cgi?id=341875
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java65
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_341875_Test.java57
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java9
5 files changed, 62 insertions, 86 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
index 29e3e59..2be6bdc 100644
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
+++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java
@@ -11,10 +11,10 @@
package org.eclipse.emf.cdo.tests.hibernate;
import org.eclipse.emf.cdo.tests.AllConfigs;
-import org.eclipse.emf.cdo.tests.AuditTest;
import org.eclipse.emf.cdo.tests.AuditSameSessionTest;
-import org.eclipse.emf.cdo.tests.BranchingTest;
+import org.eclipse.emf.cdo.tests.AuditTest;
import org.eclipse.emf.cdo.tests.BranchingSameSessionTest;
+import org.eclipse.emf.cdo.tests.BranchingTest;
import org.eclipse.emf.cdo.tests.CommitInfoTest;
import org.eclipse.emf.cdo.tests.ComplexTest;
import org.eclipse.emf.cdo.tests.ContainmentTest;
@@ -280,14 +280,6 @@ public class AllTestsHibernate extends AllConfigs
public static class Hibernate_ContainmentTest extends ContainmentTest
{
- // this testcase is overridden because it uses an ereference which should be
- // annotated with @External, but which can't be mapped like that because it is
- // also used non-externally by other testcases
- @Override
- public void testObjectNotSameResourceThanItsContainerCDOANDXMI() throws Exception
- {
- }
-
// see:
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330207#c1
@Override
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 f36acab..ae6ea18 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
@@ -212,11 +212,12 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_336590_Test.class);
testClasses.add(Bugzilla_337523_Test.class);
testClasses.add(Bugzilla_337587_Test.class);
- testClasses.add(Bugzilla_338884_Test.class);
testClasses.add(Bugzilla_338779_Test.class);
- testClasses.add(Bugzilla_339461_Test.class);
+ testClasses.add(Bugzilla_338884_Test.class);
testClasses.add(Bugzilla_339313_Test.class);
+ testClasses.add(Bugzilla_339461_Test.class);
testClasses.add(Bugzilla_340961_Test.class);
+ testClasses.add(Bugzilla_341875_Test.class);
testClasses.add(Bugzilla_342130_Test.class);
testClasses.add(Bugzilla_342135_Test.class);
}
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 5bfad93..2a090f4 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
@@ -39,9 +39,6 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
/**
* @author Eike Stepper
*/
@@ -346,68 +343,6 @@ public class ContainmentTest extends AbstractCDOTest
assertNull(order.getShippingAddress());
}
- public void testObjectNotSameResourceThanItsContainerCDOANDXMI() throws Exception
- {
- skipExternalReferences();
-
- byte[] data = null;
- {
- CDOSession session = openSession();
- ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl());
-
- CDOTransaction transaction = session.openTransaction(resourceSet);
- Resource resource1 = resourceSet.createResource(URI.createURI("test://1"));
- Resource resource2 = transaction.createResource(getResourcePath("test"));
-
- EPackage packageObject = createDynamicEPackage();
- EClass eClass = (EClass)packageObject.getEClassifier("SchoolBook");
-
- EObject container = packageObject.getEFactoryInstance().create(eClass);
- Order contained = getModel1Factory().createPurchaseOrder();
-
- resource1.getContents().add(container);
- resource2.getContents().add(contained);
-
- container.eSet(container.eClass().getEStructuralFeature("proxyElement"), contained);
-
- assertEquals(resource1, container.eResource());
- assertEquals(resource2, contained.eResource());
-
- // If the relationship is define has resolveProxy this is true if not.. this is false.
- assertEquals(container, contained.eContainer());
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- resource1.save(outputStream, null);
- data = outputStream.toByteArray();
- transaction.commit();
- }
-
- clearCache(getRepository().getRevisionManager());
- EPackage packageObject = createDynamicEPackage();
-
- ResourceSet resourceSet = new ResourceSetImpl();
- CDOSession session = openSession();
- session.getPackageRegistry().putEPackage(packageObject);
- CDOTransaction transaction = session.openTransaction(resourceSet);
-
- resourceSet.getPackageRegistry().put(packageObject.getNsURI(), packageObject);
- resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("test", new XMIResourceFactoryImpl());
-
- Resource resource1 = resourceSet.createResource(URI.createURI("test://1"));
- resource1.load(new ByteArrayInputStream(data), null);
- Resource resource2 = transaction.getResource(getResourcePath("test"));
-
- EObject container = resource1.getContents().get(0);
- Order order = (Order)resource2.getContents().get(0);
-
- assertEquals(resource1.getContents().get(0), order.eContainer());
- resource2.getContents().remove(order);
-
- Order order2 = (Order)CDOUtil.getEObject((EObject)container.eGet(container.eClass().getEStructuralFeature(
- "proxyElement")));
- assertSame(order, order2);
- }
-
public void testObjectNotSameResourceThanItsContainerCDO() throws Exception
{
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_341875_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_341875_Test.java
new file mode 100644
index 0000000..26ac1b1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_341875_Test.java
@@ -0,0 +1,57 @@
+/**
+ * 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.CDOState;
+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.model4.RefSingleContained;
+import org.eclipse.emf.cdo.tests.model4.SingleContainedElement;
+import org.eclipse.emf.cdo.tests.model4.model4Factory;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ * @author Caspar De Groot
+ */
+public class Bugzilla_341875_Test extends AbstractCDOTest
+{
+ private final model4Factory factory = getModel4Factory();
+
+ public void test()
+ {
+ SingleContainedElement element = factory.createSingleContainedElement();
+
+ RefSingleContained parent = factory.createRefSingleContained();
+ parent.setElement(element);
+
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+ CDOResource resource = tx.createResource(getResourcePath("test"));
+ resource.getContents().add(parent);
+
+ assertEquals(CDOState.NEW, CDOUtil.getCDOObject(parent).cdoState());
+ assertEquals(CDOState.NEW, CDOUtil.getCDOObject(element).cdoState());
+
+ EReference ref_elToPar = getModel4Package().getSingleContainedElement_Parent();
+ EReference ref_parToEl = getModel4Package().getRefSingleContained_Element();
+ ref_parToEl.setResolveProxies(true);
+
+ element.eUnset(ref_elToPar);
+ assertNull(parent.eGet(ref_parToEl));
+
+ tx.close();
+ session.close();
+ }
+}
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 597dc59..9e4bdd0 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
@@ -361,15 +361,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
eContainer = store.getContainer(this);
eContainerFeatureID = store.getContainingFeatureID(this);
- if (eContainer != null)
- {
- EReference containmentFeature = eContainmentFeature();
- if (containmentFeature.isResolveProxies())
- {
- adjustOppositeReference(this, eContainer, containmentFeature);
- }
- }
-
// Ensure that the internal eSettings array is initialized;
resetSettings();