Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-10-16 03:18:18 -0400
committerEike Stepper2008-10-16 03:18:18 -0400
commit5a66e91294c87603e75317d52b42dc2d53917e98 (patch)
tree121982d6dfd1007cd80f109c3baeae3809b9fcc8
parent26ee83ea483fcc3de3c037bac1a564416db5d9e0 (diff)
downloadcdo-5a66e91294c87603e75317d52b42dc2d53917e98.tar.gz
cdo-5a66e91294c87603e75317d52b42dc2d53917e98.tar.xz
cdo-5a66e91294c87603e75317d52b42dc2d53917e98.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/AbstractCDOTest.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java166
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java11
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java18
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaWrapper.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java65
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java26
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java15
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java33
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java3
14 files changed, 278 insertions, 121 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index 565e93c384..f6f7b3dabe 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -101,7 +101,14 @@ public abstract class AbstractCDOTest extends ConfigTest
assertNotNull(object.cdoID());
assertNotNull(object.cdoRevision());
assertNotNull(object.cdoView());
- assertNotNull(object.eResource());
+ if (eObject instanceof CDOResource && ((CDOResource)eObject).isRoot())
+ {
+ assertNull(object.eResource());
+ }
+ else
+ {
+ assertNotNull(object.eResource());
+ }
assertEquals(view, object.cdoView());
assertEquals(object, view.getObject(object.cdoID(), false));
}
@@ -135,9 +142,6 @@ public abstract class AbstractCDOTest extends ConfigTest
assertEquals(false, FSMUtil.isTransient(object));
assertNotNull(object.cdoID());
assertNotNull(object.cdoView());
- assertNotNull(object.cdoResource());
- assertNotNull(object.eResource());
- assertEquals(object.eResource(), object.cdoResource());
assertEquals(CDOState.PROXY, object.cdoState());
}
}
@@ -148,16 +152,16 @@ public abstract class AbstractCDOTest extends ConfigTest
CDOObject contained = CDOUtil.getCDOObject(eContained);
if (container != null && contained != null)
{
- assertEquals(container.eResource(), contained.eResource());
assertEquals(true, container.eContents().contains(contained));
if (container instanceof CDOResource)
{
- assertEquals(container.eResource(), container.cdoResource());
+ assertEquals(container, contained.eResource());
assertEquals(null, contained.eContainer());
assertEquals(true, ((CDOResource)container).getContents().contains(contained));
}
else
{
+ assertEquals(container.eResource(), contained.eResource());
assertEquals(container, contained.eContainer());
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
index 3e10fa9504..7ba2a9ce7d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
@@ -576,12 +576,12 @@ public class ComplexTest extends AbstractCDOTest
for (EObject o : elementToRemove)
{
MultiContainedElement element_work = (MultiContainedElement)o;
- assertEquals(resource1FromTx2, CDOUtil.getCDOObject(element_work).cdoResource());
+ assertEquals(resource1FromTx2, CDOUtil.getCDOObject(element_work).cdoDirectResource());
assertEquals(resource1FromTx2, element_work.eResource());
container.getElements().add(element_work);
- assertEquals(null, CDOUtil.getCDOObject(element_work).cdoResource());
+ assertEquals(null, CDOUtil.getCDOObject(element_work).cdoDirectResource());
assertEquals(resource2, element_work.eResource());
transaction2.commit();
}
@@ -605,13 +605,13 @@ public class ComplexTest extends AbstractCDOTest
assertTrue(element.getParent() == container2);
assertTrue(element.eContainer() == container2);
- assertTrue(CDOUtil.getCDOObject(element).cdoResource() == null);
+ assertTrue(CDOUtil.getCDOObject(element).cdoDirectResource() == null);
assertTrue(container1.getElement() == null);
- assertTrue(CDOUtil.getCDOObject(container1).cdoResource() == resource1);
+ assertTrue(CDOUtil.getCDOObject(container1).cdoDirectResource() == resource1);
assertTrue(container2.getElement() == element);
- assertTrue(CDOUtil.getCDOObject(container2).cdoResource() == resource2);
+ assertTrue(CDOUtil.getCDOObject(container2).cdoDirectResource() == resource2);
}
public void testMigrateContainmentMulti()
@@ -637,19 +637,19 @@ public class ComplexTest extends AbstractCDOTest
assertTrue(elementA.getParent() == container2);
assertTrue(elementA.eContainer() == container2);
- assertTrue(CDOUtil.getCDOObject(elementA).cdoResource() == null);
+ assertTrue(CDOUtil.getCDOObject(elementA).cdoDirectResource() == null);
assertTrue(elementA.eResource() == resource2);
assertTrue(elementB.getParent() == container1);
assertTrue(elementB.eContainer() == container1);
- assertTrue(CDOUtil.getCDOObject(elementB).cdoResource() == null);
+ assertTrue(CDOUtil.getCDOObject(elementB).cdoDirectResource() == null);
assertTrue(elementB.eResource() == resource1);
- assertTrue(CDOUtil.getCDOObject(container1).cdoResource() == resource1);
+ assertTrue(CDOUtil.getCDOObject(container1).cdoDirectResource() == resource1);
assertEquals(1, container1.getElements().size());
assertEquals(elementB, container1.getElements().get(0));
- assertTrue(CDOUtil.getCDOObject(container2).cdoResource() == resource2);
+ assertTrue(CDOUtil.getCDOObject(container2).cdoDirectResource() == resource2);
assertEquals(1, container2.getElements().size());
assertEquals(elementA, container2.getElements().get(0));
}
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 00b13a9d3c..9d730c6e42 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
@@ -242,7 +242,7 @@ public class InitialTest extends AbstractCDOTest
assertNew(supplier, transaction);
assertNew(resource, transaction);
assertEquals(supplier, s);
- assertEquals(resource, CDOUtil.getCDOObject(s).cdoResource());
+ assertEquals(resource, CDOUtil.getCDOObject(s).cdoDirectResource());
assertEquals(null, s.eContainer());
}
@@ -270,7 +270,7 @@ public class InitialTest extends AbstractCDOTest
contents.add(supplier);
assertNew(supplier, transaction);
assertEquals(transaction, CDOUtil.getCDOObject(supplier).cdoView());
- assertEquals(resource, CDOUtil.getCDOObject(supplier).cdoResource());
+ assertEquals(resource, CDOUtil.getCDOObject(supplier).cdoDirectResource());
assertEquals(resource, supplier.eResource());
assertEquals(null, supplier.eContainer());
}
@@ -858,8 +858,8 @@ public class InitialTest extends AbstractCDOTest
resource1.getContents().add(cat1);
cat1.getCategories().add(cat2);
- assertEquals(null, CDOUtil.getCDOObject(cat2).cdoResource());
- assertEquals(resource1, CDOUtil.getCDOObject(cat1).cdoResource());
+ assertEquals(null, CDOUtil.getCDOObject(cat2).cdoDirectResource());
+ assertEquals(resource1, CDOUtil.getCDOObject(cat1).cdoDirectResource());
assertEquals(null, ((InternalEObject)cat2).eDirectResource());
assertEquals(resource1, ((InternalEObject)cat1).eDirectResource());
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 759db2ab2d..aa9f2837d8 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
@@ -12,10 +12,12 @@
package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOAudit;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.CDOView;
+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;
@@ -44,6 +46,150 @@ import junit.framework.Assert;
*/
public class ResourceTest extends AbstractCDOTest
{
+ public void testAttachDetachResourceDepth1_Delete() throws Exception
+ {
+ testAttachDetachResourceDepth1(1, true, 0);
+ }
+
+ public void testAttachDetachResourceDepth1_Remove() throws Exception
+ {
+ testAttachDetachResourceDepth1(1, false, 0);
+ }
+
+ public void testAttachDetachResourceDepth2_Delete() throws Exception
+ {
+ testAttachDetachResourceDepth1(2, true, 1);
+ }
+
+ public void testAttachDetachResourceDepth2_Remove() throws Exception
+ {
+ testAttachDetachResourceDepth1(2, false, 1);
+ }
+
+ public void testAttachDetachResourceDepth3_Delete() throws Exception
+ {
+ testAttachDetachResourceDepth1(3, true, 2);
+ }
+
+ public void testAttachDetachResourceDepth3_Remove() throws Exception
+ {
+ testAttachDetachResourceDepth1(3, false, 2);
+ }
+
+ public void testAttachDetachResourceDepth3_Remove_Tree() throws Exception
+ {
+ testAttachDetachResourceDepth1(3, false, 1);
+ }
+
+ /**
+ * Create resource with the following pattern /test1/test2/test3 for a depth 3. <br>
+ * After it will remove the resource with the following rule:<br>
+ * if calldelete is true <code>resource.delete(null)</code> <br>
+ * if calldelete is false it will use the depthtoRemove to call <code>object.remove(resource)</code><br>
+ * deptToRemove = /0/1/2/...<br>
+ * It will remove it from parent folder (depthtoRemove - 1);
+ */
+ public void testAttachDetachResourceDepth1(int depth, boolean callDelete, int depthtoRemove) throws Exception
+ {
+ CDOSession session = openModel1Session();
+ ResourceSet resourceSet = new ResourceSetImpl();
+ CDOTransaction transaction = session.openTransaction(resourceSet);
+ CDOResource rootResource = transaction.getRootResource();
+ String path = "";
+ List<String> names = new ArrayList<String>();
+ for (int i = 0; i < depth; i++)
+ {
+ String name = "test" + String.valueOf(i + 1);
+ names.add(name);
+ path += "/" + name;
+ }
+ final URI uri = URI.createURI("cdo:" + path);
+ CDOResource resource = (CDOResource)resourceSet.createResource(uri);
+ assertEquals(names.get(names.size() - 1), resource.getName());
+
+ transaction.commit();
+ List<CDOResourceNode> nodesList = new ArrayList<CDOResourceNode>();
+ CDOResource resourceByLookup = null;
+ CDOResourceNode next = null;
+ for (int i = 0; i < depth; i++)
+ {
+ if (i == 0)
+ {
+ next = (CDOResourceNode)rootResource.getContents().get(0);
+ }
+ else
+ {
+ next = ((CDOResourceFolder)next).getNodes().get(0);
+ }
+ nodesList.add(next);
+ }
+ resourceByLookup = (CDOResource)next;
+ assertSame(resource, resourceByLookup);
+ assertClean(resourceByLookup, transaction);
+ assertEquals(true, resourceSet.getResources().contains(resourceByLookup));
+
+ CDOObject cdoParent = null;
+ CDOObject cdoRootResource = CDOUtil.getCDOObject(rootResource);
+ for (int i = 0; i < depth; i++)
+ {
+ CDOResourceNode resourceNode = nodesList.get(i);
+ CDOObject cdoResourceNode = CDOUtil.getCDOObject(resourceNode);
+
+ if (i == 0)
+ {
+ assertEquals(cdoRootResource.cdoID(), cdoResourceNode.cdoRevision().getData().getResourceID());
+ assertEquals(CDOID.NULL, cdoResourceNode.cdoRevision().getData().getContainerID());
+ }
+ else
+ {
+ assertEquals(CDOID.NULL, cdoResourceNode.cdoRevision().getData().getResourceID());
+ assertEquals(cdoParent.cdoID(), cdoResourceNode.cdoRevision().getData().getContainerID());
+ }
+ cdoParent = cdoResourceNode;
+ }
+
+ if (callDelete)
+ {
+ resource.delete(null);
+ depthtoRemove = depth;
+ }
+ else
+ {
+ CDOResourceNode node = nodesList.get(depthtoRemove);
+ if (depthtoRemove == 0)
+ {
+ rootResource.getContents().remove(node);
+ }
+ else
+ {
+ CDOResourceFolder parentFolder = (CDOResourceFolder)nodesList.get(depthtoRemove - 1);
+ assertEquals(parentFolder, node.getFolder());
+ parentFolder.getNodes().remove(node);
+ }
+ }
+ for (int i = depthtoRemove; i < depth; i++)
+ {
+ CDOResourceNode transientNode = nodesList.get(i);
+ assertTransient(transientNode);
+ if (transientNode instanceof CDOResource)
+ {
+ assertEquals(false, resourceSet.getResources().contains(transientNode));
+ }
+ assertEquals(null, transientNode.eResource());
+ if (i == depthtoRemove)
+ {
+ assertEquals(null, transientNode.eContainer());
+ }
+ else
+ {
+ assertEquals(cdoParent, transientNode.eContainer());
+ }
+ cdoParent = transientNode;
+ }
+
+ transaction.commit();
+ }
+
public void testCreateResource_FromResourceSet() throws Exception
{
CDOSession session = openModel1Session();
@@ -58,6 +204,26 @@ public class ResourceTest extends AbstractCDOTest
assertEquals(CDOURIUtil.createResourceURI(session, "test1"), resource.getURI());
assertEquals("test1", resource.getName());
assertEquals(null, resource.getFolder());
+ transaction.getRootResource().getContents().contains(resource);
+ transaction.commit();
+
+ CDOObject cdoResource = CDOUtil.getCDOObject(resource);
+ CDOObject cdoRootResource = CDOUtil.getCDOObject(transaction.getRootResource());
+
+ assertClean(cdoResource, transaction);
+ assertClean(cdoRootResource, transaction);
+ assertEquals(CDOID.NULL, cdoResource.cdoRevision().getData().getContainerID());
+ assertEquals(cdoRootResource.cdoID(), cdoResource.cdoRevision().getData().getResourceID());
+ assertEquals(CDOID.NULL, cdoRootResource.cdoRevision().getData().getResourceID());
+
+ assertEquals(true, transaction.getResourceSet().getResources().contains(resource));
+ assertEquals(true, transaction.getResourceSet().getResources().contains(transaction.getRootResource()));
+
+ transaction.getRootResource().getContents().remove(resource);
+
+ assertEquals(false, transaction.getResourceSet().getResources().contains(resource));
+ assertEquals(true, transaction.getResourceSet().getResources().contains(transaction.getRootResource()));
+
}
public void testCreateNestedResource_FromResourceSet() throws Exception
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java
index 32c067e89b..3e0f1c81a2 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java
@@ -58,7 +58,7 @@ public class StateMachineTest extends AbstractCDOTest
resource.getContents().add(supplier);
assertNew(supplier, transaction);
assertEquals(transaction, CDOUtil.getCDOObject(supplier).cdoView());
- assertEquals(resource, CDOUtil.getCDOObject(supplier).cdoResource());
+ assertEquals(resource, CDOUtil.getCDOObject(supplier).cdoDirectResource());
assertEquals(resource, supplier.eResource());
assertEquals(null, supplier.eContainer());
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
index fa4957c349..0f199e8b6e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java
@@ -22,17 +22,22 @@ import org.eclipse.emf.ecore.EObject;
*/
public interface CDOObject extends EObject
{
+ public CDOState cdoState();
+
public CDOClass cdoClass();
public CDOID cdoID();
- public CDOState cdoState();
-
public CDOView cdoView();
+ public CDORevision cdoRevision();
+
public CDOResource cdoResource();
- public CDORevision cdoRevision();
+ /**
+ * @since 2.0
+ */
+ public CDOResource cdoDirectResource();
public void cdoReload();
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
index b293b47603..f4de190232 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
@@ -20,7 +20,6 @@ import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
import org.eclipse.emf.cdo.util.CDOPackageRegistry;
@@ -79,8 +78,6 @@ public final class CDOLegacyWrapper extends CDOObjectWrapper
private CDOState state;
- private CDOResourceImpl resource;
-
private InternalCDORevision revision;
private boolean allProxiesResolved;
@@ -108,11 +105,6 @@ public final class CDOLegacyWrapper extends CDOObjectWrapper
return revision;
}
- public CDOResourceImpl cdoResource()
- {
- return resource;
- }
-
public void cdoReload()
{
CDOStateMachine.INSTANCE.reload(this);
@@ -147,16 +139,6 @@ public final class CDOLegacyWrapper extends CDOObjectWrapper
this.revision = (InternalCDORevision)revision;
}
- public void cdoInternalSetResource(CDOResource resource)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting resource: {0}", resource);
- }
-
- this.resource = (CDOResourceImpl)resource;
- }
-
public void cdoInternalPostAttach()
{
// TODO Avoid if no adapters in list (eBasicAdapters?)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaWrapper.java
index bd42b60abf..398dedf9cc 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOMetaWrapper.java
@@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.ecore.InternalEObject;
@@ -41,7 +41,14 @@ public class CDOMetaWrapper extends CDOObjectWrapper
throw new UnsupportedOperationException();
}
- public CDOResource cdoResource()
+ @Override
+ public CDOResourceImpl cdoResource()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CDOResourceImpl cdoDirectResource()
{
throw new UnsupportedOperationException();
}
@@ -71,11 +78,6 @@ public class CDOMetaWrapper extends CDOObjectWrapper
throw new UnsupportedOperationException();
}
- public void cdoInternalSetResource(CDOResource resource)
- {
- throw new UnsupportedOperationException();
- }
-
public void cdoInternalPostLoad()
{
throw new UnsupportedOperationException();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index 47bf511039..77e3482937 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -74,10 +74,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
private CDOViewImpl view;
- // TODO Consider removal because it's only an optimization (proof that revision.resourceID could be used in all cases
- // as well)
- private CDOResourceImpl resource;
-
private InternalCDORevision revision;
public CDOObjectImpl()
@@ -113,12 +109,27 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public CDOResourceImpl cdoResource()
{
- if (this instanceof CDOResourceImpl)
+ Resource resource = eResource();
+ if (resource instanceof CDOResourceImpl)
{
- resource = (CDOResourceImpl)this;
+ return (CDOResourceImpl)resource;
}
- return resource;
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public CDOResourceImpl cdoDirectResource()
+ {
+ Resource.Internal resource = eDirectResource();
+ if (resource instanceof CDOResourceImpl)
+ {
+ return (CDOResourceImpl)resource;
+ }
+
+ return null;
}
public void cdoReload()
@@ -184,17 +195,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public void cdoInternalSetResource(CDOResource resource)
{
- if (this instanceof CDOResourceImpl)
- {
- return;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting resource: {0}", resource);
- }
-
- this.resource = (CDOResourceImpl)resource;
+ throw new UnsupportedOperationException();
}
public void cdoInternalPostLoad()
@@ -250,7 +251,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
if (directResource instanceof CDOResource)
{
CDOResource cdoResource = (CDOResource)directResource;
- cdoInternalSetResource(cdoResource);
revision.setResourceID(cdoResource.cdoID());
}
@@ -345,7 +345,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
CDOViewImpl view = cdoView();
- super.eSetDirectResource(cdoResource());
+ super.eSetDirectResource(cdoDirectResource());
eContainer = eStore().getContainer(this);
eContainerFeatureID = getStore().getContainingFeatureID(this);
@@ -591,8 +591,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
else if (resource instanceof CDOResourceImpl || resource == null)
{
- this.resource = (CDOResourceImpl)resource;
- getStore().setContainer(this, cdoResource(), eInternalContainer(), eContainerFeatureID());
+ getStore().setContainer(this, (CDOResourceImpl)resource, eInternalContainer(), eContainerFeatureID());
}
else
{
@@ -606,17 +605,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public Resource.Internal eDirectResource()
{
- if (this instanceof Resource.Internal)
- {
- return (Internal)this;
- }
-
if (FSMUtil.isTransient(this))
{
return super.eDirectResource();
}
- return cdoResource();
+ return (Resource.Internal)getStore().getResource(this);
}
/**
@@ -739,7 +733,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public NotificationChain eBasicSetContainer(InternalEObject newContainer, int newContainerFeatureID,
NotificationChain msgs)
{
- boolean isResource = this instanceof CDOResource;
+ boolean isResourceRoot = this instanceof CDOResource && ((CDOResource)this).isRoot();
+
InternalEObject oldContainer = eInternalContainer();
Resource.Internal oldResource = eDirectResource();
Resource.Internal newResource = null;
@@ -747,12 +742,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
if (newContainer != null && !eContainmentFeature(this, newContainer, newContainerFeatureID).isResolveProxies())
{
- if (!isResource)
- {
- msgs = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, msgs);
- eSetDirectResource(null);
- }
-
+ msgs = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, msgs);
+ eSetDirectResource(null);
newResource = newContainer.eInternalResource();
}
else
@@ -778,7 +769,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
: null;
boolean moved = oldView != null && oldView == newView;
- if (!moved && oldResource != null && !isResource)
+ if (!moved && oldResource != null && !isResourceRoot)
{
oldResource.detached(this);
}
@@ -901,7 +892,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
else
{
- getStore().setContainer(this, cdoResource(), newEContainer, newContainerFeatureID);
+ getStore().setContainer(this, cdoDirectResource(), newEContainer, newContainerFeatureID);
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
index ac8845d500..78441c6506 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
@@ -60,6 +61,31 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
return view;
}
+ public CDOResourceImpl cdoResource()
+ {
+ Resource resource = eResource();
+ if (resource instanceof CDOResourceImpl)
+ {
+ return (CDOResourceImpl)resource;
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public CDOResourceImpl cdoDirectResource()
+ {
+ Resource.Internal resource = eDirectResource();
+ if (resource instanceof CDOResourceImpl)
+ {
+ return (CDOResourceImpl)resource;
+ }
+
+ return null;
+ }
+
public void cdoInternalSetID(CDOID id)
{
if (id == null)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
index aa03d64a1a..39d5dc2038 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
@@ -127,6 +127,21 @@ public final class CDOStore implements EStore
return revision.getContainingFeatureID();
}
+ /**
+ * @since 2.0
+ */
+ public InternalEObject getResource(InternalEObject eObject)
+ {
+ InternalCDOObject cdoObject = getCDOObject(eObject);
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("getContainer({0})", cdoObject);
+ }
+
+ InternalCDORevision revision = getRevisionForReading(cdoObject);
+ return (InternalEObject)((CDOViewImpl)cdoObject.cdoView()).convertIDToObject(revision.getResourceID());
+ }
+
@Deprecated
public EStructuralFeature getContainingFeature(InternalEObject eObject)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 6dac50dfde..cdd1dfb691 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -362,7 +362,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
CDOID id = super.getRootOrTopLevelResourceNodeID(name);
- if (getLastSavepoint().getAllDetachedObjects().containsKey(id))
+ if (getLastSavepoint().getAllDetachedObjects().containsKey(id) || getDirtyObjects().containsKey(id))
{
throw new CDOException("Root resource node " + name + " doesn't exist");
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index e07a940a17..3747c3acd4 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -580,23 +580,6 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
return (CDOResourceImpl)getObject(resourceID);
}
- public CDOResourceImpl addResource(CDOID id, String path)
- {
- URI createURI = CDOURIUtil.createResourceURI(this, path);
- CDOResourceImpl resource = (CDOResourceImpl)viewSet.getResourceFactory().createResource(createURI);
- resource.setURI(createURI);
-
- InternalCDOObject resourceObject = resource;
- resourceObject.cdoInternalSetID(id);
- resourceObject.cdoInternalSetView(this);
- resourceObject.cdoInternalSetResource(resource);
- resourceObject.cdoInternalSetState(CDOState.PROXY);
-
- ResourceSet resourceSet = getResourceSet();
- resourceSet.getResources().add(resource);
- return resource;
- }
-
public InternalCDOObject newInstance(EClass eClass)
{
EObject eObject = EcoreUtil.create(eClass);
@@ -822,20 +805,7 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
protected void cleanObject(InternalCDOObject object, InternalCDORevision revision)
{
object.cdoInternalCleanup();
- if (object instanceof CDOResourceImpl)
- {
- object.cdoInternalSetResource((CDOResourceImpl)object);
- }
- else
- {
- CDOID resourceID = revision.getResourceID();
- if (!resourceID.isNull())
- {
- CDOResourceImpl resource = getResource(resourceID);
- object.cdoInternalSetResource(resource);
- }
- }
-
+
object.cdoInternalSetView(this);
object.cdoInternalSetRevision(revision);
object.cdoInternalSetID(revision.getID());
@@ -978,7 +948,6 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
{
CDOID id = getResourceID(path);
resource.cdoInternalSetID(id);
- resource.cdoInternalSetResource(resource);
registerObject(resource);
}
catch (Exception ex)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
index f1499e4810..e9d3b48492 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/InternalCDOObject.java
@@ -15,7 +15,6 @@ import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
@@ -35,8 +34,6 @@ public interface InternalCDOObject extends CDOObject, InternalEObject, InternalC
public void cdoInternalSetID(CDOID id);
- public void cdoInternalSetResource(CDOResource resource);
-
public void cdoInternalSetView(CDOView view);
public void cdoInternalSetRevision(CDORevision revision);

Back to the top