Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2009-05-07 03:54:13 -0400
committerEike Stepper2009-05-07 03:54:13 -0400
commitcaee5708555502d1e162eb336a4684a4a05786ac (patch)
treec8d7946beed533a023120c1d08bee7748daf5a1d /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo
parentb882ed3d43cf05ad46d11130594a4fde75162975 (diff)
downloadcdo-caee5708555502d1e162eb336a4684a4a05786ac.tar.gz
cdo-caee5708555502d1e162eb336a4684a4a05786ac.tar.xz
cdo-caee5708555502d1e162eb336a4684a4a05786ac.zip
[247226] Transparently support legacy models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247226
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java37
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyWrapper.java91
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java73
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java45
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java63
5 files changed, 176 insertions, 133 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
index 33a22f7620..fb4783a60d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyAdapter.java
@@ -24,9 +24,9 @@ import java.util.List;
*/
public final class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Internal
{
- public CDOLegacyAdapter(InternalEObject instance)
+ public CDOLegacyAdapter()
{
- super(instance);
+ super(null);
}
public void setTarget(Notifier newTarget)
@@ -49,59 +49,58 @@ public final class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.
public boolean isAdapterForType(Object type)
{
- return true;
+ return type == CDOLegacyAdapter.class;
}
- public void notifyChanged(Notification notification)
+ public void notifyChanged(Notification msg)
{
- switch (notification.getEventType())
+ CDOStore store = view.getStore();
+ EStructuralFeature feature = (EStructuralFeature)msg.getFeature();
+ switch (msg.getEventType())
{
case Notification.SET:
- view.getStore().set(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- notification.getNewValue());
+ store.set(instance, feature, msg.getPosition(), msg.getNewValue());
break;
case Notification.UNSET:
- view.getStore().unset(instance, (EStructuralFeature)notification.getFeature());
+ store.unset(instance, feature);
break;
case Notification.MOVE:
// TODO Is that correct?
- view.getStore().move(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- (Integer)notification.getOldValue());
+ store.move(instance, feature, msg.getPosition(), (Integer)msg.getOldValue());
break;
case Notification.ADD:
- view.getStore().add(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition(),
- notification.getNewValue());
+ store.add(instance, feature, msg.getPosition(), msg.getNewValue());
break;
case Notification.ADD_MANY:
{
- int pos = notification.getPosition();
+ int pos = msg.getPosition();
@SuppressWarnings("unchecked")
- List<Object> list = (List<Object>)notification.getNewValue();
+ List<Object> list = (List<Object>)msg.getNewValue();
for (Object object : list)
{
// TODO Is that correct?
- view.getStore().add(instance, (EStructuralFeature)notification.getFeature(), pos++, object);
+ store.add(instance, feature, pos++, object);
}
}
break;
case Notification.REMOVE:
- view.getStore().remove(instance, (EStructuralFeature)notification.getFeature(), notification.getPosition());
+ store.remove(instance, feature, msg.getPosition());
break;
case Notification.REMOVE_MANY:
{
- int pos = notification.getPosition();
+ int pos = msg.getPosition();
@SuppressWarnings("unchecked")
- List<Object> list = (List<Object>)notification.getOldValue();
+ List<Object> list = (List<Object>)msg.getOldValue();
for (int i = 0; i < list.size(); i++)
{
- view.getStore().remove(instance, (EStructuralFeature)notification.getFeature(), pos);
+ store.remove(instance, feature, pos);
}
}
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 a9d322825b..a2a072e587 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
@@ -17,13 +17,11 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.common.model.GenUtil;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.session.CDORevisionManagerImpl;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.net4j.util.ImplementationError;
@@ -56,7 +54,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.Iterator;
import java.util.List;
/**
@@ -150,17 +147,17 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
public void cdoInternalPreCommit()
{
- instanceToRevision();
- if (cdoState() == CDOState.DIRTY) // NEW is handled in PrepareTransition
- {
- CDORevisionManagerImpl revisionManager = (CDORevisionManagerImpl)cdoView().getSession().getRevisionManager();
- InternalCDORevision originRevision = revisionManager.getRevisionByVersion(revision.getID(),
- CDORevision.UNCHUNKED, revision.getVersion() - 1, false);
- CDORevisionDelta delta = revision.compare(originRevision);
-
- // TODO LEGACY Consider to gather the deltas on the fly with noremal EMF change notifications
- cdoView().toTransaction().registerRevisionDelta(delta);
- }
+ // instanceToRevision();
+ // if (cdoState() == CDOState.DIRTY) // NEW is handled in PrepareTransition
+ // {
+ // CDORevisionManagerImpl revisionManager = (CDORevisionManagerImpl)cdoView().getSession().getRevisionManager();
+ // InternalCDORevision originRevision = revisionManager.getRevisionByVersion(revision.getID(),
+ // CDORevision.UNCHUNKED, revision.getVersion() - 1, false);
+ // CDORevisionDelta delta = revision.compare(originRevision);
+ //
+ // // TODO LEGACY Consider to gather the deltas on the fly with noremal EMF change notifications
+ // cdoView().toTransaction().registerRevisionDelta(delta);
+ // }
}
public void cdoInternalPreLoad()
@@ -245,38 +242,39 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
protected void instanceToRevisionFeature(EStructuralFeature feature, CDOPackageRegistry packageRegistry)
{
Object instanceValue = getInstanceValue(instance, feature, packageRegistry);
- if (feature.isMany())
- {
- List<Object> revisionList = revision.getList(feature); // TODO lazy?
- revisionList.clear();
-
- if (instanceValue != null)
- {
- InternalEList<?> instanceList = (InternalEList<?>)instanceValue;
- if (!instanceList.isEmpty())
- {
- for (Iterator<?> it = instanceList.basicIterator(); it.hasNext();)
- {
- Object instanceElement = it.next();
- if (instanceElement != null && feature instanceof EReference)
- {
- instanceElement = view.convertObjectToID(instanceElement);
- }
-
- revisionList.add(instanceElement);
- }
- }
- }
- }
- else
- {
- if (instanceValue != null && feature instanceof EReference)
- {
- instanceValue = view.convertObjectToID(instanceValue);
- }
-
- revision.setValue(feature, instanceValue);
- }
+ CDOObjectImpl.instanceToRevisionFeature(view, revision, feature, instanceValue);
+ // if (feature.isMany())
+ // {
+ // List<Object> revisionList = revision.getList(feature); // TODO lazy?
+ // revisionList.clear();
+ //
+ // if (instanceValue != null)
+ // {
+ // InternalEList<?> instanceList = (InternalEList<?>)instanceValue;
+ // if (!instanceList.isEmpty())
+ // {
+ // for (Iterator<?> it = instanceList.basicIterator(); it.hasNext();)
+ // {
+ // Object instanceElement = it.next();
+ // if (instanceElement != null && feature instanceof EReference)
+ // {
+ // instanceElement = view.convertObjectToID(instanceElement);
+ // }
+ //
+ // revisionList.add(instanceElement);
+ // }
+ // }
+ // }
+ // }
+ // else
+ // {
+ // if (instanceValue != null && feature instanceof EReference)
+ // {
+ // instanceValue = view.convertObjectToID(instanceValue);
+ // }
+ //
+ // revision.setValue(feature, instanceValue);
+ // }
}
/**
@@ -731,5 +729,4 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
throw new UnsupportedOperationException(method.getName());
}
}
-
}
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 82ca7821c0..6e60859328 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
@@ -322,7 +322,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- populateRevisionFeature(view, revision, eFeature, eSettings, i);
+ instanceToRevisionFeature(view, revision, eFeature, eSettings, i);
}
}
@@ -368,7 +368,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
if (!eFeature.isTransient())
{
- depopulateRevisionFeature(view, revision, eFeature, eSettings, i);
+ revisionToInstanceFeature(view, revision, eFeature, eSettings, i);
}
}
}
@@ -915,39 +915,14 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return cdoView().getStore();
}
- @SuppressWarnings("unchecked")
- private void populateRevisionFeature(InternalCDOView view, InternalCDORevision revision, EStructuralFeature feature,
- Object[] eSettings, int i)
+ private void instanceToRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ EStructuralFeature feature, Object[] eSettings, int i)
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Populating feature {0}", feature); //$NON-NLS-1$
- }
-
Object setting = cdoBasicSettings() != null ? cdoSettings()[i] : null;
- CDOStore cdoStore = cdoStore();
-
- if (feature.isMany())
- {
- if (setting != null)
- {
- int index = 0;
- EList<Object> list = (EList<Object>)setting;
- for (Object value : list)
- {
- value = cdoStore.convertToCDO(cdoView(), feature, value);
- revision.add(feature, index++, value);
- }
- }
- }
- else
- {
- setting = cdoStore.convertToCDO(cdoView(), feature, setting);
- revision.set(feature, 0, setting);
- }
+ instanceToRevisionFeature(view, revision, feature, setting);
}
- private void depopulateRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ private void revisionToInstanceFeature(InternalCDOView view, InternalCDORevision revision,
EStructuralFeature eFeature, Object[] eSettings, int i)
{
if (TRACER.isEnabled())
@@ -991,7 +966,6 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
* 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}.
*/
- @SuppressWarnings("unchecked")
private void adjustOppositeReference(InternalEObject object, EReference feature)
{
if (object != null)
@@ -1022,6 +996,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
// We should not trigger events. But we have no choice :-(.
if (feature.isMany())
{
+ @SuppressWarnings("unchecked")
InternalEList<Object> list = (InternalEList<Object>)object.eGet(feature);
int index = list.indexOf(this);
if (index != -1)
@@ -1045,6 +1020,40 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
/**
+ * @since 2.0
+ */
+ public static void instanceToRevisionFeature(InternalCDOView view, InternalCDORevision revision,
+ EStructuralFeature feature, Object setting)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Populating feature {0}", feature); //$NON-NLS-1$
+ }
+
+ CDOStore cdoStore = view.getStore();
+
+ if (feature.isMany())
+ {
+ if (setting != null)
+ {
+ int index = 0;
+ @SuppressWarnings("unchecked")
+ EList<Object> list = (EList<Object>)setting;
+ for (Object value : list)
+ {
+ value = cdoStore.convertToCDO(view, feature, value);
+ revision.add(feature, index++, value);
+ }
+ }
+ }
+ else
+ {
+ setting = cdoStore.convertToCDO(view, feature, setting);
+ revision.set(feature, 0, setting);
+ }
+ }
+
+ /**
* @author Simon McDuff
* @since 2.0
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
index 18df3f6163..7083bbf96b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
@@ -21,15 +21,21 @@ import org.eclipse.emf.cdo.util.InvalidObjectException;
import org.eclipse.emf.cdo.util.ObjectNotFoundException;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.internal.cdo.CDOLegacyAdapter;
import org.eclipse.emf.internal.cdo.CDOLegacyWrapper;
import org.eclipse.emf.internal.cdo.CDOMetaWrapper;
import org.eclipse.emf.internal.cdo.CDOStateMachine;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
@@ -73,8 +79,24 @@ public final class FSMUtil
public static boolean isMeta(Object object)
{
- return object instanceof EModelElement || object instanceof EGenericType
- || object instanceof org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
+ if (object instanceof EModelElement || object instanceof EGenericType)
+ {
+ EClass eClass = ((EObject)object).eClass();
+ if (eClass == null)
+ {
+ return false;
+ }
+
+ EPackage ePackage = eClass.getEPackage();
+ if (ePackage == null)
+ {
+ return false;
+ }
+
+ return ePackage.getNsURI() == EcorePackage.eNS_URI;
+ }
+
+ return object instanceof org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
}
public static boolean isWatchable(Object obj)
@@ -153,8 +175,21 @@ public final class FSMUtil
*/
public static InternalCDOObject adaptLegacy(InternalEObject object)
{
- // TODO LEGACY
- throw new UnsupportedOperationException(Messages.getString("FSMUtil.3")); //$NON-NLS-1$
+ if (object.getClass() == DynamicEObjectImpl.class)
+ {
+ throw new IllegalArgumentException("Use CDOFactory to create dynamic object: " + object);
+ }
+
+ EList<Adapter> adapters = object.eAdapters();
+ CDOLegacyAdapter adapter = (CDOLegacyAdapter)EcoreUtil.getAdapter(adapters, CDOLegacyAdapter.class);
+ if (adapter == null)
+ {
+ adapter = new CDOLegacyAdapter();
+ adapters.add(adapter);
+ }
+
+ return adapter;
+
// EList<InternalEObject.EReadListener> readListeners = object.eReadListeners();
// CDOLegacyWrapper wrapper = getLegacyWrapper(readListeners);
// if (wrapper == null)
@@ -168,6 +203,7 @@ public final class FSMUtil
// return wrapper;
}
+ @Deprecated
public static CDOLegacyWrapper getLegacyWrapper(EList<?> listeners)
{
for (Object listener : listeners)
@@ -185,6 +221,7 @@ public final class FSMUtil
* 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!
*/
+ @Deprecated
public static Object getLegacyWrapper(InternalEObject object)
{
// TODO LEGACY
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index aff42b181e..d7b0fb13a2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -939,41 +939,42 @@ public class CDOViewImpl extends Lifecycle implements InternalCDOView
return potentialObject;
}
- if (potentialObject instanceof InternalEObject && !(potentialObject instanceof InternalCDOObject))
- {
- // TODO LEGACY
- // try
- // {
- // InternalEObject eObject = (InternalEObject)potentialObject;
- // Object legacyListener = FSMUtil.getLegacyWrapper(eObject);
- // if (legacyListener != null)
- // {
- // potentialObject = legacyListener;
- // }
- // }
- // catch (Throwable ex)
- // {
- // OM.LOG.warn(ex);
- // }
- }
-
- if (potentialObject instanceof InternalCDOObject)
- {
- InternalCDOObject object = (InternalCDOObject)potentialObject;
- boolean newOrTransient = FSMUtil.isTransient(object) || FSMUtil.isNew(object);
- if (!(onlyPersistedID && newOrTransient))
- {
- CDOView view = object.cdoView();
- if (view == this)
+ if (potentialObject instanceof InternalEObject)
+ {
+ if (potentialObject instanceof InternalCDOObject)
+ {
+ InternalCDOObject object = (InternalCDOObject)potentialObject;
+ boolean newOrTransient = FSMUtil.isTransient(object) || FSMUtil.isNew(object);
+ if (!(onlyPersistedID && newOrTransient))
{
- return object.cdoID();
- }
+ CDOView view = object.cdoView();
+ if (view == this)
+ {
+ return object.cdoID();
+ }
- if (view != null && view.getSession() == getSession())
- {
- return object.cdoID();
+ if (view != null && view.getSession() == getSession())
+ {
+ return object.cdoID();
+ }
}
}
+ else
+ {
+ // try
+ // {
+ // InternalEObject eObject = (InternalEObject)potentialObject;
+ // InternalCDOObject cdoObject = FSMUtil.adaptLegacy(eObject);
+ // if (cdoObject != null)
+ // {
+ // potentialObject = cdoObject;
+ // }
+ // }
+ // catch (Throwable ex)
+ // {
+ // OM.LOG.warn(ex);
+ // }
+ }
}
return potentialObject;

Back to the top