Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2019-09-19 06:07:54 +0000
committerEike Stepper2019-09-19 06:07:54 +0000
commit8c2bdd31d762cf3958af1cb0ba0735162d2aa3ac (patch)
treec06b2cbfb572d28613cba7c768d310be94c3f951 /plugins/org.eclipse.emf.cdo.common/src
parent8580a5382feae010a8276d7b10cff84778121668 (diff)
downloadcdo-8c2bdd31d762cf3958af1cb0ba0735162d2aa3ac.tar.gz
cdo-8c2bdd31d762cf3958af1cb0ba0735162d2aa3ac.tar.xz
cdo-8c2bdd31d762cf3958af1cb0ba0735162d2aa3ac.zip
[551232] [DB] Support range-based mappings in CDOServerImporter
https://bugs.eclipse.org/bugs/show_bug.cgi?id=551232
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionUtil.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionManagerImpl.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java307
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/InternalCDORevisionManager.java5
5 files changed, 215 insertions, 132 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionUtil.java
index db530e093d..72431b6116 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionUtil.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.cdo.common.id.CDOWithID;
import org.eclipse.emf.cdo.common.model.CDOClassInfo;
import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
import org.eclipse.emf.cdo.internal.common.commit.CDOChangeSetDataImpl;
@@ -597,6 +598,14 @@ public final class CDORevisionUtil
}
/**
+ * @since 4.8
+ */
+ public static CDOListFeatureDelta compareLists(CDORevision originRevision, CDORevision dirtyRevision, EStructuralFeature feature)
+ {
+ return CDORevisionDeltaImpl.compareLists((InternalCDORevision)originRevision, (InternalCDORevision)dirtyRevision, feature);
+ }
+
+ /**
* @since 3.0
*/
public static String dumpAllRevisions(Map<CDOBranch, List<CDORevision>> map)
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionManagerImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionManagerImpl.java
index 7799f7cf08..4b69884c7d 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionManagerImpl.java
@@ -265,6 +265,27 @@ public class CDORevisionManagerImpl extends Lifecycle implements InternalCDORevi
}
}
+ public InternalCDORevision getBaseRevision(CDORevision revision, int referenceChunk, boolean loadOnDemand)
+ {
+ CDOID id = revision.getID();
+ CDOBranch branch = revision.getBranch();
+ int version = revision.getVersion();
+
+ if (version == CDOBranchVersion.FIRST_VERSION)
+ {
+ if (branch.isMainBranch())
+ {
+ return null;
+ }
+
+ CDOBranchPoint basePoint = branch.getBase();
+ return getRevision(id, basePoint, referenceChunk, CDORevision.DEPTH_NONE, loadOnDemand);
+ }
+
+ CDOBranchVersion baseVersion = branch.getVersion(version - 1);
+ return getRevisionByVersion(id, baseVersion, referenceChunk, loadOnDemand);
+ }
+
public CDOBranchPointRange getObjectLifetime(CDOID id, CDOBranchPoint branchPoint)
{
if (revisionLoader instanceof RevisionLoader2)
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
index 0c1b50bff4..1a9468f1bb 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
@@ -23,7 +23,6 @@ import org.eclipse.emf.cdo.common.revision.CDOElementProxy;
import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevisable;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionData;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
@@ -68,7 +67,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
+public class CDORevisionDeltaImpl implements InternalCDORevisionDelta, ListComparisonHandler
{
private static final boolean WORK_AROUND_BUG_308618 = OMPlatform.INSTANCE.isProperty("org.eclipse.emf.cdo.common.revision.delta.WORK_AROUND_BUG_308618");
@@ -122,22 +121,21 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
version = sourceRevision.getVersion();
target = CDORevisionUtil.copyRevisable(targetRevision);
- compare((InternalCDORevision)sourceRevision, (InternalCDORevision)targetRevision);
+ InternalCDORevision internalSourceRevision = (InternalCDORevision)sourceRevision;
+ InternalCDORevision internalTargetRevision = (InternalCDORevision)targetRevision;
+ compare(internalSourceRevision, internalTargetRevision);
- CDORevisionData originData = sourceRevision.data();
- CDORevisionData dirtyData = targetRevision.data();
-
- Object dirtyContainerID = dirtyData.getContainerID();
+ Object dirtyContainerID = internalTargetRevision.getContainerID();
if (dirtyContainerID instanceof CDOWithID)
{
dirtyContainerID = ((CDOWithID)dirtyContainerID).cdoID();
}
- CDOID dirtyResourceID = dirtyData.getResourceID();
- int dirtyContainingFeatureID = dirtyData.getContainingFeatureID();
- if (!compareValue(CDOContainerFeatureDelta.CONTAINER_FEATURE, originData.getContainerID(), dirtyContainerID)
- || !compareValue(null, originData.getContainingFeatureID(), dirtyContainingFeatureID)
- || !compareValue(CDOContainerFeatureDelta.CONTAINER_FEATURE, originData.getResourceID(), dirtyResourceID))
+ CDOID dirtyResourceID = internalTargetRevision.getResourceID();
+ int dirtyContainingFeatureID = internalTargetRevision.getContainingFeatureID();
+ if (!compareValue(CDOContainerFeatureDelta.CONTAINER_FEATURE, internalSourceRevision.getContainerID(), dirtyContainerID)
+ || !compareValue(null, internalSourceRevision.getContainingFeatureID(), dirtyContainingFeatureID)
+ || !compareValue(CDOContainerFeatureDelta.CONTAINER_FEATURE, internalSourceRevision.getResourceID(), dirtyResourceID))
{
CDOFeatureDelta delta = new CDOContainerFeatureDeltaImpl(dirtyResourceID, dirtyContainerID, dirtyContainingFeatureID);
addFeatureDelta(delta, null);
@@ -366,131 +364,28 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
}
}
- private void compare(final InternalCDORevision originRevision, final InternalCDORevision dirtyRevision)
+ public void addDelta(CDOListFeatureDelta listFeatureDelta)
{
- CDORevisionData originData = originRevision.data();
- CDORevisionData dirtyData = dirtyRevision.data();
+ featureDeltas.put(listFeatureDelta.getFeature(), listFeatureDelta);
+ }
+
+ public void addClearDelta(CDOClearFeatureDelta clearFeatureDelta, CDOOriginSizeProvider originSizeProvider)
+ {
+ addFeatureDelta(clearFeatureDelta, originSizeProvider);
+ }
- for (final EStructuralFeature feature : originRevision.getClassInfo().getAllPersistentFeatures())
+ private void compare(InternalCDORevision originRevision, InternalCDORevision dirtyRevision)
+ {
+ for (EStructuralFeature feature : originRevision.getClassInfo().getAllPersistentFeatures())
{
if (feature.isMany())
{
- final int originSize = originData.size(feature);
- if (originSize > 0 && dirtyData.size(feature) == 0)
- {
- addFeatureDelta(new CDOClearFeatureDeltaImpl(feature), new CDOOriginSizeProvider()
- {
- public int getOriginSize()
- {
- return originSize;
- }
- });
- }
- else
- {
- CDOListFeatureDelta listFeatureDelta = new CDOListFeatureDeltaImpl(feature, originSize);
- final List<CDOFeatureDelta> changes = listFeatureDelta.getListChanges();
-
- ListDifferenceAnalyzer analyzer = new ListDifferenceAnalyzer()
- {
- @Override
- public void analyzeLists(EList<Object> oldList, EList<?> newList, EList<ListChange> listChanges)
- {
- checkNoProxies(oldList, originRevision);
- checkNoProxies(newList, dirtyRevision);
- super.analyzeLists(oldList, newList, listChanges);
- }
-
- @Override
- protected void createAddListChange(EList<Object> oldList, EList<ListChange> listChanges, Object value, int index)
- {
- CDOFeatureDelta delta = new CDOAddFeatureDeltaImpl(feature, index, value);
- changes.add(delta);
- oldList.add(index, value);
- }
-
- @Override
- protected void createRemoveListChange(EList<?> oldList, EList<ListChange> listChanges, Object value, int index)
- {
- CDORemoveFeatureDeltaImpl delta = new CDORemoveFeatureDeltaImpl(feature, index);
-
- if (WORK_AROUND_BUG_308618)
- {
- // Fix until ListDifferenceAnalyzer delivers the correct value (bug 308618).
- delta.setValue(oldList.get(index));
- }
- else
- {
- delta.setValue(value);
- }
-
- changes.add(delta);
- oldList.remove(index);
- }
-
- @Override
- protected void createMoveListChange(EList<?> oldList, EList<ListChange> listChanges, Object value, int index, int toIndex)
- {
- CDOMoveFeatureDeltaImpl delta = new CDOMoveFeatureDeltaImpl(feature, toIndex, index);
-
- if (WORK_AROUND_BUG_308618)
- {
- // Fix until ListDifferenceAnalyzer delivers the correct value (bug 308618).
- delta.setValue(oldList.get(index));
- }
- else
- {
- delta.setValue(value);
- }
-
- changes.add(delta);
- oldList.move(toIndex, index);
- }
-
- @Override
- protected boolean equal(Object originValue, Object dirtyValue)
- {
- return compareValue(feature, originValue, dirtyValue);
- }
-
- private void checkNoProxies(EList<?> list, CDORevision revision)
- {
- if (list != null && !((InternalCDORevision)revision).isUnchunked())
- {
- for (Object element : list)
- {
- if (element instanceof CDOElementProxy || element == CDOListImpl.UNINITIALIZED)
- {
- throw new PartialCollectionLoadingNotSupportedException("List contains proxy elements");
- }
- }
- }
- }
- };
-
- CDOList originList = originRevision.getListOrNull(feature);
- if (originList == null)
- {
- originList = new CDOListImpl(0, 0);
- }
-
- CDOList dirtyList = dirtyRevision.getListOrNull(feature);
- if (dirtyList == null)
- {
- dirtyList = new CDOListImpl(0, 0);
- }
-
- analyzer.analyzeLists(originList, dirtyList, new NOOPList());
- if (!changes.isEmpty())
- {
- featureDeltas.put(feature, listFeatureDelta);
- }
- }
+ compareLists(originRevision, dirtyRevision, feature, this);
}
else
{
- Object originValue = originData.get(feature, 0);
- Object dirtyValue = dirtyData.get(feature, 0);
+ Object originValue = originRevision.get(feature, 0);
+ Object dirtyValue = dirtyRevision.get(feature, 0);
if (!compareValue(feature, originValue, dirtyValue))
{
@@ -509,7 +404,7 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
}
}
- private boolean compareValue(EStructuralFeature feature, Object originValue, Object dirtyValue)
+ private static boolean compareValue(EStructuralFeature feature, Object originValue, Object dirtyValue)
{
if (feature != null)
{
@@ -552,7 +447,7 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
return originValue.equals(dirtyValue);
}
- private Object convertEObject(Object value)
+ private static Object convertEObject(Object value)
{
CDOID id = CDOIDUtil.getCDOID(value);
if (id != null)
@@ -563,7 +458,7 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
return value;
}
- private Object convertDefaultValue(Object value, Object defaultValue)
+ private static Object convertDefaultValue(Object value, Object defaultValue)
{
// if (value == null)
// {
@@ -573,6 +468,143 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
return value;
}
+ private static void compareLists(final InternalCDORevision originRevision, final InternalCDORevision dirtyRevision, final EStructuralFeature feature,
+ ListComparisonHandler handler)
+ {
+ final int originSize = originRevision.size(feature);
+ if (originSize > 0 && dirtyRevision.size(feature) == 0)
+ {
+ handler.addClearDelta(new CDOClearFeatureDeltaImpl(feature), new CDOOriginSizeProvider()
+ {
+ public int getOriginSize()
+ {
+ return originSize;
+ }
+ });
+ }
+ else
+ {
+ CDOListFeatureDelta listFeatureDelta = new CDOListFeatureDeltaImpl(feature, originSize);
+ final List<CDOFeatureDelta> changes = listFeatureDelta.getListChanges();
+
+ ListDifferenceAnalyzer analyzer = new ListDifferenceAnalyzer()
+ {
+ @Override
+ public void analyzeLists(EList<Object> oldList, EList<?> newList, EList<ListChange> listChanges)
+ {
+ checkNoProxies(oldList, originRevision);
+ checkNoProxies(newList, dirtyRevision);
+ super.analyzeLists(oldList, newList, listChanges);
+ }
+
+ @Override
+ protected void createAddListChange(EList<Object> oldList, EList<ListChange> listChanges, Object value, int index)
+ {
+ CDOFeatureDelta delta = new CDOAddFeatureDeltaImpl(feature, index, value);
+ changes.add(delta);
+ oldList.add(index, value);
+ }
+
+ @Override
+ protected void createRemoveListChange(EList<?> oldList, EList<ListChange> listChanges, Object value, int index)
+ {
+ CDORemoveFeatureDeltaImpl delta = new CDORemoveFeatureDeltaImpl(feature, index);
+
+ if (WORK_AROUND_BUG_308618)
+ {
+ // Fix until ListDifferenceAnalyzer delivers the correct value (bug 308618).
+ delta.setValue(oldList.get(index));
+ }
+ else
+ {
+ delta.setValue(value);
+ }
+
+ changes.add(delta);
+ oldList.remove(index);
+ }
+
+ @Override
+ protected void createMoveListChange(EList<?> oldList, EList<ListChange> listChanges, Object value, int index, int toIndex)
+ {
+ CDOMoveFeatureDeltaImpl delta = new CDOMoveFeatureDeltaImpl(feature, toIndex, index);
+
+ if (WORK_AROUND_BUG_308618)
+ {
+ // Fix until ListDifferenceAnalyzer delivers the correct value (bug 308618).
+ delta.setValue(oldList.get(index));
+ }
+ else
+ {
+ delta.setValue(value);
+ }
+
+ changes.add(delta);
+ oldList.move(toIndex, index);
+ }
+
+ @Override
+ protected boolean equal(Object originValue, Object dirtyValue)
+ {
+ return compareValue(feature, originValue, dirtyValue);
+ }
+
+ private void checkNoProxies(EList<?> list, CDORevision revision)
+ {
+ if (list != null && !((InternalCDORevision)revision).isUnchunked())
+ {
+ for (Object element : list)
+ {
+ if (element instanceof CDOElementProxy || element == CDOListImpl.UNINITIALIZED)
+ {
+ throw new PartialCollectionLoadingNotSupportedException("List contains proxy elements");
+ }
+ }
+ }
+ }
+ };
+
+ CDOList originList = originRevision.getListOrNull(feature);
+ if (originList == null)
+ {
+ originList = new CDOListImpl(0, 0);
+ }
+
+ CDOList dirtyList = dirtyRevision.getListOrNull(feature);
+ if (dirtyList == null)
+ {
+ dirtyList = new CDOListImpl(0, 0);
+ }
+
+ analyzer.analyzeLists(originList, dirtyList, new NOOPList());
+ if (!changes.isEmpty())
+ {
+ handler.addDelta(listFeatureDelta);
+ }
+ }
+ }
+
+ public static CDOListFeatureDelta compareLists(final InternalCDORevision originRevision, InternalCDORevision dirtyRevision, final EStructuralFeature feature)
+ {
+ final CDOListFeatureDelta[] result = { null };
+ compareLists(originRevision, dirtyRevision, feature, new ListComparisonHandler()
+ {
+ public void addDelta(CDOListFeatureDelta listFeatureDelta)
+ {
+ result[0] = listFeatureDelta;
+ }
+
+ public void addClearDelta(CDOClearFeatureDelta clearFeatureDelta, CDOOriginSizeProvider originSizeProvider)
+ {
+ CDOListFeatureDeltaImpl listFeatureDelta = new CDOListFeatureDeltaImpl(feature, originRevision.size(feature));
+ listFeatureDelta.add(clearFeatureDelta);
+ result[0] = listFeatureDelta;
+ }
+ });
+
+ return result[0];
+ }
+
@Override
public String toString()
{
@@ -713,3 +745,14 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
}
}
}
+
+/**
+ * @author Eike Stepper
+ * @since 4.8
+ */
+interface ListComparisonHandler
+{
+ public void addDelta(CDOListFeatureDelta listFeatureDelta);
+
+ public void addClearDelta(CDOClearFeatureDelta clearFeatureDelta, CDOOriginSizeProvider originSizeProvider);
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
index 97600f60a9..038cb5fc6f 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/branch/InternalCDOBranchManager.java
@@ -119,6 +119,11 @@ public interface InternalCDOBranchManager extends CDOBranchManager, ILifecycle
public SubBranchInfo[] loadSubBranches(int branchID);
+ /**
+ * @param startID the {@link CDOBranch#getID() id} of the first branch to load.
+ * @param endID the {@link CDOBranch#getID() id} of the last branch to load, or 0 (zero) to load all branches
+ * after and including the first branch.
+ */
public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler);
/**
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/InternalCDORevisionManager.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/InternalCDORevisionManager.java
index e638095c22..56bb4f2218 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/InternalCDORevisionManager.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/InternalCDORevisionManager.java
@@ -89,6 +89,11 @@ public interface InternalCDORevisionManager extends CDORevisionManager, CDORevis
public InternalCDORevision getRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk, boolean loadOnDemand);
/**
+ * @since 4.8
+ */
+ public InternalCDORevision getBaseRevision(CDORevision revision, int referenceChunk, boolean loadOnDemand);
+
+ /**
* If the meaning of this type isn't clear, there really should be more of a description here...
*
* @author Eike Stepper

Back to the top