Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-09-23 08:12:10 +0000
committerEike Stepper2010-09-23 08:12:10 +0000
commit8fa895a78e686c230704b34ffb50e082cd9d7714 (patch)
tree9ba83ce354be6f9b9a12137ac93016cc631de57d
parentfcfa0b562cf806e6553570765f8d0ffed8df123a (diff)
downloadcdo-8fa895a78e686c230704b34ffb50e082cd9d7714.tar.gz
cdo-8fa895a78e686c230704b34ffb50e082cd9d7714.tar.xz
cdo-8fa895a78e686c230704b34ffb50e082cd9d7714.zip
[325866] IllegalStateException when committing a reattached containment of a detached container after branch merge with XRef enabled
https://bugs.eclipse.org/bugs/show_bug.cgi?id=325866
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325866_Test.java96
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java34
3 files changed, 118 insertions, 14 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 7a908f5e8c..9cdf81e4e8 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
@@ -98,6 +98,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324585_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324635_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324756_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325603_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325866_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -261,6 +262,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_324635_Test.class);
testClasses.add(Bugzilla_324756_Test.class);
testClasses.add(Bugzilla_325603_Test.class);
+ testClasses.add(Bugzilla_325866_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325866_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325866_Test.java
new file mode 100644
index 0000000000..6af5b537b9
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325866_Test.java
@@ -0,0 +1,96 @@
+/**
+ * Copyright (c) 2004 - 2010 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:
+ * Pascal Lehmann - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model4.GenRefMultiContained;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
+
+import org.eclipse.emf.spi.cdo.DefaultCDOMerger;
+
+import java.util.Map;
+
+/**
+ * IllegalStateException when committing a reattached containment of a detached container after branch merge with XRef
+ * enabled.
+ * <p>
+ * See bug 325866
+ *
+ * @author Pascal Lehmann
+ */
+public class Bugzilla_325866_Test extends AbstractCDOTest
+{
+ @Override
+ public synchronized Map<String, Object> getTestProperties()
+ {
+ Map<String, Object> map = super.getTestProperties();
+ map.put(IRepository.Props.ENSURE_REFERENTIAL_INTEGRITY, "true");
+ return map;
+ }
+
+ public void testXRefReattachBranch() throws Exception
+ {
+ skipUnlessBranching();
+
+ // setup transaction.
+ final CDOSession session1 = openSession();
+ final CDOTransaction s1Tr1 = session1.openTransaction();
+ s1Tr1.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
+
+ // create resource, and container tree using transaction 1.
+ final CDOResource resource = s1Tr1.createResource("/test1");
+ GenRefMultiContained container1 = getModel4Factory().createGenRefMultiContained();
+ GenRefMultiContained container2 = getModel4Factory().createGenRefMultiContained();
+ GenRefMultiContained container3 = getModel4Factory().createGenRefMultiContained();
+ resource.getContents().add(container1);
+ container1.getElements().add(container2);
+ container2.getElements().add(container3);
+
+ s1Tr1.commit();
+
+ // setup another branch.
+ final CDOBranch otherBranch = s1Tr1.getBranch().createBranch("other");
+ final CDOTransaction s1Tr3 = session1.openTransaction(otherBranch);
+
+ CDOResource branchResource = s1Tr3.getObject(resource);
+ assertNotSame(null, branchResource);
+
+ GenRefMultiContained otherContainer1 = (GenRefMultiContained)branchResource.getContents().get(0);
+ assertNotSame(null, otherContainer1);
+
+ GenRefMultiContained otherContainer2 = (GenRefMultiContained)otherContainer1.getElements().get(0);
+ assertNotSame(null, otherContainer2);
+
+ GenRefMultiContained otherContainer3 = (GenRefMultiContained)otherContainer2.getElements().get(0);
+ assertNotSame(null, otherContainer3);
+
+ // detach the middle container on branch.
+ otherContainer1.getElements().remove(otherContainer2);
+
+ // re-attach detached's child container.
+ otherContainer1.getElements().add(otherContainer3);
+
+ s1Tr3.commit();
+ assertEquals(false, s1Tr3.isDirty());
+
+ // merge the other branch to main.
+ s1Tr1.merge(s1Tr3.getBranch().getHead(), new DefaultCDOMerger.PerFeature.ManyValued());
+
+ s1Tr1.commit();
+ assertEquals(false, s1Tr1.isDirty());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index bb9d1ef556..d1d8331980 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -461,6 +461,20 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
+ Set<CDOObject> detachedObjects = new HashSet<CDOObject>();
+ for (CDOIDAndVersion key : changeSetData.getDetachedObjects())
+ {
+ CDOID id = key.getID();
+ InternalCDOObject object = getObjectIfExists(id);
+ if (object != null)
+ {
+ result.getDetachedObjects().add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION));
+ CDOStateMachine.INSTANCE.detach(object);
+ detachedObjects.add(object);
+ dirty = true;
+ }
+ }
+
Map<CDOID, CDOObject> dirtyObjects = lastSavepoint.getDirtyObjects();
ConcurrentMap<CDOID, CDORevisionDelta> revisionDeltas = lastSavepoint.getRevisionDeltas();
Map<CDOID, InternalCDORevision> oldRevisions = new HashMap<CDOID, InternalCDORevision>();
@@ -496,6 +510,12 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
revisionDeltas.put(id, targetGoalDelta);
result.getChangedObjects().add(targetGoalDelta);
+ // handle reattached objects.
+ if (lastSavepoint.getDetachedObjects().containsKey(id))
+ {
+ CDOStateMachine.INSTANCE.attach(object, this);
+ }
+
object.cdoInternalSetState(CDOState.DIRTY);
object.cdoInternalSetRevision(goalRevision);
revisionChanged = true;
@@ -510,20 +530,6 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
- Set<CDOObject> detachedObjects = new HashSet<CDOObject>();
- for (CDOIDAndVersion key : changeSetData.getDetachedObjects())
- {
- CDOID id = key.getID();
- InternalCDOObject object = getObjectIfExists(id);
- if (object != null)
- {
- result.getDetachedObjects().add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION));
- CDOStateMachine.INSTANCE.detach(object);
- detachedObjects.add(object);
- dirty = true;
- }
- }
-
List<CDORevisionDelta> deltas = new ArrayList<CDORevisionDelta>(revisionDeltas.values());
if (!deltas.isEmpty() || !detachedObjects.isEmpty())
{

Back to the top