summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidijus Vaishnora2011-02-03 07:32:04 (EST)
committerEgidijus Vaishnora2011-02-03 07:32:04 (EST)
commit29f81052aa8236aca75fe075c4881a6c80085184 (patch)
tree84fa1c8232f6e67188b7bcc5401460fc47c1083f
parente4be8aa572fcab52b8e6e471411870d175b81503 (diff)
downloadcdo-29f81052aa8236aca75fe075c4881a6c80085184.zip
cdo-29f81052aa8236aca75fe075c4881a6c80085184.tar.gz
cdo-29f81052aa8236aca75fe075c4881a6c80085184.tar.bz2
[335004] bug fix https://bugs.eclipse.org/bugs/show_bug.cgi?id=335004
-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_335004_Test.java74
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java30
3 files changed, 104 insertions, 1 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 73ae676..fa52034 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
@@ -195,6 +195,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_333950_Test.class);
testClasses.add(Bugzilla_334608_Test.class);
testClasses.add(Bugzilla_335675_Test.class);
+ testClasses.add(Bugzilla_335004_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_335004_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_335004_Test.java
new file mode 100644
index 0000000..f1382d2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_335004_Test.java
@@ -0,0 +1,74 @@
+/**
+ * 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+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.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_335004_Test extends AbstractCDOTest
+{
+ public void testDuplicatePackageInSystem() throws CommitException
+ {
+ String nsURI = getModel1Package().getNsURI();
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("test");
+ resource.getContents().add(getModel1Factory().createAddress());
+ transaction.commit();
+ session.close();
+ }
+
+ assertNotNull(EPackage.Registry.INSTANCE.get(nsURI));
+ Object oldPackage = EPackage.Registry.INSTANCE.remove(nsURI);
+
+ try
+ {
+ assertNull(EPackage.Registry.INSTANCE.get(nsURI));
+
+ CDOSession session = openSession();
+ session.options().setGeneratedPackageEmulationEnabled(true);
+
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource("test"); // We are loading nsURI from the server
+
+ EObject remoteObject = resource.getContents().get(0);
+ EObject localObject = getModel1Factory().createAddress();
+
+ try
+ {
+ resource.getContents().add(localObject);
+ assertSame(remoteObject.eClass(), localObject.eClass());
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException expected)
+ {
+ // Success
+ }
+ }
+ finally
+ {
+ if (oldPackage != null)
+ {
+ EPackage.Registry.INSTANCE.put(nsURI, oldPackage);
+ }
+ }
+ }
+}
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 ed18189..920c26b 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
@@ -22,6 +22,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
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.InternalCDORevisionManager;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
@@ -38,6 +39,7 @@ import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EStoreEObjectImpl;
@@ -45,9 +47,11 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult;
import org.eclipse.emf.spi.cdo.FSMUtil;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
+import org.eclipse.emf.spi.cdo.InternalCDOSession;
import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
import org.eclipse.emf.spi.cdo.InternalCDOView;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -526,7 +530,10 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
// Create new revision
EClass eClass = object.eClass();
- CDORevisionFactory factory = transaction.getSession().getRevisionManager().getFactory();
+ InternalCDOSession session = transaction.getSession();
+ checkPackageRegistrationProblems(session, eClass);
+
+ CDORevisionFactory factory = session.getRevisionManager().getFactory();
InternalCDORevision revision = (InternalCDORevision)factory.createRevision(eClass);
revision.setID(id);
revision.setBranchPoint(transaction.getBranch().getHead());
@@ -547,6 +554,27 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
+ private void checkPackageRegistrationProblems(InternalCDOSession session, EClass eClass)
+ {
+ if (session.options().isGeneratedPackageEmulationEnabled())
+ {
+ // Check that there are no multiple EPackages with the same URI in system. Bug 335004
+ String packageURI = eClass.getEPackage().getNsURI();
+ Object packageObject = session.getPackageRegistry().get(packageURI);
+ if (packageObject instanceof InternalCDOPackageInfo)
+ {
+ packageObject = ((InternalCDOPackageInfo)packageObject).getEPackage(false);
+ }
+
+ if (packageObject instanceof EPackage && packageObject != eClass.getEPackage())
+ {
+ throw new IllegalStateException(MessageFormat.format(
+ "Global EPackage {0} for EClass {1} is different from EPackage found in CDOPackageRegistry",
+ packageURI, eClass));
+ }
+ }
+ }
+
private Iterator<InternalCDOObject> getProperContents(final InternalCDOObject object,
final CDOTransaction transaction)
{