summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-02-14 05:38:30 (EST)
committerCaspar De Groot2011-02-14 05:38:30 (EST)
commit187efc3f2ea8cc2a1311b7d06a5770bf3c83e1ae (patch)
tree417b2c067d50f7bcd3a37fc991bf978b888a19f5
parentcca85402a1c8768847a965c451eab8bf71e9f236 (diff)
downloadcdo-187efc3f2ea8cc2a1311b7d06a5770bf3c83e1ae.zip
cdo-187efc3f2ea8cc2a1311b7d06a5770bf3c83e1ae.tar.gz
cdo-187efc3f2ea8cc2a1311b7d06a5770bf3c83e1ae.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/bugzilla/Bugzilla_334995_Test.java55
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java10
2 files changed, 48 insertions, 17 deletions
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
index 52f6cdc..596d0dd 100644
--- 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
@@ -29,15 +29,7 @@ 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();
- }
+ CDOID[] resourceIDs = persistResources("/res1");
{
CDOSession session = openSession();
@@ -54,7 +46,7 @@ public class Bugzilla_334995_Test extends AbstractCDOTest
}
// Fetch the persisted resource that has the same URI
- CDOResource resource1 = (CDOResource)transaction.getObject(resourceID);
+ CDOResource resource1 = (CDOResource)transaction.getObject(resourceIDs[0]);
msg("Persisted resource: " + resource1);
msg("newObjects:");
@@ -67,4 +59,47 @@ public class Bugzilla_334995_Test extends AbstractCDOTest
transaction.commit();
}
}
+
+ public void testRename() throws CommitException
+ {
+ CDOID[] resourceIDs = persistResources("/res1", "/res2");
+
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.getResource("/res1");
+ resource1.setPath("/res2");
+
+ CDOResource resource2 = (CDOResource)transaction.getObject(resourceIDs[1]);
+
+ resource1.getContents().add(getModel1Factory().createAddress());
+ resource2.getContents().add(getModel1Factory().createAddress());
+ transaction.commit();
+
+ session.close();
+ }
+ }
+
+ private CDOID[] persistResources(String... resourceNames) throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ int i = 0;
+ CDOResource[] resources = new CDOResource[resourceNames.length];
+ for (String resourceName : resourceNames)
+ {
+ resources[i++] = transaction.createResource(resourceName);
+ }
+ transaction.commit();
+
+ CDOID[] resourceIDs = new CDOID[resourceNames.length];
+ for (i = 0; i < resources.length; i++)
+ {
+ resourceIDs[i] = resources[i].cdoID();
+ }
+
+ session.close();
+ return resourceIDs;
+ }
}
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 11971e9..5c75cc0 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
@@ -762,21 +762,17 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
// 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)
+ if (resource1 != null && !isReadOnly())
{
// 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());
}
+ CDOResource resource2 = getResource(path, true);
+
return resource2;
}