summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-04-04 04:41:11 (EDT)
committerCaspar De Groot2011-04-04 04:41:11 (EDT)
commita9771b2952e4ee1ece0f855fc1add8ca4a316698 (patch)
tree747062cd8b9e18c3c3de69281df1cf9a4397b393
parentd9074c45e6c3138ce36afe9f24935ca43b2117e2 (diff)
downloadcdo-a9771b2952e4ee1ece0f855fc1add8ca4a316698.zip
cdo-a9771b2952e4ee1ece0f855fc1add8ca4a316698.tar.gz
cdo-a9771b2952e4ee1ece0f855fc1add8ca4a316698.tar.bz2
[Bug 337523] Root resource is in illegal state
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337523
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_337523_Test.java48
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java58
3 files changed, 102 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 259539e..3b550f0 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -210,6 +210,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_336314_Test.class);
testClasses.add(Bugzilla_336382_Test.class);
testClasses.add(Bugzilla_336590_Test.class);
+ testClasses.add(Bugzilla_337523_Test.class);
testClasses.add(Bugzilla_338884_Test.class);
testClasses.add(Bugzilla_338779_Test.class);
testClasses.add(Bugzilla_339461_Test.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_337523_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_337523_Test.java
new file mode 100644
index 0000000..121112a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_337523_Test.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Egidijus Vaisnora - initial API and implementation
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
+
+import java.util.Map;
+
+/**
+ * @author Egidijus Vaisnora, Caspar De Groot
+ */
+public class Bugzilla_337523_Test extends AbstractCDOTest
+{
+ public void testRootResource_loadByID() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ final CDOID rootID = session.getRepositoryInfo().getRootResourceID();
+ CDOObject rootResource1 = transaction.getObject(rootID);
+
+ Map<CDOID, InternalCDOObject> objects = ((InternalCDOTransaction)transaction).getObjects();
+ CDOObject rootResource2 = objects.get(rootID);
+
+ assertNotNull(rootResource2);
+ assertSame(rootResource1, rootResource2);
+
+ transaction.commit();
+ transaction.close();
+ }
+}
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 9493eea..633690d 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
@@ -69,6 +69,7 @@ import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.log.OMLogger;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
@@ -202,15 +203,21 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
if (rootResource == null)
{
CDOID rootResourceID = getSession().getRepositoryInfo().getRootResourceID();
- rootResource = (CDOResourceImpl)getObject(rootResourceID);
- rootResource.setRoot(true);
- registerObject(rootResource);
- getResourceSet().getResources().add(rootResource);
+ CDOResourceImpl resource = (CDOResourceImpl)getObject(rootResourceID);
+ setRootResource(resource);
}
return rootResource;
}
+ private synchronized void setRootResource(CDOResourceImpl resource)
+ {
+ rootResource = resource;
+ rootResource.setRoot(true);
+ registerObject(rootResource);
+ getResourceSet().getResources().add(rootResource);
+ }
+
protected synchronized void clearRootResource()
{
if (rootResource != null)
@@ -481,7 +488,44 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
{
checkActive();
URI uri = CDOURIUtil.createResourceURI(this, path);
- return (CDOResource)getResourceSet().getResource(uri, loadInDemand);
+ ResourceSet resourceSet = getResourceSet();
+ ensureURIs(resourceSet); // Bug 337523
+ return (CDOResource)resourceSet.getResource(uri, loadInDemand);
+ }
+
+ /**
+ * Ensures that the URIs of all resources in this resourceSet, can be fetched without triggering the loading of
+ * additional resources. Without calling this first, it is dangerous to iterate over the resources to collect their
+ * URI's, because
+ */
+ private void ensureURIs(ResourceSet resourceSet)
+ {
+ EList<Resource> resources = resourceSet.getResources();
+ Resource[] resourceArr = null;
+
+ int size = 0;
+ int i;
+
+ do
+ {
+ i = size;
+ size = resources.size();
+ if (size == 0)
+ {
+ break;
+ }
+
+ if (resourceArr == null || resourceArr.length < size)
+ {
+ resourceArr = new Resource[size * 2];
+ }
+
+ resourceArr = resources.toArray(resourceArr);
+ for (; i < size; i++)
+ {
+ resourceArr[i].getURI();
+ }
+ } while (resources.size() > size);
}
public synchronized List<CDOResourceNode> queryResources(CDOResourceFolder folder, String name, boolean exactMatch)
@@ -662,6 +706,10 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
{
registerObject(localLookupObject);
}
+ else if (id.equals(getSession().getRepositoryInfo().getRootResourceID()))
+ {
+ setRootResource((CDOResourceImpl)localLookupObject);
+ }
}
lastLookupID = id;