Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-03-02 12:34:36 +0000
committerEike Stepper2012-03-02 12:34:36 +0000
commitcdf68b2a14a24bbd1df86f143c83d0ff276b8c89 (patch)
tree8fca77949f7bda73d795c770ec50cf0a848d44e4 /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
parent646b5fba42b96d6157102c0811c129e6640b9a40 (diff)
downloadcdo-cdf68b2a14a24bbd1df86f143c83d0ff276b8c89.tar.gz
cdo-cdf68b2a14a24bbd1df86f143c83d0ff276b8c89.tar.xz
cdo-cdf68b2a14a24bbd1df86f143c83d0ff276b8c89.zip
[272478] Better support for attributes having isMany() == true and isOrdered() == false
https://bugs.eclipse.org/bugs/show_bug.cgi?id=272478
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java321
1 files changed, 188 insertions, 133 deletions
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 9ec1bde416..b9fef3935e 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
@@ -41,7 +41,6 @@ import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -834,147 +833,46 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return new CDOStoreFeatureMap(eStructuralFeature);
}
- @Override
- protected EList<?> createList(final EStructuralFeature eStructuralFeature)
+ /**
+ * @since 4.1
+ */
+ protected CDOStoreEcoreEMap createMap(EStructuralFeature eStructuralFeature)
{
- final EClassifier eType = eStructuralFeature.getEType();
-
- // Answer from Christian Damus
- // Java ensures that string constants are interned, so this is actually
- // more efficient than .equals() and it's correct
- if (eType.getInstanceClassName() == "java.util.Map$Entry") //$NON-NLS-1$
- {
- class EStoreEcoreEMap extends EcoreEMap<Object, Object> implements InternalCDOLoadable
- {
- private static final long serialVersionUID = 1L;
-
- public EStoreEcoreEMap()
- {
- super((EClass)eType, BasicEMap.Entry.class, null);
- delegateEList = new BasicEStoreEList<BasicEMap.Entry<Object, Object>>(CDOObjectImpl.this, eStructuralFeature)
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void unset()
- {
- super.unset();
- doClear();
- }
-
- @Override
- protected void didAdd(int index, BasicEMap.Entry<Object, Object> newObject)
- {
- EStoreEcoreEMap.this.doPut(newObject);
- }
-
- @Override
- protected void didSet(int index, BasicEMap.Entry<Object, Object> newObject,
- BasicEMap.Entry<Object, Object> oldObject)
- {
- didRemove(index, oldObject);
- didAdd(index, newObject);
- }
-
- @Override
- protected void didRemove(int index, BasicEMap.Entry<Object, Object> oldObject)
- {
- EStoreEcoreEMap.this.doRemove(oldObject);
- }
-
- @Override
- protected void didClear(int size, Object[] oldObjects)
- {
- EStoreEcoreEMap.this.doClear();
- }
-
- @Override
- protected void didMove(int index, BasicEMap.Entry<Object, Object> movedObject, int oldIndex)
- {
- EStoreEcoreEMap.this.doMove(movedObject);
- }
- };
-
- size = delegateEList.size();
- }
-
- private void checkListForReading()
- {
- if (!FSMUtil.isTransient(CDOObjectImpl.this))
- {
- CDOStateMachine.INSTANCE.read(CDOObjectImpl.this);
- }
- }
-
- /**
- * Ensures that the entry data is created and is populated with contents of the delegate list.
- */
- @Override
- protected synchronized void ensureEntryDataExists()
- {
- checkListForReading();
- super.ensureEntryDataExists();
- }
-
- @Override
- public int size()
- {
- checkListForReading();
- return size;
- }
-
- @Override
- public boolean isEmpty()
- {
- checkListForReading();
- return size == 0;
- }
-
- @Override
- public boolean contains(Object object)
- {
- checkListForReading();
- return super.contains(object);
- }
-
- @Override
- public boolean containsAll(Collection<?> collection)
- {
- checkListForReading();
- return super.containsAll(collection);
- }
-
- @Override
- public boolean containsKey(Object key)
- {
- checkListForReading();
- return super.containsKey(key);
- }
-
- @Override
- public boolean containsValue(Object value)
- {
- checkListForReading();
- return super.containsValue(value);
- }
+ return new CDOStoreEcoreEMap(eStructuralFeature);
+ }
- public void cdoInternalPostLoad()
- {
- entryData = null;
- size = delegateEList.size();
- }
+ /**
+ * @since 4.1
+ */
+ protected CDOStoreUnorderedEList<Object> createUnorderedList(EStructuralFeature eStructuralFeature)
+ {
+ return new CDOStoreUnorderedEList<Object>(eStructuralFeature);
+ }
- public void cdoInternalPreLoad()
- {
- }
- }
+ @Override
+ protected EList<?> createList(EStructuralFeature eStructuralFeature)
+ {
+ if (isMap(eStructuralFeature))
+ {
+ return createMap(eStructuralFeature);
+ }
- return new EStoreEcoreEMap();
+ if (!eStructuralFeature.isOrdered())
+ {
+ return createUnorderedList(eStructuralFeature);
}
return super.createList(eStructuralFeature);
}
+ private boolean isMap(EStructuralFeature eStructuralFeature)
+ {
+ // Answer from Christian Damus:
+ // Java ensures that string constants are interned, so this is actually
+ // more efficient than .equals() and it's correct
+ return eStructuralFeature.getEType().getInstanceClassName() == "java.util.Map$Entry"; //$NON-NLS-1$
+ }
+
@Override
protected void eInitializeContainer()
{
@@ -1401,6 +1299,163 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
/**
+ * @author Eike Stepper
+ * @since 4.1
+ */
+ public class CDOStoreEcoreEMap extends EcoreEMap<Object, Object> implements InternalCDOLoadable
+ {
+ private static final long serialVersionUID = 1L;
+
+ public CDOStoreEcoreEMap(EStructuralFeature eStructuralFeature)
+ {
+ super((EClass)eStructuralFeature.getEType(), BasicEMap.Entry.class, null);
+ delegateEList = new BasicEStoreEList<BasicEMap.Entry<Object, Object>>(CDOObjectImpl.this, eStructuralFeature)
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void unset()
+ {
+ super.unset();
+ doClear();
+ }
+
+ @Override
+ protected void didAdd(int index, BasicEMap.Entry<Object, Object> newObject)
+ {
+ CDOStoreEcoreEMap.this.doPut(newObject);
+ }
+
+ @Override
+ protected void didSet(int index, BasicEMap.Entry<Object, Object> newObject,
+ BasicEMap.Entry<Object, Object> oldObject)
+ {
+ didRemove(index, oldObject);
+ didAdd(index, newObject);
+ }
+
+ @Override
+ protected void didRemove(int index, BasicEMap.Entry<Object, Object> oldObject)
+ {
+ CDOStoreEcoreEMap.this.doRemove(oldObject);
+ }
+
+ @Override
+ protected void didClear(int size, Object[] oldObjects)
+ {
+ CDOStoreEcoreEMap.this.doClear();
+ }
+
+ @Override
+ protected void didMove(int index, BasicEMap.Entry<Object, Object> movedObject, int oldIndex)
+ {
+ CDOStoreEcoreEMap.this.doMove(movedObject);
+ }
+ };
+
+ size = delegateEList.size();
+ }
+
+ private void checkListForReading()
+ {
+ if (!FSMUtil.isTransient(CDOObjectImpl.this))
+ {
+ CDOStateMachine.INSTANCE.read(CDOObjectImpl.this);
+ }
+ }
+
+ /**
+ * Ensures that the entry data is created and is populated with contents of the delegate list.
+ */
+ @Override
+ protected synchronized void ensureEntryDataExists()
+ {
+ checkListForReading();
+ super.ensureEntryDataExists();
+ }
+
+ @Override
+ public int size()
+ {
+ checkListForReading();
+ return size;
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ checkListForReading();
+ return size == 0;
+ }
+
+ @Override
+ public boolean contains(Object object)
+ {
+ checkListForReading();
+ return super.contains(object);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> collection)
+ {
+ checkListForReading();
+ return super.containsAll(collection);
+ }
+
+ @Override
+ public boolean containsKey(Object key)
+ {
+ checkListForReading();
+ return super.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value)
+ {
+ checkListForReading();
+ return super.containsValue(value);
+ }
+
+ public void cdoInternalPostLoad()
+ {
+ entryData = null;
+ size = delegateEList.size();
+ }
+
+ public void cdoInternalPreLoad()
+ {
+ }
+ }
+
+ /**
+ * @author Andras Peteri
+ * @since 4.1
+ */
+ public class CDOStoreUnorderedEList<E> extends BasicEStoreEList<E>
+ {
+ private static final long serialVersionUID = 1L;
+
+ public CDOStoreUnorderedEList(EStructuralFeature feature)
+ {
+ super(CDOObjectImpl.this, feature);
+ }
+
+ @Override
+ public E remove(int index)
+ {
+ boolean oldObjectIsLast = index == size() - 1;
+ E oldObject = super.remove(index);
+
+ if (!oldObjectIsLast)
+ {
+ move(index, size() - 1);
+ }
+
+ return oldObject;
+ }
+ }
+
+ /**
* TODO Remove this when EMF has fixed bug 197487
*
* @author Eike Stepper

Back to the top