Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2009-05-07 18:48:30 +0000
committerEike Stepper2009-05-07 18:48:30 +0000
commitde325f625c1d8a8a074dcb1ca4fa80d9c86bf271 (patch)
treeb22c90f914416559383824935ac723a824d6b16f
parent00a2ce617eaae732d37fd06c4bb44090d706879a (diff)
downloadcdo-de325f625c1d8a8a074dcb1ca4fa80d9c86bf271.tar.gz
cdo-de325f625c1d8a8a074dcb1ca4fa80d9c86bf271.tar.xz
cdo-de325f625c1d8a8a074dcb1ca4fa80d9c86bf271.zip
[247226] Transparently support legacy models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247226
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java99
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java119
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java18
3 files changed, 117 insertions, 119 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
index 5a2454e68b..43771d9943 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java
@@ -41,7 +41,6 @@ import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EAttributeImpl;
import org.eclipse.emf.ecore.impl.EClassImpl;
import org.eclipse.emf.ecore.impl.EDataTypeImpl;
-import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.impl.EReferenceImpl;
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl;
import org.eclipse.emf.ecore.impl.ETypedElementImpl;
@@ -54,7 +53,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.List;
/**
* @author Eike Stepper
@@ -68,12 +66,6 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_OBJECT, CDOLegacyWrapper.class);
- private static final Method eSetDirectResourceMethod = ReflectUtil.getMethod(EObjectImpl.class, "eSetDirectResource", //$NON-NLS-1$
- Resource.Internal.class);
-
- private static final Method eBasicSetContainerMethod = ReflectUtil.getMethod(EObjectImpl.class, "eBasicSetContainer", //$NON-NLS-1$
- InternalEObject.class, int.class);
-
protected CDOState state;
protected InternalCDORevision revision;
@@ -328,47 +320,47 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
setInstanceContainer(container, revision.getContainingFeatureID());
}
- @SuppressWarnings("unchecked")
protected void revisionToInstanceFeature(EStructuralFeature feature, CDOPackageRegistry packageRegistry)
{
- Object value = revision.getValue(feature);
- if (feature.isMany())
- {
- InternalEList<Object> instanceList = (InternalEList<Object>)getInstanceValue(instance, feature, packageRegistry);
- if (instanceList != null)
- {
- clearEList(instanceList);
- if (value != null)
- {
- List<?> revisionList = (List<?>)value;
- if (feature instanceof EReference)
- {
- for (Object element : revisionList)
- {
- element = getEObjectFromPotentialID(view, feature, element);
- instanceList.basicAdd(element, null);
- }
- }
- else
- {
- // TODO Is this only for multi-valued attributes??
- for (Object element : revisionList)
- {
- instanceList.basicAdd(element, null);
- }
- }
- }
- }
- }
- else
- {
- if (feature instanceof EReference)
- {
- value = getEObjectFromPotentialID(view, feature, value);
- }
-
- setInstanceValue(instance, feature, value);
- }
+ CDOObjectImpl.revisionToInstanceFeature(this, revision, feature);
+ // Object value = revision.getValue(feature);
+ // if (feature.isMany())
+ // {
+ // InternalEList<Object> instanceList = (InternalEList<Object>)getInstanceValue(instance, feature, packageRegistry);
+ // if (instanceList != null)
+ // {
+ // clearEList(instanceList);
+ // if (value != null)
+ // {
+ // List<?> revisionList = (List<?>)value;
+ // if (feature instanceof EReference)
+ // {
+ // for (Object element : revisionList)
+ // {
+ // element = getEObjectFromPotentialID(view, feature, element);
+ // instanceList.basicAdd(element, null);
+ // }
+ // }
+ // else
+ // {
+ // // TODO Is this only for multi-valued attributes??
+ // for (Object element : revisionList)
+ // {
+ // instanceList.basicAdd(element, null);
+ // }
+ // }
+ // }
+ // }
+ // }
+ // else
+ // {
+ // if (feature instanceof EReference)
+ // {
+ // value = getEObjectFromPotentialID(view, feature, value);
+ // }
+ //
+ // setInstanceValue(instance, feature, value);
+ // }
}
protected Resource.Internal getInstanceResource(InternalEObject instance)
@@ -394,18 +386,25 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
protected void setInstanceResource(Resource.Internal resource)
{
- ReflectUtil.invokeMethod(eSetDirectResourceMethod, instance, resource);
+ Method method = ReflectUtil.getMethod(instance.getClass(), "eSetDirectResource", Resource.Internal.class); //$NON-NLS-1$
+ ReflectUtil.invokeMethod(method, instance, resource);
}
protected void setInstanceContainer(InternalEObject container, int containerFeatureID)
{
- ReflectUtil.invokeMethod(eBasicSetContainerMethod, instance, container, containerFeatureID);
+ Method method = ReflectUtil.getMethod(instance.getClass(), "eBasicSetContainer", InternalEObject.class, int.class); //$NON-NLS-1$
+ ReflectUtil.invokeMethod(method, instance, container, containerFeatureID);
+ }
+
+ protected void setInstanceValue(InternalEObject instance, EStructuralFeature feature, Object value)
+ {
+ instance.eSet(feature, value);
}
/**
* TODO Ed: Help to fix whole mess (avoid inverse updates)
*/
- protected void setInstanceValue(InternalEObject instance, EStructuralFeature feature, Object value)
+ private void setInstanceValueOLD(InternalEObject instance, EStructuralFeature feature, Object value)
{
// TODO Consider EStoreEObjectImpl based objects as well!
// TODO Don't use Java reflection
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 627de82a83..0b784339ca 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
@@ -58,6 +58,8 @@ import org.eclipse.emf.spi.cdo.InternalCDOLoadable;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
import org.eclipse.emf.spi.cdo.InternalCDOView;
+import org.eclipse.core.runtime.Assert;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -322,7 +324,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- instanceToRevisionFeature(view, revision, eFeature, eSettings, i);
+ Object setting = cdoBasicSettings() != null ? cdoSettings()[i] : null;
+ instanceToRevisionFeature(view, revision, eFeature, setting);
}
}
@@ -348,7 +351,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
TRACER.format("Depopulating revision for {0}", this); //$NON-NLS-1$
}
- InternalCDOView view = cdoView();
super.eSetDirectResource((Resource.Internal)cdoStore().getResource(this));
CDOStore store = cdoStore();
@@ -356,7 +358,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
eContainerFeatureID = store.getContainingFeatureID(this);
if (eContainer != null && eContainmentFeature().isResolveProxies())
{
- adjustOppositeReference(eContainer, eContainmentFeature());
+ adjustOppositeReference(this, eContainer, eContainmentFeature());
}
// Ensure that the internal eSettings array is initialized;
@@ -368,7 +370,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- revisionToInstanceFeature(view, revision, eFeature, eSettings, i);
+ revisionToInstanceFeature(this, revision, eFeature);
}
}
}
@@ -915,58 +917,17 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return cdoView().getStore();
}
- private void instanceToRevisionFeature(InternalCDOView view, InternalCDORevision revision,
- EStructuralFeature feature, Object[] eSettings, int i)
- {
- Object setting = cdoBasicSettings() != null ? cdoSettings()[i] : null;
- instanceToRevisionFeature(view, revision, feature, setting);
- }
-
- private void revisionToInstanceFeature(InternalCDOView view, InternalCDORevision revision,
- EStructuralFeature eFeature, Object[] eSettings, int i)
+ private void resetSettings()
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Depopulating feature {0}", eFeature); //$NON-NLS-1$
- }
-
- EStructuralFeature.Internal internalFeature = (EStructuralFeature.Internal)eFeature;
- EReference oppositeReference = cdoID().isTemporary() ? null : internalFeature.getEOpposite();
-
- CDOStore cdoStore = cdoStore();
- EStore eStore = eStore();
-
- if (eFeature.isMany())
- {
- int size = cdoStore.size(this, eFeature);
- for (int index = 0; index < size; index++)
- {
- // Do not trigger events
- // Do not trigger inverse updates
- Object object = cdoStore.get(this, eFeature, index);
- eStore.add(this, eFeature, index, object);
- if (oppositeReference != null)
- {
- adjustOppositeReference((InternalEObject)object, oppositeReference);
- }
- }
- }
- else
- {
- Object object = cdoStore.get(this, eFeature, EStore.NO_INDEX);
- eStore.set(this, eFeature, EStore.NO_INDEX, object);
- if (oppositeReference != null)
- {
- adjustOppositeReference((InternalEObject)object, oppositeReference);
- }
- }
+ cdoSettings = null;
+ cdoSettings();
}
/**
* Adjust the reference ONLY if the opposite reference used CDOID. This is true ONLY if the state of <cdo>this</code>
* was not {@link CDOState#NEW}.
*/
- private void adjustOppositeReference(InternalEObject object, EReference feature)
+ private static void adjustOppositeReference(InternalCDOObject instance, InternalEObject object, EReference feature)
{
if (object != null)
{
@@ -975,18 +936,18 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
if (feature.isMany())
{
- int index = cdoObject.eStore().indexOf(cdoObject, feature, cdoID());
+ int index = cdoObject.eStore().indexOf(cdoObject, feature, instance.cdoID());
// TODO Simon Log an error in the new view.getErrors() in the case we are not able to find the object.
// Cannot throw an exception, the detach process is too far.
if (index != -1)
{
- cdoObject.eStore().set(cdoObject, feature, index, this);
+ cdoObject.eStore().set(cdoObject, feature, index, instance);
}
}
else
{
- cdoObject.eStore().set(cdoObject, feature, 0, this);
+ cdoObject.eStore().set(cdoObject, feature, 0, instance);
}
}
else
@@ -998,25 +959,63 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
@SuppressWarnings("unchecked")
InternalEList<Object> list = (InternalEList<Object>)object.eGet(feature);
- int index = list.indexOf(this);
+ int index = list.indexOf(instance);
if (index != -1)
{
- list.set(index, this);
+ list.set(index, instance);
}
}
else
{
- object.eSet(feature, this);
+ object.eSet(feature, instance);
}
}
}
}
}
- private void resetSettings()
+ /**
+ * @since 2.0
+ */
+ public static void revisionToInstanceFeature(InternalCDOObject instance, InternalCDORevision revision,
+ EStructuralFeature eFeature)
{
- cdoSettings = null;
- cdoSettings();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Depopulating feature {0}", eFeature); //$NON-NLS-1$
+ }
+
+ EStructuralFeature.Internal internalFeature = (EStructuralFeature.Internal)eFeature;
+ EReference oppositeReference = instance.cdoID().isTemporary() ? null : internalFeature.getEOpposite();
+
+ CDOStore cdoStore = instance.cdoView().getStore();
+ EStore eStore = instance.eStore();
+ Assert.isTrue(cdoStore != eStore); // XXX Remove me!
+
+ if (eFeature.isMany())
+ {
+ int size = cdoStore.size(instance, eFeature);
+ for (int index = 0; index < size; index++)
+ {
+ // Do not trigger events
+ // Do not trigger inverse updates
+ Object object = cdoStore.get(instance, eFeature, index);
+ eStore.add(instance, eFeature, index, object);
+ if (oppositeReference != null)
+ {
+ adjustOppositeReference(instance, (InternalEObject)object, oppositeReference);
+ }
+ }
+ }
+ else
+ {
+ Object object = cdoStore.get(instance, eFeature, EStore.NO_INDEX);
+ eStore.set(instance, eFeature, EStore.NO_INDEX, object);
+ if (oppositeReference != null)
+ {
+ adjustOppositeReference(instance, (InternalEObject)object, oppositeReference);
+ }
+ }
}
/**
@@ -1041,14 +1040,14 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EList<Object> list = (EList<Object>)setting;
for (Object value : list)
{
- value = cdoStore.convertToCDO(view, feature, value);
+ value = cdoStore.convertToCDO(feature, value);
revision.add(feature, index++, value);
}
}
}
else
{
- setting = cdoStore.convertToCDO(view, feature, setting);
+ setting = cdoStore.convertToCDO(feature, setting);
revision.set(feature, 0, setting);
}
}
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 4f25fc4382..edb60132a1 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
@@ -172,7 +172,7 @@ public final class CDOStore implements EStore
InternalCDORevision revision = getRevisionForReading(cdoObject);
Object value = revision.basicGet(feature, index);
- value = convertToEMF(view, eObject, revision, feature, index, value);
+ value = convertToEMF(eObject, revision, feature, index, value);
view.getFeatureAnalyzer().postTraverseFeature(cdoObject, feature, index, value);
return value;
@@ -322,7 +322,7 @@ public final class CDOStore implements EStore
TRACER.format("set({0}, {1}, {2}, {3})", cdoObject, feature, index, value); //$NON-NLS-1$
}
- value = convertToCDO(getView(), feature, value);
+ value = convertToCDO(feature, value);
CDOFeatureDelta delta = new CDOSetFeatureDeltaImpl(feature, index, value);
InternalCDORevision revision = getRevisionForWriting(cdoObject, delta);
@@ -334,15 +334,15 @@ public final class CDOStore implements EStore
}
Object oldValue = revision.basicSet(feature, index, value);
- oldValue = convertToEMF(cdoObject.cdoView(), eObject, revision, feature, index, oldValue);
+ oldValue = convertToEMF(eObject, revision, feature, index, oldValue);
return oldValue;
}
/**
* @since 2.0
*/
- public Object convertToEMF(InternalCDOView view, EObject eObject, InternalCDORevision revision,
- EStructuralFeature feature, int index, Object value)
+ public Object convertToEMF(EObject eObject, InternalCDORevision revision, EStructuralFeature feature,
+ int index, Object value)
{
if (value != null)
{
@@ -402,7 +402,7 @@ public final class CDOStore implements EStore
/**
* @since 2.0
*/
- public Object convertToCDO(InternalCDOView view, EStructuralFeature feature, Object value)
+ public Object convertToCDO(EStructuralFeature feature, Object value)
{
if (value != null)
{
@@ -461,7 +461,7 @@ public final class CDOStore implements EStore
TRACER.format("add({0}, {1}, {2}, {3})", cdoObject, feature, index, value); //$NON-NLS-1$
}
- value = convertToCDO(cdoObject.cdoView(), feature, value);
+ value = convertToCDO(feature, value);
CDOFeatureDelta delta = new CDOAddFeatureDeltaImpl(feature, index, value);
InternalCDORevision revision = getRevisionForWriting(cdoObject, delta);
@@ -480,7 +480,7 @@ public final class CDOStore implements EStore
InternalCDORevision revision = getRevisionForWriting(cdoObject, delta);
Object result = revision.remove(feature, index);
- result = convertToEMF(cdoObject.cdoView(), eObject, revision, feature, index, result);
+ result = convertToEMF(eObject, revision, feature, index, result);
return result;
}
@@ -511,7 +511,7 @@ public final class CDOStore implements EStore
InternalCDORevision revision = getRevisionForWriting(cdoObject, delta);
Object result = revision.move(feature, target, source);
- result = convertToEMF(cdoObject.cdoView(), eObject, revision, feature, EStore.NO_INDEX, result);
+ result = convertToEMF(eObject, revision, feature, EStore.NO_INDEX, result);
return result;
}

Back to the top