Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-16 02:43:19 -0400
committerEike Stepper2013-03-16 08:01:29 -0400
commit111567554018262873122a1aef4d96288b577253 (patch)
tree763820688601ab51da28299b5face1b4df5054af
parentca8fbe26ff533db2ae0a2172a403821a9750d345 (diff)
downloadcdo-111567554018262873122a1aef4d96288b577253.tar.gz
cdo-111567554018262873122a1aef4d96288b577253.tar.xz
cdo-111567554018262873122a1aef4d96288b577253.zip
[403516] Provide EMF Comparisons for the uncommitted changes of a
CDOTransaction https://bugs.eclipse.org/bugs/show_bug.cgi?id=403516
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java71
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java56
3 files changed, 123 insertions, 28 deletions
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
index 87ccff36f9..0d7e7bceb3 100644
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
+++ b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.compare.CDOComparisonScope.Minimal;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -91,10 +92,7 @@ public final class CDOCompareUtil
public static Comparison compare(CDOObject left, CDOView rightView, CDOView[] originView)
{
CDOView leftView = left.cdoView();
- if (leftView.getSession() != rightView.getSession())
- {
- throw new IllegalArgumentException("Sessions are different");
- }
+ assertSameSession(leftView, rightView);
CDOView view = openOriginView(leftView, rightView, originView);
@@ -113,28 +111,40 @@ public final class CDOCompareUtil
*/
public static Comparison compare(CDOView leftView, CDOView rightView, CDOView[] originView)
{
- InternalCDOSession session = (InternalCDOSession)leftView.getSession();
- if (rightView.getSession() != session)
- {
- throw new IllegalArgumentException("Sessions are different");
- }
+ assertSameSession(leftView, rightView);
CDOView view = openOriginView(leftView, rightView, originView);
+ Set<CDOID> ids = getAffectedIDs(leftView, rightView, view);
+ return createComparison(leftView, rightView, view, ids);
+ }
- Set<CDOID> ids;
- if (view != null)
- {
- MergeData mergeData = session.getMergeData(leftView, rightView, view, false);
- ids = mergeData.getIDs();
- }
- else
+ public static Comparison compare(CDOView leftView, CDOView rightView, CDOView[] originView, Set<CDOID> ids)
+ {
+ assertSameSession(leftView, rightView);
+
+ CDOView view = openOriginView(leftView, rightView, originView);
+ return createComparison(leftView, rightView, view, ids);
+ }
+
+ public static Comparison compareUncommittedChanges(CDOTransaction transaction)
+ {
+ CDOSession session = transaction.getSession();
+ CDOView lastView = session.openView(transaction.getLastUpdateTime());
+
+ Set<CDOID> ids = new HashSet<CDOID>();
+ ids.addAll(transaction.getNewObjects().keySet());
+ ids.addAll(transaction.getDirtyObjects().keySet());
+ ids.addAll(transaction.getDetachedObjects().keySet());
+
+ return createComparison(transaction, lastView, null, ids);
+ }
+
+ private static void assertSameSession(CDOView view1, CDOView view2)
+ {
+ if (view1.getSession() != view2.getSession())
{
- CDOChangeSetData changeSetData = leftView.compareRevisions(rightView);
- ids = new HashSet<CDOID>(changeSetData.getChangeKinds().keySet());
+ throw new IllegalArgumentException("Sessions are different");
}
-
- IComparisonScope scope = new CDOComparisonScope.Minimal(leftView, rightView, view, ids);
- return createComparison(scope);
}
private static CDOView openOriginView(CDOView leftView, CDOView rightView, CDOView[] originView)
@@ -162,6 +172,25 @@ public final class CDOCompareUtil
return null;
}
+ private static Set<CDOID> getAffectedIDs(CDOView leftView, CDOView rightView, CDOView originView)
+ {
+ if (originView != null)
+ {
+ InternalCDOSession session = (InternalCDOSession)leftView.getSession();
+ MergeData mergeData = session.getMergeData(leftView, rightView, originView, false);
+ return mergeData.getIDs();
+ }
+
+ CDOChangeSetData changeSetData = leftView.compareRevisions(rightView);
+ return new HashSet<CDOID>(changeSetData.getChangeKinds().keySet());
+ }
+
+ private static Comparison createComparison(CDOView leftView, CDOView rightView, CDOView originView, Set<CDOID> ids)
+ {
+ IComparisonScope scope = new CDOComparisonScope.Minimal(leftView, rightView, originView, ids);
+ return createComparison(scope);
+ }
+
private static Comparison createComparison(IComparisonScope scope)
{
Function<EObject, String> idFunction = new CDOIDFunction();
diff --git a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
index 585f398193..7586650ce8 100644
--- a/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
+++ b/plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOComparisonScope.java
@@ -11,9 +11,10 @@
package org.eclipse.emf.cdo.compare;
import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionData;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
@@ -142,13 +143,24 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
private void collectRequiredParentIDs(CDOObject object, Set<CDOID> requiredParentIDs)
{
+ CDOState state = object.cdoState();
+ if (state == CDOState.TRANSIENT)
+ {
+ return;
+ }
+
CDOView view = object.cdoView();
- CDORevision revision = object.cdoRevision();
+ if (state == CDOState.PROXY)
+ {
+ CDOUtil.load(object, view);
+ }
+
+ CDORevisionData revisionData = object.cdoRevision().data();
- CDOID containerID = (CDOID)revision.data().getContainerID();
+ CDOID containerID = (CDOID)revisionData.getContainerID();
collectRequiredParentIDs(view, containerID, requiredParentIDs);
- CDOID resourceID = revision.data().getResourceID();
+ CDOID resourceID = revisionData.getResourceID();
collectRequiredParentIDs(view, resourceID, requiredParentIDs);
}
@@ -156,10 +168,8 @@ public abstract class CDOComparisonScope extends AbstractComparisonScope
{
if (!CDOIDUtil.isNull(id))
{
- if (!ids.contains(id) && !requiredParentIDs.contains(id))
+ if (!ids.contains(id) && requiredParentIDs.add(id))
{
- requiredParentIDs.add(id);
-
collectRequiredParentID(view, id, requiredParentIDs);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
index 87e015322d..294a62a540 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java
@@ -180,6 +180,62 @@ public class EMFCompareTest extends AbstractCDOTest
assertEquals(0, match.getDifferences().size());
}
+ public void testChanges() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ Company company = getModel1Factory().createCompany();
+ company.setName("Company");
+ resource.getContents().add(company);
+
+ Category category1 = getModel1Factory().createCategory();
+ category1.setName("Category1");
+ company.getCategories().add(category1);
+
+ transaction.commit();
+
+ // Change category1
+ category1.setName("CHANGED");
+
+ Category category2 = getModel1Factory().createCategory();
+ category2.setName("Category2");
+
+ // Change company, add category2
+ company.getCategories().add(category2);
+
+ Comparison comparison = CDOCompareUtil.compareUncommittedChanges(transaction);
+ dump(comparison);
+
+ assertEquals(1, comparison.getMatch(category1).getDifferences().size());
+ assertEquals(1, comparison.getMatch(company).getDifferences().size());
+ }
+
+ public void testChangesDelete() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res1"));
+
+ Company company = getModel1Factory().createCompany();
+ company.setName("Company");
+ resource.getContents().add(company);
+
+ Category category = getModel1Factory().createCategory();
+ category.setName("Category");
+ company.getCategories().add(category);
+
+ transaction.commit();
+
+ company.getCategories().clear();
+
+ Comparison comparison = CDOCompareUtil.compareUncommittedChanges(transaction);
+ dump(comparison);
+
+ assertEquals(1, comparison.getMatch(company).getDifferences().size());
+ }
+
private Company createCompany()
{
Company company = getModel1Factory().createCompany();

Back to the top