summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-03-09 03:55:10 (EST)
committerCaspar De Groot2011-03-09 03:55:10 (EST)
commite47ff3bddaa86ba8b00663af27f4bfd332ca2f12 (patch)
tree0110942e09abff944c03fdf631c6112a2bd55bb5
parent83fa8fa1985aa69b77654ed6c5098e52f51fea4d (diff)
downloadcdo-e47ff3bddaa86ba8b00663af27f4bfd332ca2f12.zip
cdo-e47ff3bddaa86ba8b00663af27f4bfd332ca2f12.tar.gz
cdo-e47ff3bddaa86ba8b00663af27f4bfd332ca2f12.tar.bz2
[Bug 338779] After refresh/PU, object's state is represented by 2 identical revisions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=338779
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_338779_Test.java125
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java27
3 files changed, 133 insertions, 20 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 bfb35dd..fb19d13 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
@@ -210,5 +210,6 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_336382_Test.class);
testClasses.add(Bugzilla_336590_Test.class);
testClasses.add(Bugzilla_338884_Test.class);
+ testClasses.add(Bugzilla_338779_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_338779_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_338779_Test.java
new file mode 100644
index 0000000..926b678
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_338779_Test.java
@@ -0,0 +1,125 @@
+/**
+ * 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.CDOObject;
+import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+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.model1.PurchaseOrder;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.Date;
+
+/**
+ * @author Caspar De Groot
+ */
+public class Bugzilla_338779_Test extends AbstractCDOTest
+{
+ private void test(PassiveUpdateMode passiveUpdateMode) throws CommitException
+ {
+ final CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+ if (passiveUpdateMode != null)
+ {
+ session.options().setPassiveUpdateEnabled(true);
+ session.options().setPassiveUpdateMode(passiveUpdateMode);
+ }
+ else
+ {
+ session.options().setPassiveUpdateEnabled(false);
+ }
+ CDOResource r1 = tx.createResource(getResourcePath("/r1")); //$NON-NLS-1$
+
+ PurchaseOrder po1 = getModel1Factory().createPurchaseOrder();
+ po1.setDate(new Date());
+ r1.getContents().add(po1);
+
+ tx.commit();
+
+ check(po1, session);
+
+ long timestamp = doSecondSession();
+ if (passiveUpdateMode != null)
+ {
+ session.waitForUpdate(timestamp);
+
+ if (passiveUpdateMode == PassiveUpdateMode.INVALIDATIONS)
+ {
+ // Read something on the object to force load
+ po1.getDate();
+ }
+ }
+ else
+ {
+ session.refresh();
+ }
+
+ check(po1, session);
+
+ tx.close();
+ session.close();
+ }
+
+ public void test_refresh() throws CommitException
+ {
+ test(null);
+ }
+
+ public void test_passiveUpdate_invalidations() throws CommitException
+ {
+ test(PassiveUpdateMode.INVALIDATIONS);
+ }
+
+ public void test_passiveUpdate_changes() throws CommitException
+ {
+ test(PassiveUpdateMode.CHANGES);
+ }
+
+ public void test_passiveUpdate_additions() throws CommitException
+ {
+ test(PassiveUpdateMode.ADDITIONS);
+ }
+
+ private void check(EObject eObject, CDOSession session)
+ {
+ CDOObject obj = CDOUtil.getCDOObject(eObject);
+ assertClean(obj, obj.cdoView());
+ CDORevision rev1 = obj.cdoRevision();
+ CDORevision rev2 = session.getRevisionManager().getRevisionByVersion(rev1.getID(), rev1, 0, false);
+ assertEquals(rev1, rev2);
+ assertSame(rev1, rev2);
+ }
+
+ private long doSecondSession() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+ CDOResource r1 = tx.getResource(getResourcePath("/r1")); //$NON-NLS-1$
+
+ // Change the purchaseOrder
+ PurchaseOrder po1 = (PurchaseOrder)r1.getContents().get(0);
+ po1.setDate(new Date());
+
+ CDOCommitInfo commitInfo = tx.commit();
+ tx.close();
+ session.close();
+
+ return commitInfo.getTimeStamp();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
index e3392b6..7bac734 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
@@ -15,10 +15,10 @@ import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDTemp;
import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.common.revision.CDORevisable;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
+import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
@@ -830,30 +830,17 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
public void execute(InternalCDOObject object, CDOState state, CDOEvent event, Pair<CDORevisionKey, Long> keyAndTime)
{
CDORevisionKey key = keyAndTime.getElement1();
- long lastUpdateTime = keyAndTime.getElement2();
InternalCDORevision oldRevision = object.cdoRevision();
if (key == null || key.getVersion() >= oldRevision.getVersion())
{
InternalCDOView view = object.cdoView();
- if (key instanceof CDORevisionDelta)
- {
- CDORevisionDelta delta = (CDORevisionDelta)key;
- InternalCDORevision newRevision = oldRevision.copy();
-
- CDORevisable target = delta.getTarget();
- if (target != null)
- {
- newRevision.setBranchPoint(target);
- newRevision.setVersion(target.getVersion());
- newRevision.setRevised(target.getRevised());
- }
- else
- {
- newRevision.adjustForCommit(view.getBranch(), lastUpdateTime);
- }
-
- delta.apply(newRevision);
+ CDORevisionKey newKey = key == null ? null : CDORevisionUtil.createRevisionKey(key.getID(), key.getBranch(),
+ key.getVersion() + 1);
+ InternalCDORevision newRevision = newKey == null ? null : view.getSession().getRevisionManager()
+ .getRevisionByVersion(newKey.getID(), newKey, 0, false);
+ if (newRevision != null)
+ {
object.cdoInternalSetRevision(newRevision);
changeState(object, CDOState.CLEAN);
object.cdoInternalPostLoad();