summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2010-10-31 23:08:35 (EDT)
committerCaspar De Groot2010-10-31 23:08:35 (EDT)
commit21d40415329b9189d85a2f371b9870f876887f7b (patch)
tree3e471ed82a099b94c448c1eece11128f3ca52f53
parent5b561dec0973ac652198ce154c48db5e7e197239 (diff)
downloadcdo-21d40415329b9189d85a2f371b9870f876887f7b.zip
cdo-21d40415329b9189d85a2f371b9870f876887f7b.tar.gz
cdo-21d40415329b9189d85a2f371b9870f876887f7b.tar.bz2
[329171] CDOResource.isLoaded returns false after adding/clearing contents of new resource
https://bugs.eclipse.org/bugs/show_bug.cgi?id=329171
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_328790_Test.java89
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java37
3 files changed, 122 insertions, 6 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 5133de6..4694af2 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
@@ -89,6 +89,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_322218_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_322754_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_323958_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324544_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_328790_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -241,6 +242,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_323958_Test.class);
testClasses.add(Bugzilla_316887_Test.class);
testClasses.add(Bugzilla_324544_Test.class);
+ testClasses.add(Bugzilla_328790_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_328790_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_328790_Test.java
new file mode 100644
index 0000000..4435f2d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_328790_Test.java
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2004 - 2010 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:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.legacy.model1.Model1Factory;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+
+/**
+ * Bug 328790 - CDOResource.isLoaded returns false after adding/clearing contents of new resource
+ *
+ * @author Caspar De Groot
+ */
+public class Bugzilla_328790_Test extends AbstractCDOTest
+{
+ public void test_newThenAdd1() throws CommitException
+ {
+ CDOSession session = openSession();
+ ResourceSet resourceSet = new ResourceSetImpl();
+ CDOTransaction tx = session.openTransaction(resourceSet);
+
+ Resource resource = resourceSet.createResource(URI.createURI("cdo://myUri"));
+ EObject object = Model1Factory.eINSTANCE.createAddress();
+ resource.getContents().add(object);
+
+ assertTrue(resource.isLoaded());
+
+ tx.commit();
+
+ assertTrue(resource.isLoaded());
+
+ tx.close();
+ session.close();
+ }
+
+ public void test_newThenAdd2() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+
+ CDOResource resource = tx.createResource("/myUri");
+ EObject object = Model1Factory.eINSTANCE.createAddress();
+ resource.getContents().add(object);
+
+ assertTrue(resource.isLoaded());
+
+ tx.commit();
+
+ assertTrue(resource.isLoaded());
+
+ tx.close();
+ session.close();
+ }
+
+ public void test_newThenClear() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+
+ CDOResource resource = tx.createResource("/myUri");
+ resource.getContents().clear();
+
+ assertTrue(resource.isLoaded());
+
+ tx.commit();
+
+ assertTrue(resource.isLoaded());
+
+ tx.close();
+ session.close();
+ }
+}
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 5363674..7571b88 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
@@ -1121,13 +1121,10 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
*/
protected void loaded()
{
- if (!isLoaded())
+ Notification notification = setLoaded(true);
+ if (notification != null)
{
- Notification notification = setLoaded(true);
- if (notification != null)
- {
- eNotify(notification);
- }
+ eNotify(notification);
}
}
@@ -1168,5 +1165,33 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
{
return true;
}
+
+ /**
+ * @since 4.0
+ */
+ @Override
+ protected void didAdd(int index, Object newObject)
+ {
+ super.didAdd(index, newObject);
+
+ if (!isExisting() && !isLoaded())
+ {
+ loaded();
+ }
+ }
+
+ /**
+ * @since 4.0
+ */
+ @Override
+ protected void didClear(int size, Object[] oldObjects)
+ {
+ super.didClear(size, oldObjects);
+
+ if (!isExisting() && !isLoaded())
+ {
+ loaded();
+ }
+ }
}
} // CDOResourceImpl