From 1724469f6fb2c4addf24adc004f9c19c52ba17dc Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Sat, 23 May 2009 17:26:31 +0000 Subject: [249436] Support FeatureMap https://bugs.eclipse.org/bugs/show_bug.cgi?id=249436 --- .../eclipse/emf/internal/cdo/CDOLegacyWrapper.java | 79 ---------------------- .../src/org/eclipse/emf/internal/cdo/CDOStore.java | 42 +++++++----- .../cdo/analyzer/CDOFeatureAnalyzerUI.java | 6 +- .../cdo/net4j/protocol/LoadChunkRequest.java | 2 +- .../revision/CDOListWithElementProxiesImpl.java | 3 +- .../emf/internal/cdo/session/CDOSessionImpl.java | 4 +- .../cdo/transaction/CDOXACommitContextImpl.java | 2 +- .../emf/internal/cdo/util/RevisionAdjuster.java | 6 +- .../eclipse/emf/spi/cdo/CDOSessionProtocol.java | 6 +- 9 files changed, 43 insertions(+), 107 deletions(-) (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse') 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 9804644297..c690444632 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 @@ -238,38 +238,6 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper { Object instanceValue = getInstanceValue(instance, feature, packageRegistry); CDOObjectImpl.instanceToRevisionFeature(view, revision, feature, instanceValue); - // if (feature.isMany()) - // { - // List 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); - // } } /** @@ -326,53 +294,6 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper // Attempt 4 Object value = revision.getValue(feature); view.getStore().set(instance, feature, Notification.NO_INDEX, value); - - // // Attempt 3 - // Object value = revision.getValue(feature); - // instance.eSet(feature, value); - - // // Attempt 2 - // CDOObjectImpl.revisionToInstanceFeature(this, revision, feature); - - // // Attempt 1 - // Object value = revision.getValue(feature); - // if (feature.isMany()) - // { - // InternalEList instanceList = (InternalEList)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) 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 edb60132a1..e2a1a73c9d 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 @@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.model.CDOModelUtil; import org.eclipse.emf.cdo.common.model.CDOType; import org.eclipse.emf.cdo.common.revision.CDOList; +import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.internal.common.revision.delta.CDOAddFeatureDeltaImpl; @@ -44,6 +45,7 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.InternalEObject.EStore; import org.eclipse.emf.ecore.impl.EStoreEObjectImpl; +import org.eclipse.emf.ecore.util.FeatureMap; import org.eclipse.emf.ecore.util.FeatureMapUtil; import org.eclipse.emf.spi.cdo.CDOElementProxy; import org.eclipse.emf.spi.cdo.InternalCDOObject; @@ -217,6 +219,7 @@ public final class CDOStore implements EStore TRACER.format("contains({0}, {1}, {2})", cdoObject, feature, value); //$NON-NLS-1$ } + // TODO Clarify feature maps if (feature instanceof EReference) { value = cdoObject.cdoView().convertObjectToID(value, true); @@ -234,6 +237,7 @@ public final class CDOStore implements EStore TRACER.format("indexOf({0}, {1}, {2})", cdoObject, feature, value); //$NON-NLS-1$ } + // TODO Clarify feature maps if (feature instanceof EReference) { value = cdoObject.cdoView().convertObjectToID(value, true); @@ -251,6 +255,7 @@ public final class CDOStore implements EStore TRACER.format("lastIndexOf({0}, {1}, {2})", cdoObject, feature, value); //$NON-NLS-1$ } + // TODO Clarify feature maps if (feature instanceof EReference) { value = cdoObject.cdoView().convertObjectToID(value, true); @@ -282,6 +287,7 @@ public final class CDOStore implements EStore InternalCDORevision revision = getRevisionForReading(cdoObject); Object[] result = revision.toArray(feature); + // TODO Clarify feature maps if (feature instanceof EReference) { for (int i = 0; i < result.length; i++) @@ -326,6 +332,7 @@ public final class CDOStore implements EStore CDOFeatureDelta delta = new CDOSetFeatureDeltaImpl(feature, index, value); InternalCDORevision revision = getRevisionForWriting(cdoObject, delta); + // TODO Clarify feature maps if (feature instanceof EReference) { Object oldValue = revision.basicGet(feature, index); @@ -341,8 +348,8 @@ public final class CDOStore implements EStore /** * @since 2.0 */ - public Object convertToEMF(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) { @@ -369,6 +376,7 @@ public final class CDOStore implements EStore } } + // TODO Clarify feature maps if (feature instanceof EReference) { // The EReference condition should be in the CDOType.convertToCDO. Since common package do not have access to @@ -377,14 +385,14 @@ public final class CDOStore implements EStore } else if (FeatureMapUtil.isFeatureMap(feature)) { - // TODO Handle feature maps! - // EStructuralFeatureMapEntryDataTypeImpl entry = (EStructuralFeatureMapEntryDataTypeImpl)value; - // EStructuralFeature feature = (EStructuralFeature)view.getResourceSet().getEObject( - // URI.createURI(entry.getURI()), true); - // Object object = view.convertIDToObject(entry.getObject()); - // value = FeatureMapUtil.createEntry(feature, object); - throw new UnsupportedOperationException( - "Feature maps currently not supported. See https://bugs.eclipse.org/249436"); //$NON-NLS-1$ + FeatureMap.Entry entry = (FeatureMap.Entry)value; + EStructuralFeature innerFeature = entry.getEStructuralFeature(); + Object innerValue = entry.getValue(); + Object convertedValue = view.convertIDToObject(innerValue); + if (convertedValue != innerValue) + { + value = FeatureMapUtil.createEntry(innerFeature, convertedValue); + } } else { @@ -418,12 +426,14 @@ public final class CDOStore implements EStore } else if (FeatureMapUtil.isFeatureMap(feature)) { - // TODO Handle feature maps! - // FeatureMap.Entry entry = (FeatureMap.Entry)value; - // String uri = EcoreUtil.getURI(entry.getEStructuralFeature()).toString(); - // value = CDORevisionUtil.createFeatureMapEntry(uri, entry.getValue()); - throw new UnsupportedOperationException( - "Feature maps currently not supported. See https://bugs.eclipse.org/249436"); //$NON-NLS-1$ + FeatureMap.Entry entry = (FeatureMap.Entry)value; + EStructuralFeature innerFeature = entry.getEStructuralFeature(); + Object innerValue = entry.getValue(); + Object convertedValue = view.convertObjectToID(innerValue); + if (convertedValue != innerValue) + { + value = CDORevisionUtil.createFeatureMapEntry(innerFeature, convertedValue); + } } else { diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java index 2225a1d106..f1f38db878 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Simon McDuff - initial API and implementation * Eike Stepper - maintenance @@ -104,7 +104,9 @@ public class CDOFeatureAnalyzerUI extends CDOAbstractFeatureRuleAnalyzer @Override protected void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index) { - // Don`t handle containment relationship TODO Simon: Do yu really mean containment here? The check is different... + // Don`t handle containment relationship + // TODO Simon: Do you really mean containment here? The check is different... + // TODO Clarify feature maps if (feature instanceof EReference) { if (lastElapseTimeBetweenOperations > maxTimeBetweenOperation || currentClusterOfFetchRule == null) diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/LoadChunkRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/LoadChunkRequest.java index 2fcd505651..a6d23642ec 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/LoadChunkRequest.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/LoadChunkRequest.java @@ -105,7 +105,7 @@ public class LoadChunkRequest extends CDOClientRequest @Override protected Object confirming(CDODataInput in) throws IOException { - CDOType type = CDOModelUtil.getType(feature.getEType()); + CDOType type = CDOModelUtil.getType(feature); Object accessID = null; MoveableList list = revision.getList(feature); for (int i = fromIndex; i <= toIndex; i++) diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/revision/CDOListWithElementProxiesImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/revision/CDOListWithElementProxiesImpl.java index 79557ca22a..ee69ad5ff1 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/revision/CDOListWithElementProxiesImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/revision/CDOListWithElementProxiesImpl.java @@ -17,7 +17,6 @@ import org.eclipse.emf.cdo.common.revision.CDOList; import org.eclipse.emf.cdo.common.revision.CDOListFactory; import org.eclipse.emf.cdo.internal.common.revision.CDOListImpl; import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList; -import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.spi.cdo.CDOElementProxy; @@ -56,7 +55,7 @@ public class CDOListWithElementProxiesImpl extends CDOListImpl Object element = super.get(index); - return element instanceof CDOElementProxy ? InternalCDORevision.UNINITIALIZED : element; + return element instanceof CDOElementProxy ? UNINITIALIZED : element; } @Override diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java index 08c2590e32..7d29e5f909 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionImpl.java @@ -895,12 +895,12 @@ public abstract class CDOSessionImpl extends Container implements Inter { public CDORevision createRevision(EClass eClass, CDOID id) { - return CDORevisionUtil.create(eClass, id); + return CDORevisionUtil.createRevision(eClass, id); } public CDORevision createRevision(CDODataInput in) throws IOException { - return CDORevisionUtil.read(in); + return in.readCDORevision(); } @Override diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java index 52a0f340c2..d55c2dd1ac 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Simon McDuff - initial API and implementation **************************************************************************/ diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java index a9d1cd18ef..0a01fd97bb 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java @@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta; import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta; import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta; +import org.eclipse.emf.cdo.internal.common.revision.CDORevisionImpl; import org.eclipse.emf.cdo.internal.common.revision.delta.CDOFeatureDeltaVisitorImpl; import org.eclipse.emf.cdo.internal.common.revision.delta.CDOListFeatureDeltaImpl; import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList; @@ -66,6 +67,8 @@ public class RevisionAdjuster extends CDOFeatureDeltaVisitorImpl public void visit(CDOSetFeatureDelta delta) { EStructuralFeature feature = delta.getFeature(); + CDORevisionImpl.checkNoFeatureMap(feature); + Object value = delta.getValue(); if (value != null && feature instanceof EReference && !(value instanceof CDOElementProxy)) { @@ -77,8 +80,9 @@ public class RevisionAdjuster extends CDOFeatureDeltaVisitorImpl public void visit(CDOListFeatureDelta deltas) { EStructuralFeature feature = deltas.getFeature(); - InternalCDOList list = (InternalCDOList)revision.getValue(feature); + CDORevisionImpl.checkNoFeatureMap(feature); + InternalCDOList list = (InternalCDOList)revision.getValue(feature); if (feature instanceof EReference) { int[] indices = ((CDOListFeatureDeltaImpl)deltas).reconstructAddedIndices().getElement2(); diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/CDOSessionProtocol.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/CDOSessionProtocol.java index d331743eee..84df6fb6ee 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/CDOSessionProtocol.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/CDOSessionProtocol.java @@ -4,7 +4,7 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Eike Stepper - initial API and implementation **************************************************************************/ @@ -360,9 +360,9 @@ public interface CDOSessionProtocol extends PackageLoader public Object adjustReference(Object id) { - if (id == null) + if (id == null || id == CDOID.NULL) { - return null; + return id; } if (idProvider != null && (id instanceof CDOID || id instanceof InternalEObject)) -- cgit v1.2.3