Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-10-18 02:11:52 -0400
committerEike Stepper2008-10-18 02:11:52 -0400
commit732069dacf61148255d3144fe751067fe916c21e (patch)
treed8c55c68be1bbb57486fdce0d42ccf234266396a
parent11cec1f9139f19a67458b3e3ffcbdeefa271a6a4 (diff)
downloadcdo-732069dacf61148255d3144fe751067fe916c21e.tar.gz
cdo-732069dacf61148255d3144fe751067fe916c21e.tar.xz
cdo-732069dacf61148255d3144fe751067fe916c21e.zip
[249847] Store resources in a hierarchical structure
https://bugs.eclipse.org/bugs/show_bug.cgi?id=249847
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java112
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java8
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java8
4 files changed, 128 insertions, 16 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
index 9d730c6e42..b5987cc0a8 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
@@ -461,20 +461,22 @@ public class InitialTest extends AbstractCDOTest
transaction.commit();
enableConsole();
}
+
{
msg("Opening transaction");
CDOTransaction transaction = session.openTransaction();
msg("Getting resource");
- CDOResource resource = transaction.getResource("/test1");
+ CDOResource resource = transaction.getResource("/test1", true);
assertNotNull(resource);
assertEquals(URI.createURI("cdo://" + session.getRepositoryUUID() + "/test1"), resource.getURI());
assertEquals(transaction.getResourceSet(), resource.getResourceSet());
assertEquals(1, transaction.getResourceSet().getResources().size());
- assertEquals(CDOState.PROXY, resource.cdoState());
+ assertEquals(CDOState.CLEAN, resource.cdoState());
assertEquals(transaction, resource.cdoView());
- assertNull(resource.cdoRevision());
+ assertNotNull(resource.cdoRevision());
}
+
{
msg("Opening transaction");
CDOTransaction transaction = session.openTransaction();
@@ -486,9 +488,9 @@ public class InitialTest extends AbstractCDOTest
assertEquals(URI.createURI("cdo://" + session.getRepositoryUUID() + "/test1"), resource.getURI());
assertEquals(transaction.getResourceSet(), resource.getResourceSet());
assertEquals(1, transaction.getResourceSet().getResources().size());
- assertEquals(CDOState.PROXY, resource.cdoState());
+ assertEquals(CDOState.CLEAN, resource.cdoState());
assertEquals(transaction, resource.cdoView());
- assertNull(resource.cdoRevision());
+ assertNotNull(resource.cdoRevision());
}
}
@@ -666,9 +668,9 @@ public class InitialTest extends AbstractCDOTest
assertNotNull(resource);
assertEquals(URI.createURI("cdo://" + session.getRepositoryUUID() + "/test1"), resource.getURI());
assertEquals(transaction.getResourceSet(), resource.getResourceSet());
- assertEquals(CDOState.PROXY, resource.cdoState());
+ assertEquals(CDOState.CLEAN, resource.cdoState());
assertEquals(transaction, resource.cdoView());
- assertNull(resource.cdoRevision());
+ assertNotNull(resource.cdoRevision());
}
public void testLoadObject() throws Exception
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 aa9f2837d8..15403ff49f 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
@@ -21,6 +21,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.tests.model1.VAT;
import org.eclipse.emf.cdo.util.CDOURIUtil;
@@ -410,6 +411,117 @@ public class ResourceTest extends AbstractCDOTest
session.close();
}
+ private String createPath(String namePrefix, int depth, String name)
+ {
+ String path = "";
+ for (int i = 0; i < depth; i++)
+ {
+ String localName = namePrefix + String.valueOf(i + 1);
+ path += "/" + localName;
+ }
+ path += "/" + name;
+ return path;
+ }
+
+ public void testChangePathFromDepth0ToDepth0() throws Exception
+ {
+ testChangePath(0, 0);
+ }
+
+ public void testChangePathFromDepth0ToDepth1() throws Exception
+ {
+ testChangePath(0, 1);
+ }
+
+ public void testChangePathFromDepth0ToDepth2() throws Exception
+ {
+ testChangePath(0, 2);
+ }
+
+ public void testChangePathFromDepth0ToDepth3() throws Exception
+ {
+ testChangePath(0, 3);
+ }
+
+ public void testChangePathFromDepth3ToDepth3() throws Exception
+ {
+ testChangePath(3, 3);
+ }
+
+ public void testChangePathFromDepth3ToDepth2() throws Exception
+ {
+ testChangePath(3, 2);
+ }
+
+ public void testChangePathFromDepth3ToDepth1() throws Exception
+ {
+ testChangePath(3, 1);
+ }
+
+ public void testChangePathFromDepth3ToDepth0() throws Exception
+ {
+ testChangePath(3, 0);
+ }
+
+ public void testChangePath(int depthFrom, int depthTo) throws Exception
+ {
+ String prefixA = "testA";
+ String prefixB = "testB";
+
+ String oldPath = createPath(prefixA, depthFrom, "test");
+ String newPath = createPath(prefixB, depthTo, "test2");
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(oldPath);
+ Order order = getModel1Factory().createOrder();
+ resource.getContents().add(order);
+
+ String path = CDOURIUtil.extractResourcePath(resource.getURI());
+ assertEquals(oldPath, path);
+ assertEquals(depthFrom, CDOURIUtil.analyzePath(resource.getURI()).size() - 1);
+
+ transaction.commit();
+
+ CDOID idBeforeChangePath = CDOUtil.getCDOObject(resource).cdoID();
+ CDOID idBeforeChangePathOrder = CDOUtil.getCDOObject(order).cdoID();
+
+ msg("New path");
+ resource.setPath(newPath);
+ path = CDOURIUtil.extractResourcePath(resource.getURI());
+ assertEquals(depthTo, CDOURIUtil.analyzePath(resource.getURI()).size() - 1);
+ assertEquals(newPath, path);
+ transaction.commit();
+
+ CDOID idAfterChangePath = CDOUtil.getCDOObject(resource).cdoID();
+ assertEquals(idBeforeChangePath, idAfterChangePath);
+
+ CDOID idAfterChangePathOrder = CDOUtil.getCDOObject(order).cdoID();
+ assertEquals(idBeforeChangePathOrder, idAfterChangePathOrder);
+
+ Resource resourceRenamed = transaction.getResourceSet().getResource(
+ CDOURIUtil.createResourceURI(session, newPath), false);
+
+ assertEquals(resource, resourceRenamed);
+ assertClean(resource, transaction);
+ assertClean(order, transaction);
+ session.close();
+ }
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+
+ try
+ {
+ transaction.getResourceSet().getResource(CDOURIUtil.createResourceURI(session, oldPath), true);
+ fail("Doesn't exist");
+ }
+ catch (Exception ex)
+ {
+ }
+ Resource resource = transaction.getResourceSet().getResource(CDOURIUtil.createResourceURI(session, newPath), true);
+ assertNotNull(resource);
+ }
+
public void testChangePath() throws Exception
{
long commitTime1;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 95f19fe063..645f54f4dc 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -203,7 +203,7 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
*/
public URI getURI()
{
- if (initialURI != null)
+ if (cdoID() == null && initialURI != null)
{
return initialURI;
}
@@ -293,11 +293,6 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
*/
private Notification setLoaded(boolean isLoaded)
{
- if (isLoaded)
- {
- initialURI = null;
- }
-
boolean oldIsLoaded = loaded;
loaded = isLoaded;
@@ -535,7 +530,6 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
{
if (!isLoaded())
{
-
CDOViewImpl view = cdoView();
if (!FSMUtil.isTransient(this))
{
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 b1f8261cda..5d822f2f4c 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
@@ -2,7 +2,7 @@
* <copyright>
* </copyright>
*
- * $Id: CDOResourceNodeImpl.java,v 1.1.2.2 2008-10-17 19:07:51 estepper Exp $
+ * $Id: CDOResourceNodeImpl.java,v 1.1.2.3 2008-10-18 06:11:52 estepper Exp $
*/
package org.eclipse.emf.cdo.eresource.impl;
@@ -212,9 +212,13 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe
String newName = names.remove(names.size() - 1);
CDOResourceFolder newFolder = transaction.getOrCreateResourceFolder(names);
+ if (newFolder == null)
+ {
+ transaction.getRootResource().getContents().add(this);
+ }
+
basicSetFolder(newFolder, false);
basicSetName(newName, false);
-
adjustContainedResources(oldPath);
}
}

Back to the top