Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-10-01 12:32:05 +0000
committerEike Stepper2012-10-01 12:32:05 +0000
commite9a7ae8e260eac1d7aef3506979eb355641316b9 (patch)
tree0785116d661e6d56f552f2e46f245c865bdc2dc4
parent54e89a4372508356f689196a8a0927e78b3ff605 (diff)
downloadcdo-e9a7ae8e260eac1d7aef3506979eb355641316b9.tar.gz
cdo-e9a7ae8e260eac1d7aef3506979eb355641316b9.tar.xz
cdo-e9a7ae8e260eac1d7aef3506979eb355641316b9.zip
[390808] Integrate CDO with EMF Compare
https://bugs.eclipse.org/bugs/show_bug.cgi?id=390808
-rw-r--r--plugins/org.eclipse.emf.cdo.compare/src/org/eclipse/emf/cdo/compare/CDOCompareUtil.java98
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFCompareTest.java29
2 files changed, 56 insertions, 71 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 5fbd17baf8..3158ecc3dc 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
@@ -16,13 +16,12 @@ import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
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.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.emf.common.notify.Notifier;
@@ -64,6 +63,7 @@ public final class CDOCompareUtil
public static CDOComparison compare(CDOView leftView, CDOBranchPoint right, boolean threeWay)
{
+ Set<Object> objectsToDeactivateOnClose = new HashSet<Object>();
CDOSession session = leftView.getSession();
CDOView rightView;
@@ -78,6 +78,7 @@ public final class CDOCompareUtil
else
{
rightView = session.openView(right);
+ objectsToDeactivateOnClose.add(rightView);
}
CDOView originView = null;
@@ -87,6 +88,7 @@ public final class CDOCompareUtil
if (!ancestor.equals(leftView) && !ancestor.equals(rightView))
{
originView = session.openView(ancestor);
+ objectsToDeactivateOnClose.add(originView);
}
}
@@ -103,7 +105,7 @@ public final class CDOCompareUtil
}
IComparisonScope scope = new CDOComparisonScope.Minimal(leftView, rightView, originView, ids);
- return createComparison(scope, leftView, rightView, originView);
+ return createComparison(scope, objectsToDeactivateOnClose);
}
public static CDOComparison compare(EObject leftRoot, CDOBranchPoint right)
@@ -113,6 +115,8 @@ public final class CDOCompareUtil
public static CDOComparison compare(EObject leftRoot, CDOBranchPoint right, boolean threeWay)
{
+ Set<Object> objectsToDeactivateOnClose = new HashSet<Object>();
+
CDOObject leftObject = CDOUtil.getCDOObject(leftRoot);
CDOView leftView = leftObject.cdoView();
CDOBranchPoint left = CDOBranchUtil.copyBranchPoint(leftView);
@@ -130,6 +134,7 @@ public final class CDOCompareUtil
else
{
rightView = session.openView(right);
+ objectsToDeactivateOnClose.add(rightView);
}
Notifier rightObject = rightView.getObject(leftObject);
@@ -143,11 +148,12 @@ public final class CDOCompareUtil
{
originView = session.openView(ancestor);
originObject = originView.getObject(leftObject);
+ objectsToDeactivateOnClose.add(originView);
}
}
IComparisonScope scope = new CDOComparisonScope.AllContents(leftObject, rightObject, originObject);
- return createComparison(scope, leftView, rightView, originView);
+ return createComparison(scope, objectsToDeactivateOnClose);
}
private static EMFCompare createComparator(IComparisonScope scope)
@@ -160,12 +166,11 @@ public final class CDOCompareUtil
return comparator;
}
- private static CDOComparison createComparison(IComparisonScope scope, CDOView leftView, CDOView rightView,
- CDOView originView)
+ private static CDOComparison createComparison(IComparisonScope scope, Set<Object> objectsToDeactivateOnClose)
{
EMFCompare comparator = createComparator(scope);
Comparison comparison = comparator.compare();
- return new CDOComparison(comparison, leftView, rightView, originView);
+ return new CDOComparison(comparison, objectsToDeactivateOnClose);
}
/**
@@ -173,68 +178,34 @@ public final class CDOCompareUtil
*/
public static class CDOComparison extends DelegatingComparison implements CloseableComparison
{
- private CDOView leftView;
-
- private CDOView rightView;
-
- private CDOView originView;
+ private Set<Object> objectsToDeactivateOnClose;
- public CDOComparison(Comparison delegate, CDOView leftView, CDOView rightView, CDOView originView)
+ public CDOComparison(Comparison delegate, Set<Object> objectsToDeactivateOnClose)
{
super(delegate);
- this.leftView = leftView;
- this.rightView = rightView;
- this.originView = originView;
-
- leftView.addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- close();
- }
- });
- }
-
- public CDOView getLeftView()
- {
- return leftView;
+ this.objectsToDeactivateOnClose = objectsToDeactivateOnClose;
}
- public CDOView getRightView()
- {
- return rightView;
- }
-
- public CDOView getOriginView()
+ public boolean isClosed()
{
- return originView;
+ return delegate == null;
}
public void close()
{
- close(false);
- }
-
- public void close(boolean closeLeftView)
- {
- if (closeLeftView)
+ if (delegate != null)
{
- LifecycleUtil.deactivate(leftView);
- }
-
- LifecycleUtil.deactivate(rightView);
- LifecycleUtil.deactivate(originView);
-
- leftView = null;
- rightView = null;
- originView = null;
- delegate = null;
- }
+ delegate = null;
+ if (objectsToDeactivateOnClose != null)
+ {
+ for (Object object : objectsToDeactivateOnClose)
+ {
+ LifecycleUtil.deactivate(object);
+ }
- public boolean isClosed()
- {
- return delegate == null;
+ objectsToDeactivateOnClose = null;
+ }
+ }
}
}
@@ -283,8 +254,7 @@ public final class CDOCompareUtil
public Minimal(CDOView leftView, CDOView rightView, CDOView originView, Set<CDOID> ids)
{
- super(leftView.getRootResource(), rightView.getRootResource(), originView != null ? originView
- .getRootResource() : null);
+ super(getRoot(leftView), getRoot(rightView), getRoot(originView));
this.ids = ids;
Set<CDOID> requiredParentIDs = new HashSet<CDOID>();
@@ -343,6 +313,16 @@ public final class CDOCompareUtil
}
}
}
+
+ private static CDOResource getRoot(CDOView view)
+ {
+ if (view == null)
+ {
+ return null;
+ }
+
+ return view.getRootResource();
+ }
}
}
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 ae5303508d..645f7f2b9f 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
@@ -34,34 +34,34 @@ import org.eclipse.emf.ecore.EObject;
public class EMFCompareTest extends AbstractCDOTest
{
@SuppressWarnings("unused")
- public void testAllContentsOfRoot() throws Exception
+ public void testAllContentsOfCompany() throws Exception
{
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/res1"));
-
+
Company company = createCompany();
company.setName("ESC");
-
+
resource.getContents().add(company);
resource.getContents().add(createCompany());
resource.getContents().add(createCompany());
CDOCommitInfo commit1 = transaction.commit();
-
+
company.setName("Sympedia");
CDOCommitInfo commit2 = transaction.commit();
-
+
company.setName("Eclipse");
CDOCommitInfo commit3 = transaction.commit();
-
+
// CloseableComparison comparison = CDOCompareUtil.compare(session.openView(commit2).getObject(company), commit3);
- CDOComparison comparison = CDOCompareUtil.compare(transaction.getRootResource(), commit2);
- dump(comparison.getMatches(), "");
+ CDOComparison comparison = CDOCompareUtil.compare(company, commit2);
+ dump(comparison);
comparison.close();
}
@SuppressWarnings("unused")
- public void testAllContentsOfCompany() throws Exception
+ public void testAllContentsOfRoot() throws Exception
{
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
@@ -82,8 +82,8 @@ public class EMFCompareTest extends AbstractCDOTest
CDOCommitInfo commit3 = transaction.commit();
// CloseableComparison comparison = CDOCompareUtil.compare(session.openView(commit2).getObject(company), commit3);
- CDOComparison comparison = CDOCompareUtil.compare(company, commit2);
- dump(comparison.getMatches(), "");
+ CDOComparison comparison = CDOCompareUtil.compare(transaction.getRootResource(), commit2);
+ dump(comparison);
comparison.close();
}
@@ -109,7 +109,7 @@ public class EMFCompareTest extends AbstractCDOTest
// CloseableComparison comparison = CDOCompareUtil.compare(session.openView(commit2).getObject(company), commit3);
CDOComparison comparison = CDOCompareUtil.compare(transaction, commit2);
- dump(comparison.getMatches(), "");
+ dump(comparison);
comparison.close();
}
@@ -124,6 +124,11 @@ public class EMFCompareTest extends AbstractCDOTest
return company;
}
+ private static void dump(CDOComparison comparison)
+ {
+ dump(comparison.getMatches(), "");
+ }
+
private static void dump(EList<Match> matches, String indent)
{
for (Match match : matches)

Back to the top