summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-01-27 07:56:14 (EST)
committerEike Stepper2008-01-27 07:56:14 (EST)
commit8b3a505531ad6d24be837d132ee50d7d94296195 (patch)
tree9eb4495780053e8e10e183979c2bd580409acf7f
parentbf34e68190a15c2068ee5982cb8bb5f05b2c9e9c (diff)
downloadcdo-8b3a505531ad6d24be837d132ee50d7d94296195.zip
cdo-8b3a505531ad6d24be837d132ee50d7d94296195.tar.gz
cdo-8b3a505531ad6d24be837d132ee50d7d94296195.tar.bz2
[204890] Implement detach
https://bugs.eclipse.org/bugs/show_bug.cgi?id=204890
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java523
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java38
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java95
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java2
9 files changed, 591 insertions, 90 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 045069b..833fbff 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
@@ -83,7 +83,7 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
return session;
}
- protected void assertTransient(CDOObject object)
+ protected static void assertTransient(CDOObject object)
{
assertTrue(FSMUtil.isTransient(object));
assertEquals(null, object.cdoID());
@@ -92,7 +92,7 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
assertEquals(object.eResource(), object.cdoResource());
}
- protected void assertNotTransient(CDOObject object)
+ protected static void assertNotTransient(CDOObject object)
{
assertFalse(FSMUtil.isTransient(object));
assertNotNull(object.cdoID());
@@ -103,25 +103,25 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
assertEquals(object.eResource(), object.cdoResource());
}
- protected void assertNew(CDOObject object)
+ protected static void assertNew(CDOObject object)
{
assertNotTransient(object);
assertEquals(CDOState.NEW, object.cdoState());
}
- protected void assertDirty(CDOObject object)
+ protected static void assertDirty(CDOObject object)
{
assertNotTransient(object);
assertEquals(CDOState.DIRTY, object.cdoState());
}
- protected void assertClean(CDOObject object)
+ protected static void assertClean(CDOObject object)
{
assertNotTransient(object);
assertEquals(CDOState.CLEAN, object.cdoState());
}
- protected void assertProxy(CDOObject object)
+ protected static void assertProxy(CDOObject object)
{
assertFalse(FSMUtil.isTransient(object));
assertNotNull(object.cdoID());
@@ -132,7 +132,7 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
assertEquals(CDOState.PROXY, object.cdoState());
}
- protected void assertContent(CDOObject container, CDOObject contained)
+ protected static void assertContent(CDOObject container, CDOObject contained)
{
assertEquals(container.eResource(), contained.eResource());
assertEquals(container.cdoResource(), contained.cdoResource());
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 f13aaff..175bc1d 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
@@ -144,7 +144,6 @@ public class InitialTest extends AbstractCDOTest
ResourceSet expected = transaction.getResourceSet();
ResourceSet actual = resource.getResourceSet();
assertEquals(expected, actual);
-
}
public void testAttachView() 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
new file mode 100644
index 0000000..88665fc
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/StateMachineTest.java
@@ -0,0 +1,523 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper() throws Exception{} Germany.
+ * 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() throws Exception{} and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+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.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Product;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+
+import org.eclipse.emf.internal.cdo.CDOStateMachine;
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
+
+import org.eclipse.emf.common.util.URI;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @author Eike Stepper
+ */
+public class StateMachineTest extends AbstractCDOTest
+{
+ private static final long TIMESTAMP = 12345678L;
+
+ public void test__TRANSIENT__ATTACH() throws Exception
+ {
+ // Attach resource
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/test1");
+ assertNew(resource);
+ assertEquals(URI.createURI("cdo:/test1"), resource.getURI());
+ assertEquals(transaction.getResourceSet(), resource.getResourceSet());
+
+ // Attach single object
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ resource.getContents().add(supplier);
+ assertNew(supplier);
+ assertEquals(transaction, supplier.cdoView());
+ assertEquals(resource, supplier.cdoResource());
+ assertEquals(resource, supplier.eResource());
+ assertEquals(null, supplier.eContainer());
+
+ // Attach object tree
+ Category cat1 = Model1Factory.eINSTANCE.createCategory();
+ cat1.setName("CAT1");
+ Category cat2 = Model1Factory.eINSTANCE.createCategory();
+ cat2.setName("CAT2");
+ cat1.getCategories().add(cat2);
+ Product p1 = Model1Factory.eINSTANCE.createProduct();
+ p1.setName("P1");
+ cat1.getProducts().add(p1);
+ Product p2 = Model1Factory.eINSTANCE.createProduct();
+ p2.setName("P2");
+ cat1.getProducts().add(p2);
+ Product p3 = Model1Factory.eINSTANCE.createProduct();
+ p3.setName("P3");
+ cat2.getProducts().add(p3);
+ assertTransient(cat1);
+ assertTransient(cat2);
+ assertTransient(p1);
+ assertTransient(p2);
+ assertTransient(p3);
+ resource.getContents().add(cat1);
+ assertNew(cat1);
+ assertNew(cat2);
+ assertNew(p1);
+ assertNew(p2);
+ assertNew(p3);
+ }
+
+ public void test__TRANSIENT__DETACH() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ try
+ {
+ CDOStateMachine.INSTANCE.detach((InternalCDOObject)supplier);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__TRANSIENT__READ() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ CDOStateMachine.INSTANCE.read((InternalCDOObject)supplier);
+ }
+
+ public void test__TRANSIENT__WRITE() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ CDOStateMachine.INSTANCE.write((InternalCDOObject)supplier);
+ }
+
+ public void test__TRANSIENT__INVALIDATE() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ try
+ {
+ CDOStateMachine.INSTANCE.invalidate((InternalCDOObject)supplier, TIMESTAMP);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__TRANSIENT__RELOAD() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ CDOStateMachine.INSTANCE.reload((InternalCDOObject)supplier);
+ assertTransient(supplier);
+ }
+
+ public void test__TRANSIENT__COMMIT() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+ try
+ {
+ CDOStateMachine.INSTANCE.commit((InternalCDOObject)supplier, new CommitTransactionResult(12345678L));
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__TRANSIENT__ROLLBACK() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ assertTransient(supplier);
+
+ // Rollback locally
+ try
+ {
+ CDOStateMachine.INSTANCE.rollback((InternalCDOObject)supplier, false);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+
+ // Rollback remotely
+ try
+ {
+ CDOStateMachine.INSTANCE.rollback((InternalCDOObject)supplier, true);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__ATTACH() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ attach(supplier);
+ fail("Expected NullPointerException due to revision==null");
+ }
+ catch (NullPointerException ex)
+ {
+ }
+ }
+
+ public void test__PREPARED_ATTACH__DETACH() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ CDOStateMachine.INSTANCE.detach((InternalCDOObject)supplier);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__READ() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ CDOStateMachine.INSTANCE.read((InternalCDOObject)supplier);
+ assertEquals(CDOState.PREPARED_ATTACH, supplier.cdoState());
+ }
+
+ public void test__PREPARED_ATTACH__WRITE() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ CDOStateMachine.INSTANCE.write((InternalCDOObject)supplier);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__INVALIDATE() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ CDOStateMachine.INSTANCE.invalidate((InternalCDOObject)supplier, TIMESTAMP);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__RELOAD() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ reload(supplier);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__COMMIT() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ CDOStateMachine.INSTANCE.commit((InternalCDOObject)supplier, new CommitTransactionResult(TIMESTAMP));
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__PREPARED_ATTACH__ROLLBACK() throws Exception
+ {
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ supplier.setName("Stepper");
+ ((InternalCDOObject)supplier).cdoInternalSetState(CDOState.PREPARED_ATTACH);
+ try
+ {
+ CDOStateMachine.INSTANCE.rollback((InternalCDOObject)supplier, false);
+ fail("Expected IllegalStateException");
+ }
+ catch (IllegalStateException ex)
+ {
+ assertFailure(ex);
+ }
+ }
+
+ public void test__NEW__ATTACH() throws Exception
+ {
+ }
+
+ public void test__NEW__DETACH() throws Exception
+ {
+ }
+
+ public void test__NEW__READ() throws Exception
+ {
+ }
+
+ public void test__NEW__WRITE() throws Exception
+ {
+ }
+
+ public void test__NEW__INVALIDATE() throws Exception
+ {
+ }
+
+ public void test__NEW__RELOAD() throws Exception
+ {
+ }
+
+ public void test__NEW__COMMIT() throws Exception
+ {
+ }
+
+ public void test__NEW__ROLLBACK() throws Exception
+ {
+ }
+
+ public void test__CLEAN__ATTACH() throws Exception
+ {
+ }
+
+ public void test__CLEAN__DETACH() throws Exception
+ {
+ }
+
+ public void test__CLEAN__READ() throws Exception
+ {
+ }
+
+ public void test__CLEAN__WRITE() throws Exception
+ {
+ }
+
+ public void test__CLEAN__INVALIDATE() throws Exception
+ {
+ }
+
+ public void test__CLEAN__RELOAD() throws Exception
+ {
+ }
+
+ public void test__CLEAN__COMMIT() throws Exception
+ {
+ }
+
+ public void test__CLEAN__ROLLBACK() throws Exception
+ {
+ }
+
+ public void test__DIRTY__ATTACH() throws Exception
+ {
+ }
+
+ public void test__DIRTY__DETACH() throws Exception
+ {
+ }
+
+ public void test__DIRTY__READ() throws Exception
+ {
+ }
+
+ public void test__DIRTY__WRITE() throws Exception
+ {
+ }
+
+ public void test__DIRTY__INVALIDATE() throws Exception
+ {
+ }
+
+ public void test__DIRTY__RELOAD() throws Exception
+ {
+ }
+
+ public void test__DIRTY__COMMIT() throws Exception
+ {
+ }
+
+ public void test__DIRTY__ROLLBACK() throws Exception
+ {
+ }
+
+ public void test__PROXY__ATTACH() throws Exception
+ {
+ }
+
+ public void test__PROXY__DETACH() throws Exception
+ {
+ }
+
+ public void test__PROXY__READ() throws Exception
+ {
+ }
+
+ public void test__PROXY__WRITE() throws Exception
+ {
+ }
+
+ public void test__PROXY__INVALIDATE() throws Exception
+ {
+ }
+
+ public void test__PROXY__RELOAD() throws Exception
+ {
+ }
+
+ public void test__PROXY__COMMIT() throws Exception
+ {
+ }
+
+ public void test__PROXY__ROLLBACK() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__ATTACH() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__DETACH() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__READ() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__WRITE() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__INVALIDATE() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__RELOAD() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__COMMIT() throws Exception
+ {
+ }
+
+ public void test__CONFLICT__ROLLBACK() throws Exception
+ {
+ }
+
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ private static void assertFailure(IllegalStateException ex)
+ {
+ ex.printStackTrace();
+ assertTrue("Expected FAIL transition", ex.getMessage().startsWith("Failing event "));
+ }
+
+ private static void attach(CDOObject object) throws Exception
+ {
+ invokeMethod(object, "testAttach");
+ }
+
+ private static void reload(CDOObject object) throws Exception
+ {
+ invokeMethod(object, "testReload");
+ }
+
+ private static void invokeMethod(CDOObject object, String methodName) throws Exception
+ {
+ Method method = null;
+
+ try
+ {
+ method = CDOStateMachine.class.getDeclaredMethod(methodName, new Class[] { InternalCDOObject.class });
+ method.setAccessible(true);
+ method.invoke(CDOStateMachine.INSTANCE, object);
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (InvocationTargetException ex)
+ {
+ throw (Exception)ex.getTargetException();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Reflection problem: " + ex.getMessage());
+ }
+ finally
+ {
+ if (method != null)
+ {
+ method.setAccessible(false);
+ }
+ }
+ }
+}
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 36c35ee..915c7c2 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
@@ -424,7 +424,7 @@ public class CDOResourceImpl extends CDOObjectImpl implements CDOResource
public void detached(EObject object)
{
InternalCDOObject legacy = getLegacyWrapper(object);
- CDOStateMachine.INSTANCE.detach(legacy, this, view);
+ CDOStateMachine.INSTANCE.detach(legacy);
}
/**
@@ -554,7 +554,7 @@ public class CDOResourceImpl extends CDOObjectImpl implements CDOResource
* @author Eike Stepper
*/
protected class TransientContents<E extends Object & EObject> extends NotifyingListImpl<E> implements
- InternalEList<E>
+ InternalEList<E>
{
private static final long serialVersionUID = 1L;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
index fde647e..061ee9d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
@@ -142,7 +142,7 @@ public class CDOCallbackImpl extends CDOLegacyImpl implements CDOCallback
if (((InternalEObject)instance).eDeliver())
{
InternalCDOObject object = FSMUtil.adapt(instance, view);
- CDOStateMachine.INSTANCE.detach(object, cdoResource(), view);
+ CDOStateMachine.INSTANCE.detach(object);
}
}
}
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 6fe9675..d6da040 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
@@ -32,7 +32,6 @@ import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EStoreEObjectImpl;
@@ -210,7 +209,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- finalizeRevisionFeature(view, revision, i, setting, eFeature, eSettings);
+ postAttachFeature(view, revision, i, setting, eFeature, eSettings);
}
}
}
@@ -486,41 +485,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return resource != null ? (CDOViewImpl)cdoObject.cdoResource().cdoView() : null;
}
- @Deprecated
- static void finalizeCDORevision(InternalCDOObject cdoObject, EObject eContainer, int eContainerFeatureID,
- Object[] eSettings)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Finalizing revision for {0}", cdoObject);
- }
-
- CDOViewImpl view = (CDOViewImpl)cdoObject.cdoView();
- InternalCDORevision revision = (InternalCDORevision)cdoObject.cdoRevision();
- revision.setVersion(1);
- revision.setContainerID(eContainer == null ? CDOID.NULL : ((CDOObjectImpl)eContainer).cdoID());
- revision.setContainingFeatureID(eContainerFeatureID);
-
- if (eSettings != null)
- {
- EClass eClass = cdoObject.eClass();
- for (int i = 0; i < eClass.getFeatureCount(); i++)
- {
- Object setting = eSettings[i];
- if (setting != null)
- {
- EStructuralFeature eFeature = cdoObject.cdoInternalDynamicFeature(i);
- if (!eFeature.isTransient())
- {
- finalizeRevisionFeature(view, revision, i, setting, eFeature, eSettings);
- }
- }
- }
- }
- }
-
@SuppressWarnings("unchecked")
- private static void finalizeRevisionFeature(CDOViewImpl view, InternalCDORevision revision, int i, Object setting,
+ private static void postAttachFeature(CDOViewImpl view, InternalCDORevision revision, int i, Object setting,
EStructuralFeature eFeature, Object[] eSettings)
{
CDOFeatureImpl cdoFeature = ModelUtil.getCDOFeature(eFeature, view.getSession().getPackageManager());
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
index 23ae830..2ee44c7 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
@@ -64,7 +64,7 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
{
super(CDOState.class, CDOEvent.class);
- init(CDOState.TRANSIENT, CDOEvent.ATTACH, new AttachTransition());
+ init(CDOState.TRANSIENT, CDOEvent.ATTACH, new PrepareAttachTransition());
init(CDOState.TRANSIENT, CDOEvent.DETACH, FAIL);
init(CDOState.TRANSIENT, CDOEvent.READ, IGNORE);
init(CDOState.TRANSIENT, CDOEvent.WRITE, IGNORE);
@@ -72,9 +72,8 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.TRANSIENT, CDOEvent.RELOAD, IGNORE);
init(CDOState.TRANSIENT, CDOEvent.COMMIT, FAIL);
init(CDOState.TRANSIENT, CDOEvent.ROLLBACK, FAIL);
- init(CDOState.TRANSIENT, CDOEvent.FINALIZE_ATTACH, FAIL);
- init(CDOState.PREPARED_ATTACH, CDOEvent.ATTACH, FAIL);
+ init(CDOState.PREPARED_ATTACH, CDOEvent.ATTACH, new FinalizeAttachTransition());
init(CDOState.PREPARED_ATTACH, CDOEvent.DETACH, FAIL);
init(CDOState.PREPARED_ATTACH, CDOEvent.READ, IGNORE);
init(CDOState.PREPARED_ATTACH, CDOEvent.WRITE, FAIL);
@@ -82,7 +81,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.PREPARED_ATTACH, CDOEvent.RELOAD, FAIL);
init(CDOState.PREPARED_ATTACH, CDOEvent.COMMIT, FAIL);
init(CDOState.PREPARED_ATTACH, CDOEvent.ROLLBACK, FAIL);
- init(CDOState.PREPARED_ATTACH, CDOEvent.FINALIZE_ATTACH, new FinalizeAttachTransition());
init(CDOState.NEW, CDOEvent.ATTACH, FAIL);
init(CDOState.NEW, CDOEvent.DETACH, FAIL);
@@ -92,7 +90,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.NEW, CDOEvent.RELOAD, FAIL);
init(CDOState.NEW, CDOEvent.COMMIT, new CommitTransition());
init(CDOState.NEW, CDOEvent.ROLLBACK, FAIL);
- init(CDOState.NEW, CDOEvent.FINALIZE_ATTACH, FAIL);
init(CDOState.CLEAN, CDOEvent.ATTACH, FAIL);
init(CDOState.CLEAN, CDOEvent.DETACH, FAIL);
@@ -102,7 +99,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.CLEAN, CDOEvent.RELOAD, new ReloadTransition());
init(CDOState.CLEAN, CDOEvent.COMMIT, FAIL);
init(CDOState.CLEAN, CDOEvent.ROLLBACK, FAIL);
- init(CDOState.CLEAN, CDOEvent.FINALIZE_ATTACH, FAIL);
init(CDOState.DIRTY, CDOEvent.ATTACH, FAIL);
init(CDOState.DIRTY, CDOEvent.DETACH, FAIL);
@@ -112,7 +108,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.DIRTY, CDOEvent.RELOAD, new ReloadTransition());
init(CDOState.DIRTY, CDOEvent.COMMIT, new CommitTransition());
init(CDOState.DIRTY, CDOEvent.ROLLBACK, new RollbackTransition());
- init(CDOState.DIRTY, CDOEvent.FINALIZE_ATTACH, FAIL);
init(CDOState.PROXY, CDOEvent.ATTACH, new LoadResourceTransition());
init(CDOState.PROXY, CDOEvent.DETACH, new DetachTransition());
@@ -122,7 +117,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.PROXY, CDOEvent.RELOAD, new ReloadTransition());
init(CDOState.PROXY, CDOEvent.COMMIT, FAIL);
init(CDOState.PROXY, CDOEvent.ROLLBACK, FAIL);
- init(CDOState.PROXY, CDOEvent.FINALIZE_ATTACH, IGNORE);
init(CDOState.CONFLICT, CDOEvent.ATTACH, IGNORE);
init(CDOState.CONFLICT, CDOEvent.DETACH, IGNORE);
@@ -132,7 +126,6 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.CONFLICT, CDOEvent.RELOAD, FAIL);
init(CDOState.CONFLICT, CDOEvent.COMMIT, IGNORE);
init(CDOState.CONFLICT, CDOEvent.ROLLBACK, new RollbackTransition());
- init(CDOState.CONFLICT, CDOEvent.FINALIZE_ATTACH, IGNORE);
}
public void attach(InternalCDOObject object, CDOResource resource, CDOViewImpl view)
@@ -155,13 +148,17 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
TRACER.format("FINALIZE_ATTACH: {0} --> {1}", object, view);
}
- process(object, CDOEvent.FINALIZE_ATTACH, data);
+ process(object, CDOEvent.ATTACH, null);
}
- public void detach(InternalCDOObject object, CDOResource resource, CDOViewImpl view)
+ public void detach(InternalCDOObject object)
{
- // TODO Implement method CDOStateMachine.detach()
- throw new UnsupportedOperationException("Not yet implemented");
+ if (TRACER.isEnabled())
+ {
+ trace(object, CDOEvent.DETACH);
+ }
+
+ process(object, CDOEvent.DETACH, null);
}
public void read(InternalCDOObject object)
@@ -191,14 +188,21 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
public void reload(InternalCDOObject... objects)
{
+ CDOView view = null;
Map<CDOID, InternalCDOObject> ids = new HashMap<CDOID, InternalCDOObject>();
List<InternalCDORevision> revisions = new ArrayList<InternalCDORevision>();
List<InternalCDORevision> revised = new ArrayList<InternalCDORevision>();
for (InternalCDOObject object : objects)
{
CDOState state = object.cdoState();
- if (state != CDOState.NEW && state != CDOState.CONFLICT)
+ if (state != CDOState.TRANSIENT && state != CDOState.PREPARED_ATTACH && state != CDOState.NEW
+ && state != CDOState.CONFLICT)
{
+ if (view == null)
+ {
+ view = object.cdoView();
+ }
+
InternalCDORevision revision = (InternalCDORevision)object.cdoRevision();
if (revision.isCurrent())
{
@@ -213,28 +217,30 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
- try
- {
- CDOView view = objects[0].cdoView();
- IChannel channel = view.getSession().getChannel();
- VerifyRevisionRequest request = new VerifyRevisionRequest(channel, revisions);
- revisions = request.send();
- }
- catch (Exception ex)
- {
- throw new TransportException(ex);
- }
-
- revisions.addAll(revised);
- for (InternalCDORevision revision : revisions)
+ if (view != null)
{
- InternalCDOObject object = ids.get(revision.getID());
- if (TRACER.isEnabled())
+ try
+ {
+ IChannel channel = view.getSession().getChannel();
+ VerifyRevisionRequest request = new VerifyRevisionRequest(channel, revisions);
+ revisions = request.send();
+ }
+ catch (Exception ex)
{
- trace(object, CDOEvent.RELOAD);
+ throw new TransportException(ex);
}
- process(object, CDOEvent.RELOAD, null);
+ revisions.addAll(revised);
+ for (InternalCDORevision revision : revisions)
+ {
+ InternalCDOObject object = ids.get(revision.getID());
+ if (TRACER.isEnabled())
+ {
+ trace(object, CDOEvent.RELOAD);
+ }
+
+ process(object, CDOEvent.RELOAD, null);
+ }
}
}
@@ -295,6 +301,18 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
+ @SuppressWarnings("unused")
+ private void testAttach(InternalCDOObject object)
+ {
+ process(object, CDOEvent.ATTACH, null);
+ }
+
+ @SuppressWarnings("unused")
+ private void testReload(InternalCDOObject object)
+ {
+ process(object, CDOEvent.RELOAD, null);
+ }
+
/**
* @author Eike Stepper
*/
@@ -314,7 +332,8 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
/**
* @author Eike Stepper
*/
- private final class AttachTransition implements ITransition<CDOState, CDOEvent, InternalCDOObject, ResourceAndView>
+ private final class PrepareAttachTransition implements
+ ITransition<CDOState, CDOEvent, InternalCDOObject, ResourceAndView>
{
public void execute(InternalCDOObject object, CDOState state, CDOEvent event, ResourceAndView data)
{
@@ -363,7 +382,7 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
for (Iterator<?> it = FSMUtil.iterator(object.eContents(), transaction); it.hasNext();)
{
InternalCDOObject content = (InternalCDOObject)it.next();
- INSTANCE.process(content, CDOEvent.FINALIZE_ATTACH, null);
+ INSTANCE.process(content, CDOEvent.ATTACH, null);
}
}
}
@@ -603,11 +622,5 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
*/
enum CDOEvent
{
- ATTACH, DETACH, READ, WRITE, INVALIDATE, RELOAD, COMMIT, ROLLBACK,
-
- /**
- * An internal event that is only triggered by the state machine itself to express the two phase nature of attaching
- * an object tree to a view in {@link CDOStateMachine#attach(InternalCDOObject, CDOResource, CDOViewImpl) attach()}.
- */
- FINALIZE_ATTACH
+ ATTACH, DETACH, READ, WRITE, INVALIDATE, RELOAD, COMMIT, ROLLBACK
}
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 b773c69..60181c8 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
@@ -539,7 +539,7 @@ public final class CDOStore implements EStore
{
if (containedView != null)
{
- CDOStateMachine.INSTANCE.detach(contained, contained.cdoResource(), containedView);
+ CDOStateMachine.INSTANCE.detach(contained);
}
CDOStateMachine.INSTANCE.attach(contained, container.cdoResource(), containerView);
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 92f83a0..462e883 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
@@ -775,7 +775,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
private void notifyRemove(CDOResourceImpl cdoResource)
{
- CDOStateMachine.INSTANCE.detach(cdoResource, cdoResource, this);
+ CDOStateMachine.INSTANCE.detach(cdoResource);
fireEvent(new ResourcesEvent(cdoResource.getPath(), ResourcesEvent.Kind.REMOVED));
}