Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddiver2014-07-17 20:22:29 +0000
committerEsteban DUGUEPEROUX2014-08-12 08:28:06 +0000
commit78244dca0fe493795e4b2ae2498c16d30eacfce5 (patch)
treeb5157ccb0a5fb0b2016fc417d2cdd8f0100bdc1d
parent4a6afc879e7792bddd32b4391a267e76b3ace92f (diff)
downloadcdo-78244dca0fe493795e4b2ae2498c16d30eacfce5.tar.gz
cdo-78244dca0fe493795e4b2ae2498c16d30eacfce5.tar.xz
cdo-78244dca0fe493795e4b2ae2498c16d30eacfce5.zip
[439843] Fixed incorrect container reference id
https://bugs.eclipse.org/bugs/show_bug.cgi?id=439843 Change-Id: Ie8b8c3b239deb2663894cda0aa64e9e37d4a369e Signed-off-by: Leonid Ripeynih <akafakir@gmail.com>
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439843_Test.java71
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java18
2 files changed, 80 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439843_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439843_Test.java
new file mode 100644
index 0000000000..3f2d8c1ec0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439843_Test.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2004-2014 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:
+ * Eike Stepper - 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.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.config.impl.ModelConfig;
+import org.eclipse.emf.cdo.tests.model1.Order;
+import org.eclipse.emf.cdo.tests.model1.OrderDetail;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+/**
+ * @author Leonid Ripeynih
+ */
+@Requires(ModelConfig.CAPABILITY_LEGACY)
+public class Bugzilla_439843_Test extends AbstractCDOTest
+{
+
+ public void testLegacyOpposite_Multiple() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+
+ String path = getResourcePath("test");
+ CDOResource resource = tx.createResource(path);
+
+ Order order = getModel1Factory().createSalesOrder();
+ OrderDetail detail = getModel1Factory().createOrderDetail();
+
+ order.getOrderDetails().add(detail);
+ resource.getContents().add(order);
+
+ tx.commit();
+
+ // We need to detach an object and attach it back
+ //
+ order.getOrderDetails().remove(detail);
+ order.getOrderDetails().add(detail);
+
+ tx.commit();
+ tx.close();
+ session.close();
+
+ // To reproduce the bug we need to load object from revision.
+ // In local cache everything is fine...
+ //
+ session = openSession();
+ tx = session.openTransaction();
+
+ resource = tx.getResource(path);
+
+ order = (Order)resource.getContents().get(0);
+ detail = order.getOrderDetails().get(0);
+
+ // Basic assertions on bidirectional reference contract
+ //
+ assertSame(order, detail.eContainer());
+ assertEquals(true, order.getOrderDetails().contains(detail));
+ assertSame(order, detail.getOrder());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
index aa074f8581..f7f203c458 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
@@ -166,13 +166,13 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
if (oldValue != null)
{
InternalEObject oldChild = (InternalEObject)oldValue;
- setContainer(store, oldChild, null, 0);
+ setContainer(store, oldChild, null, InternalEObject.EOPPOSITE_FEATURE_BASE);
}
if (newValue != null)
{
InternalEObject newChild = (InternalEObject)newValue;
- setContainer(store, newChild, this, reference.getFeatureID());
+ setContainer(store, newChild, this, newChild.eContainerFeatureID());
}
}
}
@@ -192,7 +192,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
{
if (child != null)
{
- setContainer(store, (InternalEObject)child, null, 0);
+ setContainer(store, (InternalEObject)child, null, InternalEObject.EOPPOSITE_FEATURE_BASE);
}
}
}
@@ -217,7 +217,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
if (reference.isContainment())
{
InternalEObject newChild = (InternalEObject)newValue;
- setContainer(store, newChild, this, reference.getFeatureID());
+ setContainer(store, newChild, this, newChild.eContainerFeatureID());
}
}
}
@@ -237,7 +237,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
if (reference.isContainment())
{
InternalEObject newChild = (InternalEObject)object;
- setContainer(store, newChild, this, reference.getFeatureID());
+ setContainer(store, newChild, this, newChild.eContainerFeatureID());
}
}
}
@@ -256,7 +256,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
if (reference.isContainment())
{
InternalEObject oldChildEObject = (InternalEObject)oldChild;
- setContainer(store, oldChildEObject, null, 0);
+ setContainer(store, oldChildEObject, null, InternalEObject.EOPPOSITE_FEATURE_BASE);
}
}
}
@@ -281,7 +281,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
Object oldChild = oldChildren[i];
if (oldChild instanceof InternalEObject)
{
- setContainer(store, (InternalEObject)oldChild, null, 0);
+ setContainer(store, (InternalEObject)oldChild, null, InternalEObject.EOPPOSITE_FEATURE_BASE);
}
}
}
@@ -301,7 +301,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
if (reference.isContainment())
{
InternalEObject oldChildEObject = (InternalEObject)oldChild;
- setContainer(store, oldChildEObject, null, 0);
+ setContainer(store, oldChildEObject, null, InternalEObject.EOPPOSITE_FEATURE_BASE);
}
}
}
@@ -323,7 +323,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
return;
}
- store.setContainer(object, null, container, InternalEObject.EOPPOSITE_FEATURE_BASE - containingFeatureID);
+ store.setContainer(object, null, container, containingFeatureID);
}
/**

Back to the top