summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidijus Vaishnora2011-09-23 06:27:51 (EDT)
committerEgidijus Vaishnora2011-09-23 06:27:51 (EDT)
commit9e23c84546123bb1d0f4af762a7b78770aa46839 (patch)
tree3ec9c5a28fd2cefd0e52d1787c5266fa936b1dde
parent95e1550f9bcf337671f89e2d22a94f4efc9944e5 (diff)
downloadcdo-9e23c84546123bb1d0f4af762a7b78770aa46839.zip
cdo-9e23c84546123bb1d0f4af762a7b78770aa46839.tar.gz
cdo-9e23c84546123bb1d0f4af762a7b78770aa46839.tar.bz2
358189: Provide smart cross reference iterator in CDOTransactionImpl.removeCrossReferences method
https://bugs.eclipse.org/bugs/show_bug.cgi?id=358189
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java67
1 files changed, 57 insertions, 10 deletions
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 2fd08ab..b6e8705 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
@@ -127,7 +127,9 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.InternalEObject.EStore;
-import org.eclipse.emf.ecore.util.EContentsEList;
+import org.eclipse.emf.ecore.impl.EClassImpl.FeatureSubsetSupplier;
+import org.eclipse.emf.ecore.util.EContentsEList.FeatureIterator;
+import org.eclipse.emf.ecore.util.ECrossReferenceEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult;
@@ -2187,8 +2189,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
List<Pair<Setting, EObject>> objectsToBeRemoved = new LinkedList<Pair<Setting, EObject>>();
for (CDOObject referencer : referencers)
{
- EContentsEList.FeatureIterator<EObject> it = (EContentsEList.FeatureIterator<EObject>)referencer
- .eCrossReferences().iterator();
+ FeatureIterator<EObject> it = getChangeableCrossReferences(referencer);
while (it.hasNext())
{
EObject referencedObject = it.next();
@@ -2198,13 +2199,6 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
{
EReference reference = (EReference)it.feature();
- // Don't touch derived references -- user app might not like this.
- // And don't touch unchangeable references either.
- if (reference.isDerived() || !reference.isChangeable())
- {
- continue;
- }
-
// In the case of DIRTY, we must investigate further: Is the referencer dirty
// because a reference to the referencedObject was added? Only in this case
// should we remove it. If this is not the case (i.e. it is dirty in a different
@@ -2235,6 +2229,44 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
+ private FeatureIterator<EObject> getChangeableCrossReferences(EObject object)
+ {
+ FeatureSubsetSupplier features = (FeatureSubsetSupplier)object.eClass().getEAllStructuralFeatures();
+ EStructuralFeature[] crossReferences = features.crossReferences();
+ if (crossReferences != null)
+ {
+ List<EStructuralFeature> changeableReferences = new ArrayList<EStructuralFeature>();
+ for (int i = 0; i < crossReferences.length; i++)
+ {
+ EStructuralFeature reference = crossReferences[i];
+
+ // Filter out derived references
+ if (reference.isDerived())
+ {
+ continue;
+ }
+
+ // Filter out unchangeable references
+ if (!reference.isChangeable())
+ {
+ continue;
+ }
+
+ changeableReferences.add(reference);
+ }
+
+ if (!changeableReferences.isEmpty())
+ {
+ EStructuralFeature[] collectedStructuralFeatures = changeableReferences
+ .toArray(new EStructuralFeature[changeableReferences.size()]);
+ return (FeatureIterator<EObject>)new ECrossReferenceEListDerived(object, collectedStructuralFeatures)
+ .iterator();
+ }
+ }
+
+ return (FeatureIterator<EObject>)ECrossReferenceEList.<EObject> emptyContentsEList().iterator();
+ }
+
public synchronized long getLastCommitTime()
{
return lastCommitTime;
@@ -2981,4 +3013,19 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
}
+
+ public static class ECrossReferenceEListDerived extends ECrossReferenceEList<EObject>
+ {
+
+ public ECrossReferenceEListDerived(EObject eObject)
+ {
+ super(eObject);
+ }
+
+ public ECrossReferenceEListDerived(EObject eObject, EStructuralFeature[] eStructuralFeatures)
+ {
+ super(eObject, eStructuralFeatures);
+ }
+ }
+
}