Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2019-10-30 12:20:46 -0400
committerEike Stepper2019-10-30 12:20:46 -0400
commitc9c07f7e1cf23236d5dd73ae631d28aeee33d510 (patch)
tree1bcc4d7f2f318c5d9f5ba487e3795c444152de97
parente064154d851a765006f3bbc54901f68a70f4c2c8 (diff)
downloadcdo-c9c07f7e1cf23236d5dd73ae631d28aeee33d510.tar.gz
cdo-c9c07f7e1cf23236d5dd73ae631d28aeee33d510.tar.xz
cdo-c9c07f7e1cf23236d5dd73ae631d28aeee33d510.zip
[540266] "Duplicate path" exception when moving an existing CDOResourceNode to a different folder
https://bugs.eclipse.org/bugs/show_bug.cgi?id=540266
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java46
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java3
3 files changed, 50 insertions, 15 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
index 5f2468a3b6..163fe22f71 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
@@ -678,6 +678,52 @@ public class ResourceTest extends AbstractCDOTest
assertEquals(true, CDOIDUtil.isNull(data.getResourceID()));
}
+ public void testNoUneededResourcesLoadOnMove() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ // Fill folder1
+ transaction.createResource(getResourcePath("folder1/res1"));
+ transaction.createResource(getResourcePath("folder1/res2"));
+
+ // Fill folder2
+ transaction.createResource(getResourcePath("folder2/res3"));
+ transaction.createResource(getResourcePath("folder2/res4"));
+
+ transaction.commit();
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ assertTrue(transaction.getResourceSet().getResources().isEmpty());
+
+ CDOResourceFolder folder1 = transaction.getResourceFolder(getResourcePath("folder1"));
+ CDOResourceFolder folder2 = transaction.getResourceFolder(getResourcePath("folder2"));
+ assertEquals(0, transaction.getResourceSet().getResources().size());
+
+ // The "no duplicates" validation should not trigger the load of other resources
+ folder1.addResource("res5");
+ assertEquals(1, transaction.getResourceSet().getResources().size());
+
+ // The "commit" operation should not trigger the load of other resources
+ transaction.commit();
+ assertEquals(1, transaction.getResourceSet().getResources().size());
+
+ CDOResource resource1 = transaction.getResource(getResourcePath("folder1/res1"));
+ assertEquals(2, transaction.getResourceSet().getResources().size());
+
+ // The "no duplicates" validation should not trigger the load of other resources
+ resource1.setFolder(folder2);
+ assertEquals(2, transaction.getResourceSet().getResources().size());
+
+ transaction.commit();
+ assertEquals(2, transaction.getResourceSet().getResources().size());
+
+ // The load of sibling resources is expected with an explicit call to getNodes().
+ folder1.getNodes().add(resource1);
+ assertEquals(3, transaction.getResourceSet().getResources().size());
+ }
+
public void testDuplicatePathAfterDetach() throws Exception
{
CDOSession session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
index 68dc0397af..b813165556 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
@@ -22,8 +22,6 @@ import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.util.CDOURIUtil;
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.emf.common.util.EList;
@@ -35,8 +33,6 @@ import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
import org.eclipse.emf.spi.cdo.InternalCDOView;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -139,16 +135,8 @@ public class CDOResourceFolderImpl extends CDOResourceNodeImpl implements CDORes
@Override
protected CDOResourceNode validate(int index, CDOResourceNode newNode)
{
- String newName = newNode.getName();
-
- for (Iterator<CDOResourceNode> it = iterator(); it.hasNext();)
- {
- CDOResourceNode existingNode = it.next();
- if (ObjectUtil.equals(existingNode.getName(), newName))
- {
- throw new CDODuplicateResourceException(MessageFormat.format(Messages.getString("CDOResourceNodeImpl.5"), existingNode.getPath())); //$NON-NLS-1$
- }
- }
+ String newPath = getPath() + CDOURIUtil.SEGMENT_SEPARATOR + newNode.getName();
+ CDOResourceFolderImpl.this.checkDuplicates(newPath);
return super.validate(index, newNode);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
index e626c332cb..d42a773491 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java
@@ -422,8 +422,9 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe
/**
* @ADDED
+ * @since 4.8
*/
- private void checkDuplicates(String newPath) throws CDODuplicateResourceException
+ protected void checkDuplicates(String newPath) throws CDODuplicateResourceException
{
InternalCDOView view = cdoView();
if (view != null)

Back to the top