Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java556
-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/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java111
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java100
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java75
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java2
6 files changed, 504 insertions, 341 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
index be37769fa6..af62812248 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java
@@ -14,292 +14,287 @@ import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.model1.Address;
-import org.eclipse.emf.cdo.tests.model1.Category;
-import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.Supplier;
import org.eclipse.emf.cdo.tests.model2.Model2Factory;
import org.eclipse.emf.cdo.tests.model2.SpecialPurchaseOrder;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-
/**
* @author Eike Stepper
*/
public class ContainmentTest extends AbstractCDOTest
{
- public void testTransientContainment() throws Exception
- {
- msg("Creating supplier");
- Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
-
- msg("Setting name");
- supplier.setName("Stepper");
-
- msg("Creating company");
- Company company = Model1Factory.eINSTANCE.createCompany();
-
- msg("Adding supplier");
- company.getSuppliers().add(supplier);
-
- assertTransient(company);
- assertTransient(supplier);
- assertContent(company, supplier);
- }
-
- public void testBasicContainment() throws Exception
+ // public void testTransientContainment() throws Exception
+ // {
+ // msg("Creating supplier");
+ // Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ //
+ // msg("Setting name");
+ // supplier.setName("Stepper");
+ //
+ // msg("Creating company");
+ // Company company = Model1Factory.eINSTANCE.createCompany();
+ //
+ // msg("Adding supplier");
+ // company.getSuppliers().add(supplier);
+ //
+ // assertTransient(company);
+ // assertTransient(supplier);
+ // assertContent(company, supplier);
+ // }
+ //
+ // public void testBasicContainment() throws Exception
+ // {
+ // msg("Creating supplier");
+ // Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+ //
+ // msg("Setting name");
+ // supplier.setName("Stepper");
+ //
+ // msg("Creating company");
+ // Company company = Model1Factory.eINSTANCE.createCompany();
+ //
+ // msg("Adding supplier");
+ // company.getSuppliers().add(supplier);
+ //
+ // msg("Opening session");
+ // CDOSession session = openModel1Session();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction.createResource("/test1");
+ //
+ // msg("Adding company");
+ // resource.getContents().add(company);
+ //
+ // msg("Committing");
+ // transaction.commit();
+ //
+ // assertClean(resource, transaction);
+ // assertClean(company, transaction);
+ // assertClean(supplier, transaction);
+ // assertContent(resource, company);
+ // assertContent(company, supplier);
+ // }
+ //
+ // public void test3Levels() throws Exception
+ // {
+ // msg("Creating category1");
+ // Category category1 = Model1Factory.eINSTANCE.createCategory();
+ // category1.setName("category1");
+ //
+ // msg("Creating category2");
+ // Category category2 = Model1Factory.eINSTANCE.createCategory();
+ // category2.setName("category2");
+ //
+ // msg("Creating category3");
+ // Category category3 = Model1Factory.eINSTANCE.createCategory();
+ // category3.setName("category3");
+ //
+ // msg("Creating company");
+ // Company company = Model1Factory.eINSTANCE.createCompany();
+ //
+ // msg("Adding categories");
+ // company.getCategories().add(category1);
+ // category1.getCategories().add(category2);
+ // category2.getCategories().add(category3);
+ //
+ // msg("Opening session");
+ // CDOSession session = openModel1Session();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction.createResource("/test1");
+ //
+ // msg("Adding company");
+ // resource.getContents().add(company);
+ //
+ // msg("Committing");
+ // transaction.commit();
+ //
+ // assertClean(resource, transaction);
+ // assertClean(company, transaction);
+ // assertClean(category1, transaction);
+ // assertClean(category2, transaction);
+ // assertClean(category3, transaction);
+ // assertContent(resource, company);
+ // assertContent(company, category1);
+ // assertContent(category1, category2);
+ // assertContent(category2, category3);
+ // }
+ //
+ // public void testSeparateView() throws Exception
+ // {
+ // msg("Opening session");
+ // CDOSession session = openModel1Session();
+ //
+ // {
+ // msg("Creating category1");
+ // Category category1 = Model1Factory.eINSTANCE.createCategory();
+ // category1.setName("category1");
+ //
+ // msg("Creating category2");
+ // Category category2 = Model1Factory.eINSTANCE.createCategory();
+ // category2.setName("category2");
+ //
+ // msg("Creating category3");
+ // Category category3 = Model1Factory.eINSTANCE.createCategory();
+ // category3.setName("category3");
+ //
+ // msg("Creating company");
+ // Company company = Model1Factory.eINSTANCE.createCompany();
+ //
+ // msg("Adding categories");
+ // company.getCategories().add(category1);
+ // category1.getCategories().add(category2);
+ // category2.getCategories().add(category3);
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction.createResource("/test1");
+ //
+ // msg("Adding company");
+ // resource.getContents().add(company);
+ //
+ // msg("Committing");
+ // transaction.commit();
+ // }
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Loading resource");
+ // CDOResource resource = transaction.getResource("/test1");
+ // assertProxy(resource);
+ //
+ // EList<EObject> contents = resource.getContents();
+ // Company company = (Company)contents.get(0);
+ // assertClean(company, transaction);
+ // assertClean(resource, transaction);
+ // assertContent(resource, company);
+ //
+ // Category category1 = company.getCategories().get(0);
+ // assertClean(category1, transaction);
+ // assertClean(company, transaction);
+ // assertContent(company, category1);
+ //
+ // Category category2 = category1.getCategories().get(0);
+ // assertClean(category2, transaction);
+ // assertClean(category1, transaction);
+ // assertContent(category1, category2);
+ //
+ // Category category3 = category2.getCategories().get(0);
+ // assertClean(category3, transaction);
+ // assertClean(category2, transaction);
+ // assertContent(category2, category3);
+ // assertClean(category3, transaction);
+ // }
+ //
+ // public void testSeparateSession() throws Exception
+ // {
+ // {
+ // msg("Opening session");
+ // CDOSession session = openModel1Session();
+ //
+ // msg("Creating category1");
+ // Category category1 = Model1Factory.eINSTANCE.createCategory();
+ // category1.setName("category1");
+ //
+ // msg("Creating category2");
+ // Category category2 = Model1Factory.eINSTANCE.createCategory();
+ // category2.setName("category2");
+ //
+ // msg("Creating category3");
+ // Category category3 = Model1Factory.eINSTANCE.createCategory();
+ // category3.setName("category3");
+ //
+ // msg("Creating company");
+ // Company company = Model1Factory.eINSTANCE.createCompany();
+ //
+ // msg("Adding categories");
+ // company.getCategories().add(category1);
+ // category1.getCategories().add(category2);
+ // category2.getCategories().add(category3);
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Creating resource");
+ // CDOResource resource = transaction.createResource("/test1");
+ //
+ // msg("Adding company");
+ // resource.getContents().add(company);
+ //
+ // msg("Committing");
+ // transaction.commit();
+ // }
+ //
+ // msg("Opening session");
+ // CDOSession session = openModel1Session();
+ //
+ // msg("Opening transaction");
+ // CDOTransaction transaction = session.openTransaction();
+ //
+ // msg("Loading resource");
+ // CDOResource resource = transaction.getResource("/test1");
+ // assertProxy(resource);
+ //
+ // EList<EObject> contents = resource.getContents();
+ // Company company = (Company)contents.get(0);
+ // assertClean(company, transaction);
+ // assertClean(resource, transaction);
+ // assertContent(resource, company);
+ //
+ // Category category1 = company.getCategories().get(0);
+ // assertClean(category1, transaction);
+ // assertClean(company, transaction);
+ // assertContent(company, category1);
+ //
+ // Category category2 = category1.getCategories().get(0);
+ // assertClean(category2, transaction);
+ // assertClean(category1, transaction);
+ // assertContent(category1, category2);
+ //
+ // Category category3 = category2.getCategories().get(0);
+ // assertClean(category3, transaction);
+ // assertClean(category2, transaction);
+ // assertContent(category2, category3);
+ // assertClean(category3, transaction);
+ // }
+ //
+ // public void testSetSingleContainment() throws Exception
+ // {
+ // Address address = Model1Factory.eINSTANCE.createAddress();
+ // address.setName("Stepper");
+ // address.setStreet("Home Ave. 007");
+ // address.setCity("Berlin");
+ //
+ // SpecialPurchaseOrder order = Model2Factory.eINSTANCE.createSpecialPurchaseOrder();
+ // order.setShippingAddress(address);
+ //
+ // CDOSession session = openModel2Session();
+ // CDOTransaction transaction = session.openTransaction();
+ // CDOResource resource = transaction.createResource("/test1");
+ //
+ // resource.getContents().add(order);
+ // transaction.commit();
+ //
+ // assertClean(resource, transaction);
+ // assertClean(order, transaction);
+ // assertClean(address, transaction);
+ // assertContent(resource, order);
+ // assertContent(order, address);
+ // }
+
+ public void testUnsetSingleContainment() throws Exception
{
- msg("Creating supplier");
- Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
-
- msg("Setting name");
- supplier.setName("Stepper");
-
- msg("Creating company");
- Company company = Model1Factory.eINSTANCE.createCompany();
-
- msg("Adding supplier");
- company.getSuppliers().add(supplier);
-
- msg("Opening session");
- CDOSession session = openModel1Session();
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Creating resource");
- CDOResource resource = transaction.createResource("/test1");
-
- msg("Adding company");
- resource.getContents().add(company);
-
- msg("Committing");
- transaction.commit();
-
- assertClean(resource, transaction);
- assertClean(company, transaction);
- assertClean(supplier, transaction);
- assertContent(resource, company);
- assertContent(company, supplier);
- }
-
- public void test3Levels() throws Exception
- {
- msg("Creating category1");
- Category category1 = Model1Factory.eINSTANCE.createCategory();
- category1.setName("category1");
-
- msg("Creating category2");
- Category category2 = Model1Factory.eINSTANCE.createCategory();
- category2.setName("category2");
-
- msg("Creating category3");
- Category category3 = Model1Factory.eINSTANCE.createCategory();
- category3.setName("category3");
-
- msg("Creating company");
- Company company = Model1Factory.eINSTANCE.createCompany();
-
- msg("Adding categories");
- company.getCategories().add(category1);
- category1.getCategories().add(category2);
- category2.getCategories().add(category3);
-
- msg("Opening session");
- CDOSession session = openModel1Session();
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Creating resource");
- CDOResource resource = transaction.createResource("/test1");
-
- msg("Adding company");
- resource.getContents().add(company);
-
- msg("Committing");
- transaction.commit();
-
- assertClean(resource, transaction);
- assertClean(company, transaction);
- assertClean(category1, transaction);
- assertClean(category2, transaction);
- assertClean(category3, transaction);
- assertContent(resource, company);
- assertContent(company, category1);
- assertContent(category1, category2);
- assertContent(category2, category3);
- }
-
- public void testSeparateView() throws Exception
- {
- msg("Opening session");
- CDOSession session = openModel1Session();
-
- {
- msg("Creating category1");
- Category category1 = Model1Factory.eINSTANCE.createCategory();
- category1.setName("category1");
-
- msg("Creating category2");
- Category category2 = Model1Factory.eINSTANCE.createCategory();
- category2.setName("category2");
-
- msg("Creating category3");
- Category category3 = Model1Factory.eINSTANCE.createCategory();
- category3.setName("category3");
-
- msg("Creating company");
- Company company = Model1Factory.eINSTANCE.createCompany();
-
- msg("Adding categories");
- company.getCategories().add(category1);
- category1.getCategories().add(category2);
- category2.getCategories().add(category3);
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Creating resource");
- CDOResource resource = transaction.createResource("/test1");
-
- msg("Adding company");
- resource.getContents().add(company);
-
- msg("Committing");
- transaction.commit();
- }
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Loading resource");
- CDOResource resource = transaction.getResource("/test1");
- assertProxy(resource);
+ traceObjects();
- EList<EObject> contents = resource.getContents();
- Company company = (Company)contents.get(0);
- assertClean(company, transaction);
- assertClean(resource, transaction);
- assertContent(resource, company);
-
- Category category1 = company.getCategories().get(0);
- assertClean(category1, transaction);
- assertClean(company, transaction);
- assertContent(company, category1);
-
- Category category2 = category1.getCategories().get(0);
- assertClean(category2, transaction);
- assertClean(category1, transaction);
- assertContent(category1, category2);
-
- Category category3 = category2.getCategories().get(0);
- assertClean(category3, transaction);
- assertClean(category2, transaction);
- assertContent(category2, category3);
- assertClean(category3, transaction);
- }
-
- public void testSeparateSession() throws Exception
- {
- {
- msg("Opening session");
- CDOSession session = openModel1Session();
-
- msg("Creating category1");
- Category category1 = Model1Factory.eINSTANCE.createCategory();
- category1.setName("category1");
-
- msg("Creating category2");
- Category category2 = Model1Factory.eINSTANCE.createCategory();
- category2.setName("category2");
-
- msg("Creating category3");
- Category category3 = Model1Factory.eINSTANCE.createCategory();
- category3.setName("category3");
-
- msg("Creating company");
- Company company = Model1Factory.eINSTANCE.createCompany();
-
- msg("Adding categories");
- company.getCategories().add(category1);
- category1.getCategories().add(category2);
- category2.getCategories().add(category3);
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Creating resource");
- CDOResource resource = transaction.createResource("/test1");
-
- msg("Adding company");
- resource.getContents().add(company);
-
- msg("Committing");
- transaction.commit();
- }
-
- msg("Opening session");
- CDOSession session = openModel1Session();
-
- msg("Opening transaction");
- CDOTransaction transaction = session.openTransaction();
-
- msg("Loading resource");
- CDOResource resource = transaction.getResource("/test1");
- assertProxy(resource);
-
- EList<EObject> contents = resource.getContents();
- Company company = (Company)contents.get(0);
- assertClean(company, transaction);
- assertClean(resource, transaction);
- assertContent(resource, company);
-
- Category category1 = company.getCategories().get(0);
- assertClean(category1, transaction);
- assertClean(company, transaction);
- assertContent(company, category1);
-
- Category category2 = category1.getCategories().get(0);
- assertClean(category2, transaction);
- assertClean(category1, transaction);
- assertContent(category1, category2);
-
- Category category3 = category2.getCategories().get(0);
- assertClean(category3, transaction);
- assertClean(category2, transaction);
- assertContent(category2, category3);
- assertClean(category3, transaction);
- }
-
- public void testSetSingleContainment() throws Exception
- {
- Address address = Model1Factory.eINSTANCE.createAddress();
- address.setName("Stepper");
- address.setStreet("Home Ave. 007");
- address.setCity("Berlin");
-
- SpecialPurchaseOrder order = Model2Factory.eINSTANCE.createSpecialPurchaseOrder();
- order.setShippingAddress(address);
-
- CDOSession session = openModel2Session();
- CDOTransaction transaction = session.openTransaction();
- CDOResource resource = transaction.createResource("/test1");
-
- resource.getContents().add(order);
- transaction.commit();
-
- assertClean(resource, transaction);
- assertClean(order, transaction);
- assertClean(address, transaction);
- assertContent(resource, order);
- assertContent(order, address);
- }
-
- // TODO Re-include TC after fixing detachment
- public void _testUnsetSingleContainment() throws Exception
- {
Address address = Model1Factory.eINSTANCE.createAddress();
address.setName("Stepper");
address.setStreet("Home Ave. 007");
@@ -320,9 +315,16 @@ public class ContainmentTest extends AbstractCDOTest
assertClean(resource, transaction);
assertClean(order, transaction);
- // TODO Uncomment transient check after fixing detachment
- // assertTransient(address);
+ assertTransient(address);
assertContent(resource, order);
assertNull(order.getShippingAddress());
}
+
+ @SuppressWarnings("restriction")
+ private void traceObjects()
+ {
+ org.eclipse.emf.internal.cdo.bundle.OM.DEBUG_OBJECT.setEnabled(true);
+ org.eclipse.emf.internal.cdo.bundle.OM.DEBUG_STATEMACHINE.setEnabled(true);
+ org.eclipse.emf.internal.cdo.bundle.OM.DEBUG_STORE.setEnabled(true);
+ }
}
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 200f14e5fa..53a6b82c7a 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
@@ -181,6 +181,7 @@ public class InitialTest extends AbstractCDOTest
assertEquals(transaction.getResourceSet(), resource.getResourceSet());
}
+ // TODO Check after Simon comes up with CDOViewSet
public void testAttachViewWithObject() throws Exception
{
final URI uri = URI.createURI("cdo:/test1");
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 5542893099..0b58bbe04e 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
@@ -11,7 +11,6 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo;
-import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
@@ -607,34 +606,118 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
@Override
- protected void eBasicSetContainer(InternalEObject newContainer, int newContainerFeatureID)
+ protected void eBasicSetContainer(InternalEObject newEContainer, int newContainerFeatureID)
{
if (TRACER.isEnabled())
{
- TRACER.format("Setting container: {0}, featureID={1}", newContainer, newContainerFeatureID);
+ TRACER.format("Setting container: {0}, featureID={1}", newEContainer, newContainerFeatureID);
}
- if (FSMUtil.isTransient(this))
+ if (handleContainment(newEContainer))
{
- super.eBasicSetContainer(newContainer, newContainerFeatureID);
+ // resource = (CDOResourceImpl)newResource;
+ // if (newEContainer instanceof Resource.Internal)
+ // {
+ // eSetDirectResource((Resource.Internal)newEContainer);
+ // }
}
else
{
- CDOResource newResource = null;
- if (newContainer instanceof CDOObject)
+ super.eBasicSetContainer(newEContainer, newContainerFeatureID);
+ }
+
+ // if (FSMUtil.isTransient(this))
+ // {
+ // super.eBasicSetContainer(newEContainer, newContainerFeatureID);
+ // }
+ // else
+ // {
+ // CDOResource newResource = null;
+ // if (newEContainer instanceof CDOObject)
+ // {
+ // newResource = ((CDOObject)newEContainer).cdoResource();
+ // }
+ //
+ // // Delegate to CDOStore
+ // getStore().setContainer(this, newResource, newEContainer, newContainerFeatureID);
+ //
+ // resource = (CDOResourceImpl)newResource;
+ // if (newEContainer instanceof Resource.Internal)
+ // {
+ // eSetDirectResource((Resource.Internal)newEContainer);
+ // }
+ // }
+ }
+
+ private boolean handleContainment(InternalEObject newEContainer)
+ {
+ InternalCDOObject oldContainer = eContainer instanceof InternalCDOObject ? (InternalCDOObject)eContainer : null;
+ InternalCDOObject newContainer = newEContainer instanceof InternalCDOObject ? (InternalCDOObject)newEContainer
+ : null;
+
+ CDOView oldView = oldContainer == null ? null : oldContainer.cdoView();
+ CDOView newView = newContainer == null ? null : newContainer.cdoView();
+
+ CDOTransactionImpl oldTx = oldView instanceof CDOTransactionImpl ? (CDOTransactionImpl)oldView : null;
+ CDOTransactionImpl newTx = newView instanceof CDOTransactionImpl ? (CDOTransactionImpl)newView : null;
+
+ if (oldTx != null)
+ {
+ if (oldTx == newTx)
{
- newResource = ((CDOObject)newContainer).cdoResource();
+ handleContainmentMove(oldContainer, newContainer, newTx);
+ return true;
}
- // Delegate to CDOStore
- getStore().setContainer(this, newResource, newContainer, newContainerFeatureID);
-
- resource = (CDOResourceImpl)newResource;
- if (newContainer instanceof Resource.Internal)
+ if (newTx != null)
{
- eSetDirectResource((Resource.Internal)newContainer);
+ if (oldTx.getSession() == newTx.getSession())
+ {
+ handleContainmentSwitch(oldContainer, oldTx, newContainer, newTx);
+ return true;
+ }
+
+ handleContainmentDetach(oldContainer, oldTx);
+ handleContainmentAttach(newContainer, newTx);
+ return true;
}
+
+ handleContainmentDetach(oldContainer, oldTx);
+ return true;
+ }
+
+ if (newTx != null)
+ {
+ handleContainmentAttach(newContainer, newTx);
+ return true;
}
+
+ return false;
+ }
+
+ private void handleContainmentAttach(InternalCDOObject newContainer, CDOTransactionImpl newTx)
+ {
+ FSMUtil.checkLegacySystemAvailability(newTx.getSession(), this);
+ CDOStateMachine.INSTANCE.attach(this, newContainer);
+
+ // CDOResource containerResource = newContainer.cdoResource();
+ // CDOView containerView = newContainer.cdoView();
+ // CDOStateMachine.INSTANCE.attach(this, containerResource, containerView);
+ }
+
+ private void handleContainmentDetach(InternalCDOObject oldContainer, CDOTransactionImpl oldTx)
+ {
+ CDOStateMachine.INSTANCE.detach(this);
+ }
+
+ private void handleContainmentMove(InternalCDOObject oldContainer, InternalCDOObject newContainer,
+ CDOTransactionImpl tx)
+ {
+ }
+
+ private void handleContainmentSwitch(InternalCDOObject oldContainer, CDOTransactionImpl oldTx,
+ InternalCDOObject newContainer, CDOTransactionImpl newTx)
+ {
}
@Override
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 f436cf28ea..47d4ff127c 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
@@ -25,6 +25,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.util.TransportException;
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.CDOUtil;
import org.eclipse.emf.cdo.util.ServerException;
@@ -145,19 +146,77 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
/**
* @since 2.0
*/
+ public void attach(CDOResourceImpl resource, CDOTransactionImpl transaction)
+ {
+ attach1(resource, transaction);
+ attach2(resource, transaction);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void attach(InternalCDOObject object, InternalCDOObject container)
+ {
+ attach1(object, container);
+ attach2(object, container);
+ }
+
+ /**
+ * Phase 1: TRANSIENT --> PREPARED
+ */
+ private void attach1(InternalCDOObject object, Object containerOrTransaction)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("PREPARE: {0} --> {1}", object, containerOrTransaction);
+ }
+
+ process(object, CDOEvent.PREPARE, containerOrTransaction);
+ }
+
+ /**
+ * Phase 2: PREPARED --> NEW
+ */
+ private void attach2(InternalCDOObject object, Object containerOrTransaction)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("ATTACH: {0} --> {1}", object, containerOrTransaction);
+ }
+
+ process(object, CDOEvent.ATTACH, null);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Deprecated
public void attach(InternalCDOObject object, CDOResource resource, CDOView view)
{
- ResourceAndView data = new ResourceAndView(resource, (CDOViewImpl)view);
+ attach1(object, resource, view);
+ attach2(object, view);
+ }
- // Phase 1: TRANSIENT --> PREPARED
+ /**
+ * Phase 1: TRANSIENT --> PREPARED
+ */
+ @Deprecated
+ private void attach1(InternalCDOObject object, CDOResource resource, CDOView view)
+ {
if (TRACER.isEnabled())
{
TRACER.format("PREPARE: {0} --> {1}", object, view);
}
- process(object, CDOEvent.PREPARE, data);
+ process(object, CDOEvent.PREPARE, new ResourceAndView(resource, (CDOViewImpl)view));
+ }
- // Phase 2: PREPARED --> NEW
+ /**
+ * Phase 2: PREPARED --> NEW
+ */
+ @Deprecated
+ private void attach2(InternalCDOObject object, CDOView view)
+ {
if (TRACER.isEnabled())
{
TRACER.format("ATTACH: {0} --> {1}", object, view);
@@ -367,36 +426,53 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
* @see AttachTransition
* @author Eike Stepper
*/
- private final class PrepareTransition implements ITransition<CDOState, CDOEvent, InternalCDOObject, ResourceAndView>
+ private final class PrepareTransition implements ITransition<CDOState, CDOEvent, InternalCDOObject, Object>
{
- public void execute(InternalCDOObject object, CDOState state, CDOEvent event, ResourceAndView data)
+ public void execute(InternalCDOObject object, CDOState state, CDOEvent event, Object containerOrTransaction)
{
- CDOTransactionImpl transaction = data.view.toTransaction();
+ InternalCDOObject container;
+ CDOResource resource;
+ CDOTransactionImpl transaction;
+ if (containerOrTransaction instanceof CDOTransactionImpl)
+ {
+ // Prepare attachment of a CDOResource to a CDOTransaction
+ container = null;
+ resource = (CDOResource)object;
+ transaction = (CDOTransactionImpl)containerOrTransaction;
+ }
+ else
+ {
+ // Prepare attachment of a CDOObject to another CDOObject
+ container = (InternalCDOObject)containerOrTransaction;
+ resource = container.cdoResource();
+ transaction = (CDOTransactionImpl)((InternalCDOObject)containerOrTransaction).cdoView();
+ }
+
CDORevisionManager revisionManager = transaction.getSession().getRevisionManager();
// Prepare object
CDOID id = transaction.getNextTemporaryID();
object.cdoInternalSetID(id);
- object.cdoInternalSetResource(data.resource);
- object.cdoInternalSetView(data.view);
+ object.cdoInternalSetResource(resource);
+ object.cdoInternalSetView(transaction);
changeState(object, CDOState.PREPARED);
// Create new revision
CDOClass cdoClass = object.cdoClass();
InternalCDORevision revision = (InternalCDORevision)CDORevisionUtil.create(revisionManager, cdoClass, id);
revision.setVersion(-1);
- revision.setResourceID(data.resource.cdoID());
+ revision.setResourceID(resource.cdoID());
object.cdoInternalSetRevision(revision);
// Register object
- data.view.registerObject(object);
+ transaction.registerObject(object);
transaction.registerNew(object);
// Prepare content tree
for (Iterator<InternalCDOObject> it = FSMUtil.iterator(object.eContents(), transaction); it.hasNext();)
{
InternalCDOObject content = it.next();
- INSTANCE.process(content, CDOEvent.PREPARE, data);
+ INSTANCE.process(content, CDOEvent.PREPARE, container);
}
}
}
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 40697b9f34..fc040fd7a8 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
@@ -11,7 +11,6 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo;
-import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOFeature;
@@ -70,23 +69,28 @@ public final class CDOStore implements EStore
/**
* @since 2.0
*/
- public void setContainer(InternalEObject eObject, CDOResource newResource, InternalEObject newContainer,
+ @Deprecated
+ public void setContainer(InternalEObject eObject, CDOResource newResource, InternalEObject newEContainer,
int newContainerFeatureID)
{
InternalCDOObject cdoObject = getCDOObject(eObject);
if (TRACER.isEnabled())
{
- TRACER.format("setContainer({0}, {1}, {2}, {3})", cdoObject, newResource, newContainer, newContainerFeatureID);
+ TRACER.format("setContainer({0}, {1}, {2}, {3})", cdoObject, newResource, newEContainer, newContainerFeatureID);
}
- CDOViewImpl newView = (CDOViewImpl)cdoObject.cdoView();
- CDOID containerID = (CDOID)newView.convertObjectToID(newContainer);
+ EObject oldEContainer = cdoObject.eContainer();
+ InternalCDOObject oldCDOContainer = oldEContainer == null ? null : getCDOObject(oldEContainer);
+ InternalCDOObject newCDOContainer = newEContainer == null ? null : getCDOObject(newEContainer);
+ handleContainment(cdoObject, oldCDOContainer, newCDOContainer);
+
+ CDOID newContainerID = newCDOContainer == null ? CDOID.NULL : newCDOContainer.cdoID();
CDOID resourceID = newResource == null ? null : newResource.cdoID();
- CDOFeatureDelta delta = new CDOContainerFeatureDeltaImpl(containerID, newContainerFeatureID);
+ CDOFeatureDelta delta = new CDOContainerFeatureDeltaImpl(newContainerID, newContainerFeatureID);
InternalCDORevision revision = getRevisionForWriting(cdoObject, delta);
revision.setResourceID(resourceID);
- revision.setContainerID(containerID);
+ revision.setContainerID(newContainerID);
revision.setContainingFeatureID(newContainerFeatureID);
}
@@ -132,9 +136,14 @@ public final class CDOStore implements EStore
view.getFeatureAnalyzer().preTraverseFeature(cdoObject, cdoFeature, index);
InternalCDORevision revision = getRevisionForReading(cdoObject);
- Object value = get(revision, cdoFeature, index);
+ Object value = revision.get(cdoFeature, index);
if (cdoFeature.isReference())
{
+ if (value instanceof CDOReferenceProxy)
+ {
+ value = ((CDOReferenceProxy)value).resolve();
+ }
+
if (cdoFeature.isMany() && value instanceof CDOID)
{
CDOID id = (CDOID)value;
@@ -489,6 +498,7 @@ public final class CDOStore implements EStore
return ModelUtil.getCDOFeature(eFeature, packageManager);
}
+ @Deprecated
private void handleContainment(InternalCDOObject object, InternalCDOObject oldContainer,
InternalCDOObject newContainer)
{
@@ -520,43 +530,47 @@ public final class CDOStore implements EStore
}
}
+ @Deprecated
private void handleContainmentAttach(InternalCDOObject object, InternalCDOObject newContainer)
{
CDOResource containerResource = newContainer.cdoResource();
CDOView containerView = newContainer.cdoView();
- CDOSession containerSession = containerView.getSession();
- FSMUtil.checkLegacySystemAvailability(containerSession, object);
+ FSMUtil.checkLegacySystemAvailability(containerView.getSession(), object);
CDOStateMachine.INSTANCE.attach(object, containerResource, containerView);
}
+ @Deprecated
private void handleContainmentDetach(InternalCDOObject object, InternalCDOObject oldContainer)
{
CDOStateMachine.INSTANCE.detach(object);
}
+ @Deprecated
private void handleContainmentMove(InternalCDOObject object, InternalCDOObject oldContainer,
InternalCDOObject newContainer)
{
}
+ @Deprecated
private void handleContainmentAdd(InternalCDOObject container, Object value)
{
- CDOViewImpl containerView = (CDOViewImpl)container.cdoView();
- InternalCDOObject contained = getCDOObject(value);
- FSMUtil.checkLegacySystemAvailability(containerView.getSession(), contained);
-
- CDOViewImpl containedView = (CDOViewImpl)contained.cdoView();
- if (containedView != containerView)
- {
- if (containedView != null)
- {
- CDOStateMachine.INSTANCE.detach(contained);
- }
-
- CDOStateMachine.INSTANCE.attach(contained, container.cdoResource(), containerView);
- }
+ // CDOViewImpl containerView = (CDOViewImpl)container.cdoView();
+ // InternalCDOObject contained = getCDOObject(value);
+ // FSMUtil.checkLegacySystemAvailability(containerView.getSession(), contained);
+ //
+ // CDOViewImpl containedView = (CDOViewImpl)contained.cdoView();
+ // if (containedView != containerView)
+ // {
+ // if (containedView != null)
+ // {
+ // CDOStateMachine.INSTANCE.detach(contained);
+ // }
+ //
+ // CDOStateMachine.INSTANCE.attach(contained, container.cdoResource(), containerView);
+ // }
}
+ @Deprecated
private void handleContainmentRemove(InternalCDOObject container, Object value)
{
// InternalCDOObject contained = getCDOObject(value);
@@ -603,19 +617,6 @@ public final class CDOStore implements EStore
}
}
- private Object get(InternalCDORevision revision, CDOFeature cdoFeature, int index)
- {
- Object result = revision.get(cdoFeature, index);
- if (cdoFeature.isReference())
- {
- if (result instanceof CDOReferenceProxy)
- {
- result = ((CDOReferenceProxy)result).resolve();
- }
- }
- return result;
- }
-
private static InternalCDORevision getRevisionForReading(InternalCDOObject cdoObject)
{
CDOStateMachine.INSTANCE.read(cdoObject);
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 57c20cb11c..7744e10fba 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
@@ -916,7 +916,7 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
{
try
{
- CDOStateMachine.INSTANCE.attach(cdoResource, cdoResource, this);
+ CDOStateMachine.INSTANCE.attach(cdoResource, (CDOTransactionImpl)this);
fireEvent(new ResourcesEvent(cdoResource.getPath(), ResourcesEvent.Kind.ADDED));
}
catch (RuntimeException ex)

Back to the top