Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-14 11:27:03 +0000
committerEike Stepper2012-09-14 11:27:03 +0000
commit86b9f0f9b6f0ade19472328e86b899f58838fd0a (patch)
treedf4e46fb3efa1c375f1277f67d55c0f7c95dfbd9 /plugins
parent3d4c0de327cf50fad02237a0f14cef3f61b01ed4 (diff)
downloadcdo-86b9f0f9b6f0ade19472328e86b899f58838fd0a.tar.gz
cdo-86b9f0f9b6f0ade19472328e86b899f58838fd0a.tar.xz
cdo-86b9f0f9b6f0ade19472328e86b899f58838fd0a.zip
[363661] [Legacy] ETypes of EStructuralFeatures in Ecore Models are not
persisted https://bugs.eclipse.org/bugs/show_bug.cgi?id=363661
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java46
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PushTransactionTest.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java53
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java23
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java46
5 files changed, 142 insertions, 47 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
index 0a3baef061..f48ce664db 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
@@ -71,11 +71,48 @@ public final class EMFUtil
*/
public static final String CDO_ANNOTATION_KEY_PERSISTENT = "persistent";
- private static final EReference EOPERATION_EEXCEPTIONS = EcorePackage.eINSTANCE.getEOperation_EExceptions();
+ /**
+ * @since 4.2
+ */
+ public static final EReference EOPERATION_EEXCEPTIONS = EcorePackage.eINSTANCE.getEOperation_EExceptions();
- private static final EReference ETYPED_ELEMENT_ETYPE = EcorePackage.eINSTANCE.getETypedElement_EType();
+ /**
+ * @since 4.2
+ */
+ public static final EReference ETYPED_ELEMENT_ETYPE = EcorePackage.eINSTANCE.getETypedElement_EType();
- private static final EReference ECLASS_ESUPER_TYPES = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
+ /**
+ * @since 4.2
+ */
+ public static final EReference ECLASS_ESUPER_TYPES = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
+
+ /**
+ * @since 4.2
+ */
+ public static final EAttribute ECLASSIFIER_INSTANCE_CLASS_NAME = EcorePackage.eINSTANCE
+ .getEClassifier_InstanceClassName();
+
+ /**
+ * @since 4.2
+ */
+ public static final EReference EOPERATION_EGENERIC_EXCEPTIONS = EcorePackage.eINSTANCE
+ .getEOperation_EGenericExceptions();
+
+ /**
+ * @since 4.2
+ */
+ public static final EReference ETYPED_ELEMENT_EGENERIC_TYPE = EcorePackage.eINSTANCE.getETypedElement_EGenericType();
+
+ /**
+ * @since 4.2
+ */
+ public static final EReference ECLASS_EGENERIC_SUPER_TYPES = EcorePackage.eINSTANCE.getEClass_EGenericSuperTypes();
+
+ /**
+ * @since 4.2
+ */
+ public static final EAttribute ECLASSIFIER_INSTANCE_TYPE_NAME = EcorePackage.eINSTANCE
+ .getEClassifier_InstanceTypeName();
private EMFUtil()
{
@@ -290,7 +327,8 @@ public final class EMFUtil
*/
public static boolean isPersistent(EStructuralFeature feature)
{
- if (feature == ECLASS_ESUPER_TYPES || feature == ETYPED_ELEMENT_ETYPE || feature == EOPERATION_EEXCEPTIONS)
+ if (feature == ECLASS_ESUPER_TYPES || feature == ETYPED_ELEMENT_ETYPE || feature == EOPERATION_EEXCEPTIONS
+ || feature == ECLASSIFIER_INSTANCE_CLASS_NAME)
{
// http://www.eclipse.org/newsportal/article.php?id=26780&group=eclipse.tools.emf#26780
return false;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PushTransactionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PushTransactionTest.java
index a24d049e9b..174e721c7c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PushTransactionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PushTransactionTest.java
@@ -520,6 +520,27 @@ public class PushTransactionTest extends AbstractCDOTest
assertNull(supplier.getName());
}
+ public void testUnsetValueWithoutPushTX() throws Exception
+ {
+ {
+ msg("Open session & local transaction");
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath));
+ Supplier supplier = (Supplier)resource.getContents().get(0);
+ supplier.setName(null);
+ msg("Commit");
+ transaction.commit();
+ session.close();
+ }
+
+ CDOSession session = openSession();
+ CDOView view = session.openView();
+ CDOResource resource = view.getResource(getResourcePath(resourcePath));
+ Supplier supplier = (Supplier)resource.getContents().get(0);
+ assertNull(supplier.getName());
+ }
+
public void testConflictWithRemovedObject() throws Exception
{
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
index 52be0de893..3568f1e090 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
@@ -15,7 +15,6 @@ import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
@@ -190,10 +189,10 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
return;
}
- EClass eClass = revision.getEClass();
-
// This loop adjusts the opposite wrapper objects to support dangling references. See Bugzilla_251263_Test
- for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(eClass))
+ EClass eClass = revision.getEClass();
+ EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
+ for (EStructuralFeature feature : allPersistentFeatures)
{
EReference oppositeReference = ((EStructuralFeature.Internal)feature).getEOpposite();
if (oppositeReference != null && !oppositeReference.isContainment() && EMFUtil.isPersistent(oppositeReference))
@@ -242,11 +241,12 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
instanceToRevisionContainment();
EClass eClass = revision.getEClass();
- for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(eClass))
+ EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
+ for (EStructuralFeature feature : allPersistentFeatures)
{
if (feature.isUnsettable())
{
- if (!instance.eIsSet(feature))
+ if (!isSetInstanceValue(instance, feature))
{
if (feature.isMany())
{
@@ -325,11 +325,11 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
instanceToRevisionContainment();
// Handle values
- CDOPackageRegistry packageRegistry = cdoView().getSession().getPackageRegistry();
EClass eClass = revision.getEClass();
- for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(eClass))
+ EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
+ for (EStructuralFeature feature : allPersistentFeatures)
{
- instanceToRevisionFeature(feature, packageRegistry);
+ instanceToRevisionFeature(feature);
}
revision.setUnchunked();
@@ -354,15 +354,17 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
}
- protected void instanceToRevisionFeature(EStructuralFeature feature, CDOPackageRegistry packageRegistry)
+ protected void instanceToRevisionFeature(EStructuralFeature feature)
{
- Object instanceValue = getInstanceValue(instance, feature, packageRegistry);
- CDOObjectImpl.instanceToRevisionFeature(view, this, feature, instanceValue);
+ if (isSetInstanceValue(instance, feature))
+ {
+ Object instanceValue = getInstanceValue(instance, feature);
+ CDOObjectImpl.instanceToRevisionFeature(view, this, feature, instanceValue);
+ }
}
protected void revisionToInstance()
{
-
if (underConstruction)
{
// Return if revisionToInstance was called before to avoid doubled calls
@@ -392,7 +394,9 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
revisionToInstanceContainer();
- for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(revision.getEClass()))
+ EClass eClass = revision.getEClass();
+ EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
+ for (EStructuralFeature feature : allPersistentFeatures)
{
revisionToInstanceFeature(feature);
}
@@ -527,7 +531,16 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
else
{
- eSet(feature, object);
+ if (object != null)
+ {
+ eSet(feature, object);
+ }
+ else
+ {
+ // TODO Unset for features with non-null default values would not lead to null values.
+ // Probably CDORevisionData.NIL has to be used, but that impacts all IStores. Deferred ;-(
+ eUnset(feature);
+ }
}
}
else
@@ -764,13 +777,13 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
protected void resolveAllProxies()
{
- CDOPackageRegistry packageRegistry = cdoView().getSession().getPackageRegistry();
EClass eClass = revision.getEClass();
- for (EStructuralFeature feature : CDOModelUtil.getAllPersistentFeatures(eClass))
+ EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
+ for (EStructuralFeature feature : allPersistentFeatures)
{
if (feature instanceof EReference)
{
- resolveProxies(feature, packageRegistry);
+ resolveProxies(feature);
}
}
}
@@ -779,9 +792,9 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
* IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for
* EMF with fixed bug #247130. These compile errors do not affect native models!
*/
- protected void resolveProxies(EStructuralFeature feature, CDOPackageRegistry packageRegistry)
+ protected void resolveProxies(EStructuralFeature feature)
{
- Object value = getInstanceValue(instance, feature, packageRegistry);
+ Object value = getInstanceValue(instance, feature);
if (value != null)
{
if (feature.isMany())
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
index cf76b1f1b8..bd0b7819c7 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
@@ -13,7 +13,7 @@ package org.eclipse.emf.internal.cdo.object;
import org.eclipse.emf.cdo.CDOLock;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.cdo.view.CDOView;
@@ -45,6 +45,7 @@ import org.eclipse.emf.spi.cdo.InternalCDOView;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.List;
/**
* @author Eike Stepper
@@ -221,12 +222,28 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
return instance.eContainerFeatureID();
}
- public Object getInstanceValue(InternalEObject instance, EStructuralFeature feature,
- CDOPackageRegistry packageRegistry)
+ public Object getInstanceValue(InternalEObject instance, EStructuralFeature feature)
{
return instance.eGet(feature);
}
+ public boolean isSetInstanceValue(InternalEObject instance, EStructuralFeature feature)
+ {
+ // Single-valued features that need special handling
+ if (feature == EMFUtil.ETYPED_ELEMENT_EGENERIC_TYPE || feature == EMFUtil.ECLASSIFIER_INSTANCE_TYPE_NAME)
+ {
+ return getInstanceValue(instance, feature) != null;
+ }
+
+ // Many-valued features that need special handling
+ if (feature == EMFUtil.ECLASS_EGENERIC_SUPER_TYPES || feature == EMFUtil.EOPERATION_EGENERIC_EXCEPTIONS)
+ {
+ return !((List<?>)getInstanceValue(instance, feature)).isEmpty();
+ }
+
+ return instance.eIsSet(feature);
+ }
+
public void setInstanceResource(Resource.Internal resource)
{
Method method = ReflectUtil.getMethod(instance.getClass(), "eSetDirectResource", Resource.Internal.class); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index eefa97649f..ee6952f562 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -2058,33 +2058,39 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
importNewRevisions(in, revisions, idMappings);
List<InternalCDORevisionDelta> revisionDeltas = importRevisionDeltas(in);
- // Re-map temp IDs
- CDOIDMapper idMapper = new CDOIDMapper(idMappings);
- for (InternalCDORevision revision : revisions)
+ if (!idMappings.isEmpty())
{
- revision.adjustReferences(idMapper);
- }
+ // Re-map temp IDs
+ CDOIDMapper idMapper = new CDOIDMapper(idMappings);
+ for (InternalCDORevision revision : revisions)
+ {
+ revision.adjustReferences(idMapper);
+ }
- for (InternalCDORevisionDelta delta : revisionDeltas)
- {
- delta.adjustReferences(idMapper);
+ for (InternalCDORevisionDelta delta : revisionDeltas)
+ {
+ delta.adjustReferences(idMapper);
+ }
}
- // Create new objects
- List<InternalCDOObject> newObjects = new ArrayList<InternalCDOObject>();
- for (InternalCDORevision revision : revisions)
+ if (!revisions.isEmpty())
{
- InternalCDOObject object = newInstance(revision);
- registerObject(object);
- registerAttached(object, true);
+ // Create new objects
+ List<InternalCDOObject> newObjects = new ArrayList<InternalCDOObject>();
+ for (InternalCDORevision revision : revisions)
+ {
+ InternalCDOObject object = newInstance(revision);
+ registerObject(object);
+ registerAttached(object, true);
- newObjects.add(object);
- }
+ newObjects.add(object);
+ }
- // Post-load new objects (important for legacy objects!)
- for (InternalCDOObject object : newObjects)
- {
- object.cdoInternalPostLoad();
+ // Post-load new objects (important for legacy objects!)
+ for (InternalCDOObject object : newObjects)
+ {
+ object.cdoInternalPostLoad();
+ }
}
// Apply deltas

Back to the top