summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-02-10 03:11:33 (EST)
committerCaspar De Groot2011-02-10 03:11:33 (EST)
commitd35263782ae8bb93ab56cc3ac55ae5d8e8ab4e48 (patch)
treed4475b115907a0f509f0c84a4a4b382419e15716
parent9ab3bb2884164fd4b62276cac5c8b7272eb3417d (diff)
downloadcdo-d35263782ae8bb93ab56cc3ac55ae5d8e8ab4e48.zip
cdo-d35263782ae8bb93ab56cc3ac55ae5d8e8ab4e48.tar.gz
cdo-d35263782ae8bb93ab56cc3ac55ae5d8e8ab4e48.tar.bz2
[Bug 334995] CDOTransaction corrupted by persisted + new resource with same URI
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334995
-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_334995_Test.java70
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java22
3 files changed, 92 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 0dc37fd..5e4d846 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
@@ -199,6 +199,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_335004_Test.class);
testClasses.add(Bugzilla_336314_Test.class);
testClasses.add(Bugzilla_336590_Test.class);
+ testClasses.add(Bugzilla_334995_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_334995_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java
new file mode 100644
index 0000000..52f6cdc
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334995_Test.java
@@ -0,0 +1,70 @@
+/**
+ * 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.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.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import java.util.Map.Entry;
+
+/**
+ * Bug 334995 - CDOTransaction corrupted by persisted + new resource with same URI
+ *
+ * @author Caspar De Groot
+ */
+public class Bugzilla_334995_Test extends AbstractCDOTest
+{
+ public void test() throws CommitException
+ {
+ CDOID resourceID;
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/res1");
+ transaction.commit();
+ resourceID = resource.cdoID();
+ session.close();
+ }
+
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource = transaction.createResource("/res1");
+ msg("New resource: " + resource);
+ msg("newObjects:");
+
+ for (Entry<CDOID, CDOObject> entry : transaction.getNewObjects().entrySet())
+ {
+ msg(" " + entry + ", state: " + entry.getValue().cdoState());
+ assertNew(entry.getValue(), transaction);
+ }
+
+ // Fetch the persisted resource that has the same URI
+ CDOResource resource1 = (CDOResource)transaction.getObject(resourceID);
+ msg("Persisted resource: " + resource1);
+
+ msg("newObjects:");
+ for (Entry<CDOID, CDOObject> entry : transaction.getNewObjects().entrySet())
+ {
+ msg(" " + entry + ", state: " + entry.getValue().cdoState());
+ assertNew(entry.getValue(), transaction);
+ }
+
+ transaction.commit();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
index 2c2cb76..b40cd3a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
@@ -772,7 +772,27 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
private CDOResource newResourceInstance(InternalCDORevision revision)
{
String path = getResourcePath(revision);
- return getResource(path, true);
+ URI uri = CDOURIUtil.createResourceURI(this, path);
+
+ // Bug 334995: Check if locally there is already a resource with the same URI
+ CDOResource resource1 = (CDOResource)getResourceSet().getResource(uri, false);
+ String oldName = null;
+ if (resource1 != null)
+ {
+ // We have no other option than to change the name of the local resource
+ oldName = resource1.getName();
+ resource1.setName(oldName + ".renamed");
+ }
+
+ CDOResource resource2 = getResource(path, true);
+
+ if (resource1 != null)
+ {
+ OM.LOG.warn("URI clash: resource being instantiated had same URI as a resource already present "
+ + "locally; local resource was renamed from " + oldName + " to " + resource1.getName());
+ }
+
+ return resource2;
}
private String getResourcePath(InternalCDORevision revision)