Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-06 02:27:12 -0400
committerEike Stepper2013-09-06 02:27:12 -0400
commitfec6dc9ed61d94ffd0fc7a43ab605f63d04c2868 (patch)
tree2ff42b3aac69d834e39e824727fcf57d6eab59fd
parentad78f4d3e69bacd8f346d45a2d32239cc72d5e19 (diff)
downloadcdo-fec6dc9ed61d94ffd0fc7a43ab605f63d04c2868.tar.gz
cdo-fec6dc9ed61d94ffd0fc7a43ab605f63d04c2868.tar.xz
cdo-fec6dc9ed61d94ffd0fc7a43ab605f63d04c2868.zip
Revert "[416289] Stale reference not removed between locally detached object and remotely changed ones https://bugs.eclipse.org/bugs/show_bug.cgi?id=416289"
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415415_Test.java206
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java53
2 files changed, 17 insertions, 242 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415415_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415415_Test.java
deleted file mode 100644
index 839e9b9c31..0000000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415415_Test.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2013 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:
- * Esteban Dugueperoux - initial API and implementation
- */
-package org.eclipse.emf.cdo.tests.bugzilla;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-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.model3.NodeA;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-/**
- * Bug 415415: Stale reference not removed between locally detached object and remotely changed ones
- *
- * @author Esteban Dugueperoux
- */
-public class Bugzilla_415415_Test extends AbstractCDOTest
-{
- private static final String RESOURCE_NAME = "res1";
-
- private CDOTransaction transaction;
-
- private NodeA root;
-
- private NodeA child1;
-
- private NodeA child2;
-
- private CDOObject rootCDO;
-
- private CDOObject child1CDO;
-
- private CDOObject child2CDO;
-
- private CDOID rootID;
-
- private CDOID child1ID;
-
- private CDOID child2ID;
-
- private RemoteUser remoteUser;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- root = getModel3Factory().createNodeA();
- root.setName("root");
-
- child1 = getModel3Factory().createNodeA();
- child1.setName("child1");
- root.getChildren().add(child1);
-
- child2 = getModel3Factory().createNodeA();
- child2.setName("child2");
- root.getChildren().add(child2);
-
- CDOSession session = openSession();
- session.options().setPassiveUpdateEnabled(true);
- session.options().setPassiveUpdateMode(PassiveUpdateMode.ADDITIONS);
-
- transaction = session.openTransaction();
- CDOResource resource = transaction.createResource(getResourcePath(RESOURCE_NAME));
- resource.getContents().add(root);
- transaction.commit();
-
- rootCDO = CDOUtil.getCDOObject(root);
- rootID = rootCDO.cdoID();
-
- child1CDO = CDOUtil.getCDOObject(child1);
- child1ID = child1CDO.cdoID();
-
- child2CDO = CDOUtil.getCDOObject(child2);
- child2ID = child2CDO.cdoID();
-
- remoteUser = new RemoteUser();
- }
-
- @Override
- public void tearDown() throws Exception
- {
- root = null;
- child1 = null;
- child2 = null;
-
- rootCDO = null;
- child1CDO = null;
- child2CDO = null;
-
- rootID = null;
- child1ID = null;
- child2ID = null;
-
- remoteUser = null;
- super.tearDown();
- }
-
- public void testStaleReferenceRemove_FromLocallyDirtyObjectToRemotelyDetachedObject() throws Exception
- {
- child2.getOtherNodes().add(child1);
- remoteUser.removeNodeA1ChildToNodeAroot();
- CDOCommitInfo commit = remoteUser.commit();
- transaction.waitForUpdate(commit.getTimeStamp(), DEFAULT_TIMEOUT);
-
- assertEquals("As child1 is remotelly detached, the stale reference child2.otherNodes:child1 should be removed", 0,
- child2.getOtherNodes().size());
-
- String assertMessage = "As the stale reference child2.otherNodes:child1 has been removed and child2 is already dirty child2 should be the only dirty object";
- assertEquals(assertMessage, 1, transaction.getDirtyObjects().size());
- assertEquals(assertMessage, child2CDO, transaction.getDirtyObjects().get(child2ID));
-
- transaction.commit();
- remoteUser.assertNotStaleReference();
- }
-
- public void testStaleReferenceRemove_FromRemotelyDirtyObjectToLocallyDetachedObject() throws Exception
- {
- root.getChildren().remove(child1);
- remoteUser.createReferenceFromNodeA2ToNodeA1();
- CDOCommitInfo commit = remoteUser.commit();
- transaction.waitForUpdate(commit.getTimeStamp(), DEFAULT_TIMEOUT);
-
- assertEquals(1, transaction.getDetachedObjects().size());
- assertEquals(child1CDO, transaction.getDetachedObjects().get(child1ID));
- assertEquals("As child1 is locally detached, the stale reference child2.otherNodes:child1 should be removed", 0,
- child2.getOtherNodes().size());
-
- String assertMessage = "As the stale reference child2.otherNodes:child1 has been removed, child2 should become the only dirty object with the nodeARoot";
- assertEquals(assertMessage, 2, transaction.getDirtyObjects().size());
- assertEquals(assertMessage, child2CDO, transaction.getDirtyObjects().get(child2ID));
- assertEquals(assertMessage, rootCDO, transaction.getDirtyObjects().get(rootID));
-
- commit = transaction.commit();
- remoteUser.waitForUpdate(commit.getTimeStamp(), DEFAULT_TIMEOUT);
- remoteUser.assertNotStaleReference();
- }
-
- /**
- * @author Esteban Dugueperoux
- */
- private final class RemoteUser
- {
- private CDOTransaction transaction;
-
- private NodeA root;
-
- private NodeA child1;
-
- private NodeA child2;
-
- public RemoteUser()
- {
- CDOSession session = openSession();
- session.options().setPassiveUpdateEnabled(true);
- session.options().setPassiveUpdateMode(PassiveUpdateMode.ADDITIONS);
-
- transaction = session.openTransaction();
-
- CDOResource resource = transaction.getResource(getResourcePath(RESOURCE_NAME));
-
- root = (NodeA)resource.getContents().get(0);
- child1 = root.getChildren().get(0);
- child2 = root.getChildren().get(1);
- }
-
- public void removeNodeA1ChildToNodeAroot()
- {
- root.getChildren().remove(child1);
- }
-
- public void createReferenceFromNodeA2ToNodeA1()
- {
- child2.getOtherNodes().add(child1);
- }
-
- public CDOCommitInfo commit() throws Exception
- {
- return transaction.commit();
- }
-
- public void waitForUpdate(long timeStamp, long defaultTimeout)
- {
- transaction.waitForUpdate(timeStamp, defaultTimeout);
- }
-
- public void assertNotStaleReference()
- {
- assertEquals(0, transaction.getDetachedObjects().size());
- assertEquals(0, transaction.getDirtyObjects().size());
- assertEquals(0, child2.getOtherNodes().size());
- }
- }
-}
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 53068c527e..1658e28e5b 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
@@ -2395,10 +2395,17 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
{
if (!allDetachedObjects.isEmpty())
{
- // Remove stale references from locally changed or new objects to remotely detached objects
- Set<CDOObject> remotelyDetachedObjects = getObjects(allDetachedObjects);
- removeCrossReferences(remotelyDetachedObjects, getDirtyObjects().values());
- removeCrossReferences(remotelyDetachedObjects, getNewObjects().values());
+ Set<CDOID> referencedOIDs = new HashSet<CDOID>();
+ for (CDOIDAndVersion key : allDetachedObjects)
+ {
+ referencedOIDs.add(key.getID());
+ }
+
+ Collection<CDOObject> cachedDirtyObjects = getDirtyObjects().values();
+ removeCrossReferences(cachedDirtyObjects, referencedOIDs);
+
+ Collection<CDOObject> cachedNewObjects = getNewObjects().values();
+ removeCrossReferences(cachedNewObjects, referencedOIDs);
}
// Bug 290032 - Sticky views
@@ -2408,36 +2415,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
session.clearCommittedSinceLastRefresh();
}
- Map<CDOObject, Pair<CDORevision, CDORevisionDelta>> conflicts = //
- super.invalidate(allChangedObjects, allDetachedObjects, deltas, revisionDeltas, detachedObjects);
-
- if (!allChangedObjects.isEmpty())
- {
- // Remove stale references from remotely changed objects to locally detached objects
- Set<CDOObject> remotelyChangedObjects = getObjects(allChangedObjects);
- removeCrossReferences(getDetachedObjects().values(), remotelyChangedObjects);
- }
-
- return conflicts;
- }
-
- private Set<CDOObject> getObjects(Collection<? extends CDOIDAndVersion> identifiables)
- {
- Set<CDOObject> result = new HashSet<CDOObject>();
- for (CDOIDAndVersion identifiable : identifiables)
- {
- CDOID id = identifiable.getID();
- InternalCDOObject object = getObject(id, false);
- if (object != null)
- {
- result.add(object);
- }
- }
-
- return result;
+ return super.invalidate(allChangedObjects, allDetachedObjects, deltas, revisionDeltas, detachedObjects);
}
- private void removeCrossReferences(Collection<CDOObject> possibleTargets, Collection<CDOObject> referencers)
+ private void removeCrossReferences(Collection<CDOObject> referencers, Set<CDOID> referencedOIDs)
{
List<Pair<Setting, EObject>> objectsToBeRemoved = new LinkedList<Pair<Setting, EObject>>();
for (CDOObject referencer : referencers)
@@ -2449,9 +2430,9 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
while (it.hasNext())
{
EObject referencedObject = it.next();
- CDOObject referencedCDOObject = CDOUtil.getCDOObject(referencedObject);
+ CDOID referencedOID = CDOUtil.getCDOObject(referencedObject).cdoID();
- if (possibleTargets.contains(referencedCDOObject))
+ if (referencedOIDs.contains(referencedOID))
{
EReference reference = (EReference)it.feature();
@@ -2471,7 +2452,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
{
for (Object value : list)
{
- if (value == referencedCDOObject.cdoID() || value == referencedObject)
+ if (value == referencedOID || value == referencedObject)
{
continue;
}
@@ -2481,7 +2462,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
else
{
Object value = cleanRevision.getValue(reference);
- if (value == referencedCDOObject.cdoID() || value == referencedObject)
+ if (value == referencedOID || value == referencedObject)
{
continue;
}

Back to the top