Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-11 09:25:45 +0000
committerEike Stepper2012-09-11 09:25:45 +0000
commit331d1571faab283cfe17870af6c29fef78ab5e5b (patch)
tree7f5342e00072738d1822960fedd4e42b89b0f13e /plugins
parent83bca15d508274b6db6a5df2d636876a86ca0e8c (diff)
downloadcdo-331d1571faab283cfe17870af6c29fef78ab5e5b.tar.gz
cdo-331d1571faab283cfe17870af6c29fef78ab5e5b.tar.xz
cdo-331d1571faab283cfe17870af6c29fef78ab5e5b.zip
[389231] Don't load all resource contents for remove(int)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389231
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java53
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java4
2 files changed, 55 insertions, 2 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 f6ea641bd3..d85b005e01 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
@@ -34,6 +34,7 @@ import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.util.ObjectNotFoundException;
+import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.io.IOUtil;
@@ -41,6 +42,8 @@ import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
@@ -49,6 +52,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -433,6 +437,55 @@ public class ResourceTest extends AbstractCDOTest
}
}
+ public void testRemoveResourceByIndex() throws Exception
+ {
+ final int trees = 5;
+ final int depth = 5;
+ int count = 0;
+
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/test1"));
+ for (int i = 0; i < trees; i++)
+ {
+ Category tree = createCategoryTree(depth);
+ if (count == 0)
+ {
+ count = 1 + countObjects(tree);
+ }
+
+ resource.getContents().add(tree);
+ }
+
+ transaction.commit();
+ session.close();
+ }
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ transaction.options().setStrongReferencePolicy(CDOAdapterPolicy.ALL);
+
+ CDOResource resource = transaction.getResource(getResourcePath("/test1"));
+ EList<EObject> contents = resource.getContents();
+ int expected = ((InternalCDOTransaction)transaction).getObjects().size() + count;
+
+ contents.remove(3);
+ assertEquals(expected, ((InternalCDOTransaction)transaction).getObjects().size());
+ }
+
+ private int countObjects(EObject tree)
+ {
+ int count = 0;
+ for (TreeIterator<EObject> it = tree.eAllContents(); it.hasNext();)
+ {
+ it.next();
+ ++count;
+ }
+
+ return count;
+ }
+
public void testAttachResource() throws Exception
{
CDOSession session = openSession();
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 2dc67cc128..41c3237c20 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
@@ -739,12 +739,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
isSameView = oldView != null && oldView == newView;
}
- if (oldResource != null)
+ if (oldResource != null && resource != null)
{
notifications = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, notifications);
// When setting the resource to null we assume that detach has already been called in the resource implementation
- if (!isSameView && resource != null)
+ if (!isSameView)
{
oldResource.detached(this);
}

Back to the top