Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2017-05-17 11:47:47 -0400
committerEike Stepper2017-05-17 11:47:47 -0400
commitc310ac782023d7ff7fe22661fe260b7f505ee810 (patch)
tree75378eaec000f2124d01015b4ebbb4b766062b4a
parent2def4a8c9bafcfaa9500a0e06fdaf0e07eca154a (diff)
downloadcdo-c310ac782023d7ff7fe22661fe260b7f505ee810.tar.gz
cdo-c310ac782023d7ff7fe22661fe260b7f505ee810.tar.xz
cdo-c310ac782023d7ff7fe22661fe260b7f505ee810.zip
[516824] Multiple revision instances are loaded during branch switch
https://bugs.eclipse.org/bugs/show_bug.cgi?id=516824
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java39
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_516824_Test.java91
2 files changed, 121 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index 425e265b72..f22baaedec 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -75,6 +75,7 @@ import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
+import org.eclipse.emf.cdo.spi.common.revision.BaseCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -587,10 +588,7 @@ public class Repository extends Container<Object> implements InternalRepository,
InternalCDORevision target = loadRevisionTarget(id, branchPoint, referenceChunk, accessor);
if (target != null)
{
- if (referenceChunk == UNCHUNKED)
- {
- target.setUnchunked();
- }
+ target = normalizeRevision(target, info, referenceChunk);
CDOBranch branch = branchPoint.getBranch();
long revised = loadRevisionRevised(id, branch);
@@ -614,12 +612,9 @@ public class Repository extends Container<Object> implements InternalRepository,
}
else
{
- if (referenceChunk == UNCHUNKED)
- {
- revision.setUnchunked();
- }
-
revision.freeze();
+
+ revision = normalizeRevision(revision, info, referenceChunk);
info.setResult(revision);
}
}
@@ -627,6 +622,32 @@ public class Repository extends Container<Object> implements InternalRepository,
return null;
}
+ private InternalCDORevision normalizeRevision(InternalCDORevision revision, RevisionInfo info, int referenceChunk)
+ {
+ if (info instanceof RevisionInfo.Available)
+ {
+ RevisionInfo.Available availableInfo = (RevisionInfo.Available)info;
+
+ CDOBranchVersion availableBranchVersion = availableInfo.getAvailableBranchVersion();
+ if (availableBranchVersion instanceof BaseCDORevision)
+ {
+ BaseCDORevision availableRevision = (BaseCDORevision)availableBranchVersion;
+ if (availableRevision.equals(revision))
+ {
+ ensureChunks(availableRevision, referenceChunk);
+ return availableRevision;
+ }
+ }
+ }
+
+ if (referenceChunk == UNCHUNKED)
+ {
+ revision.setUnchunked();
+ }
+
+ return revision;
+ }
+
private InternalCDORevision loadRevisionTarget(CDOID id, CDOBranchPoint branchPoint, int referenceChunk, IStoreAccessor accessor)
{
CDOBranch branch = branchPoint.getBranch();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_516824_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_516824_Test.java
new file mode 100644
index 0000000000..a96b9db166
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_516824_Test.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2017 Obeo.
+ * 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:
+ * Maxime Porhel (Obeo) - initial API and implementation
+ */
+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.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesBefore;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+
+/**
+ * Bug 516824: Multiple revision instances are loaded during branch switch.
+ *
+ * @author Maxime Porhel (Obeo)
+ */
+@CleanRepositoriesBefore(reason = "because")
+@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+public class Bugzilla_516824_Test extends AbstractCDOTest
+{
+ /**
+ * Ensure that there is no ClassCastException thrown during the branch switching.
+ */
+ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+ public void testSetBranch() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ Supplier supplier = getModel1Factory().createSupplier();
+ supplier.setName("s0");
+ // supplier.setPreferred(false); default value
+
+ Company company = getModel1Factory().createCompany();
+ company.setName("c0");
+ company.getSuppliers().add(supplier);
+
+ CDOResource resource = transaction.createResource("newResource.company");
+ resource.getContents().add(company);
+
+ transaction.commit();
+
+ // Make sure invalidation will trigger delta notifications
+ resource.eAdapters().add(new EContentAdapter());
+
+ CDOBranch subBranch = transaction.getBranch().createBranch("subBranch");
+ transaction.setBranch(subBranch);
+ }
+
+ @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
+ public void testSetBranchLegacy() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource = transaction.createResource("newResource.ecore");
+ EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
+ EClass eClass = EcoreFactory.eINSTANCE.createEClass();
+
+ ePackage.setName("p0");
+ eClass.setName("c0");
+
+ resource.getContents().add(ePackage);
+ ePackage.getEClassifiers().add(eClass);
+
+ transaction.commit();
+
+ // Make sure invalidation will trigger delta notifications
+ resource.eAdapters().add(new EContentAdapter());
+
+ CDOBranch subBranch = transaction.getBranch().createBranch("subBranch");
+ transaction.setBranch(subBranch);
+ }
+}

Back to the top