Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-15 13:39:10 -0500
committerEike Stepper2011-12-15 13:39:10 -0500
commit51d24d76353302014f8fe1ea32a14d0836f73952 (patch)
treee50a1b169d5fef29894d651bb64fee8a4b25e6d9
parent7193f5a630497293ee54fecbb36eb48a563783c4 (diff)
downloadcdo-51d24d76353302014f8fe1ea32a14d0836f73952.tar.gz
cdo-51d24d76353302014f8fe1ea32a14d0836f73952.tar.xz
cdo-51d24d76353302014f8fe1ea32a14d0836f73952.zip
[366286] Invalidate transition creates illegal object for audit view
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366286
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java78
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java35
4 files changed, 113 insertions, 6 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index 136ad4787d..f6daaf57be 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -192,7 +192,8 @@ public abstract class AbstractCDOTest extends ConfigTest
}
}
- protected static void commitAndSync(CDOTransaction transaction, CDOUpdatable... updatables) throws CommitException
+ protected static CDOCommitInfo commitAndSync(CDOTransaction transaction, CDOUpdatable... updatables)
+ throws CommitException
{
CDOCommitInfo info = transaction.commit();
if (info != null)
@@ -205,5 +206,7 @@ public abstract class AbstractCDOTest extends ConfigTest
}
}
}
+
+ return info;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
index 6f9ccf6162..a81ff48f87 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
@@ -56,7 +56,6 @@ public class Bugzilla_361819_Test extends AbstractCDOTest
assertClean(testingObject, testingObject.cdoView());
session.refresh();
session.refresh();
- assertProxy(testingObject);
// Load proxy
((Category)testingEObject).getName();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java
new file mode 100644
index 0000000000..bf5711b447
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java
@@ -0,0 +1,78 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
+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.Category;
+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.cdo.view.CDOView;
+
+/**
+ * @author Egidijus Vaisnora
+ */
+public class Bugzilla_365204_Test extends AbstractCDOTest
+{
+ public void testAuditViewTimeSwitch() throws CommitException
+ {
+ skipUnlessAuditing();
+
+ CDOSession sessionA = openSession();
+ CDOTransaction transaction = sessionA.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("test"));
+
+ Category category = getModel1Factory().createCategory();
+ resource.getContents().add(category);
+
+ // Make version 1 of the category
+ CDOCommitInfo commit1 = transaction.commit();
+ CDOID categoryID = CDOUtil.getCDOObject(category).cdoID();
+
+ CDOSession sessionB = openSession();
+ CDOView auditView = sessionB.openView(commit1.getTimeStamp());
+ CDOObject auditCategory = auditView.getObject(categoryID);
+ assertEquals(1, CDOUtil.getCDOObject(auditCategory).cdoRevision().getVersion());
+
+ // Make version 2 of the category
+ category.setName("version 2");
+ CDOCommitInfo commit2 = commitAndSync(transaction, auditView);
+ assertEquals(true, commit1.getTimeStamp() < commit2.getTimeStamp());
+ assertEquals(2, CDOUtil.getCDOObject(category).cdoRevision().getVersion());
+
+ // Make version 3 of the category
+ category.setName("version 3");
+ CDOCommitInfo commit3 = commitAndSync(transaction, auditView);
+ assertEquals(true, commit2.getTimeStamp() < commit3.getTimeStamp());
+ assertEquals(3, CDOUtil.getCDOObject(category).cdoRevision().getVersion());
+
+ // Load PROXY
+ ((Category)CDOUtil.getEObject(auditCategory)).getName();
+
+ // Fill cache with latest versions
+ CDORevision version2 = cacheRevision(sessionB, categoryID, 2); // Keep pointer
+ CDORevision version3 = cacheRevision(sessionB, categoryID, 3); // Keep pointer
+ System.out.println(version2);
+ System.out.println(version3);
+
+ auditView.setTimeStamp(commit3.getTimeStamp());
+
+ // Load PROXY if any
+ ((Category)CDOUtil.getEObject(auditCategory)).getName();
+
+ assertEquals(3, CDOUtil.getCDOObject(auditCategory).cdoRevision().getVersion());
+ }
+
+ private CDORevision cacheRevision(CDOSession session, CDOID id, int version)
+ {
+ CDOBranchVersion branchVersion = session.getBranchManager().getMainBranch().getVersion(version);
+ CDORevisionManager revisionManager = session.getRevisionManager();
+ return revisionManager.getRevisionByVersion(id, branchVersion, CDORevision.UNCHUNKED, true);
+ }
+}
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 423f12d63e..d2015260c3 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
@@ -16,6 +16,7 @@ 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;
@@ -24,6 +25,7 @@ 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;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionCache;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOInvalidationPolicy;
@@ -849,10 +851,20 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
{
InternalCDOView view = object.cdoView();
- 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);
+ CDORevisionKey newKey = null;
+ if (key != null)
+ {
+ int newVersion = getNewVersion(key);
+ newKey = CDORevisionUtil.createRevisionKey(key.getID(), key.getBranch(), newVersion);
+ }
+
+ InternalCDORevision newRevision = null;
+ if (newKey != null)
+ {
+ InternalCDORevisionCache cache = view.getSession().getRevisionManager().getCache();
+ newRevision = (InternalCDORevision)cache.getRevisionByVersion(newKey.getID(), newKey);
+ }
+
if (newRevision != null)
{
object.cdoInternalSetRevision(newRevision);
@@ -869,6 +881,21 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
}
+
+ private int getNewVersion(CDORevisionKey key)
+ {
+ if (key instanceof CDORevisionDelta)
+ {
+ CDORevisionDelta delta = (CDORevisionDelta)key;
+ CDORevisable target = delta.getTarget();
+ if (target != null && key.getBranch() == target.getBranch())
+ {
+ return target.getVersion();
+ }
+ }
+
+ return key.getVersion() + 1;
+ }
}
/**

Back to the top