Search in sources :

Example 1 with Comparison

use of org.eclipse.emf.compare.Comparison in project tdq-studio-se by Talend.

the class DQReferenceMerger method addInTarget.

/*
     * override this method to fix a specail case: when add a catalog on database server,this new one can't be added in
     * local db connection
     */
@Override
protected void addInTarget(ReferenceChange diff, boolean rightToLeft) {
    final Match match = diff.getMatch();
    final EObject expectedContainer;
    if (rightToLeft) {
        expectedContainer = match.getLeft();
    } else {
        expectedContainer = match.getRight();
    }
    if (expectedContainer == null) {
        // one of the "required" diffs should have created our container.
        return;
    }
    final Comparison comparison = match.getComparison();
    final EReference reference = diff.getReference();
    final EObject expectedValue;
    final Match valueMatch = comparison.getMatch(diff.getValue());
    if (valueMatch == null) {
        // This is an out of scope value.
        if (diff.getValue().eIsProxy()) {
            // Copy the proxy
            expectedValue = EcoreUtil.copy(diff.getValue());
        } else {
            // Use the same value.
            expectedValue = diff.getValue();
        }
    } else if (rightToLeft) {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setLeft(expectedValue);
        } else {
            // qiongli: when I add catalog on remote server,test on reload, should replace "valueMatch.getLeft()"
            // with "valueMatch.getRight()" at here.
            // expectedValue = valueMatch.getLeft();
            expectedValue = valueMatch.getRight();
            // qiongli: remove the newest DataManage from the right Catalog or Schema,avoid a missing
            // "datamanage herf=" "
            Catalog catlog = SwitchHelpers.CATALOG_SWITCH.doSwitch(expectedValue);
            Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(expectedValue);
            if (catlog != null) {
                EList<DataManager> dataManager = catlog.getDataManager();
                dataManager.clear();
            } else if (schema != null) {
                EList<DataManager> dataManager = schema.getDataManager();
                dataManager.clear();
            }
        }
    } else {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setRight(expectedValue);
        } else {
            expectedValue = valueMatch.getLeft();
        }
    }
    // We have the container, reference and value. We need to know the insertion index.
    if (reference.isMany()) {
        final int insertionIndex = findInsertionIndex(comparison, diff, rightToLeft);
        final List<EObject> targetList = (List<EObject>) safeEGet(expectedContainer, reference);
        addAt(targetList, expectedValue, insertionIndex);
    } else {
        safeESet(expectedContainer, reference, expectedValue);
    }
    if (reference.isContainment()) {
        // Copy XMI ID when applicable.
        final Resource initialResource = diff.getValue().eResource();
        final Resource targetResource = expectedValue.eResource();
        if (initialResource instanceof XMIResource && targetResource instanceof XMIResource) {
            ((XMIResource) targetResource).setID(expectedValue, ((XMIResource) initialResource).getID(diff.getValue()));
        }
    }
// no need to check this for DQ items,
// checkImpliedDiffsOrdering(diff, rightToLeft);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Catalog(orgomg.cwm.resource.relational.Catalog) Match(org.eclipse.emf.compare.Match) EList(org.eclipse.emf.common.util.EList) Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) EReference(org.eclipse.emf.ecore.EReference)

Example 2 with Comparison

use of org.eclipse.emf.compare.Comparison in project tdq-studio-se by Talend.

the class DataProviderComparisonLevel method compareWithReloadObject.

@Override
protected boolean compareWithReloadObject() throws ReloadCompareException {
    Map<ResourceSet, List<Resource>> rsJrxmlMap = removeJrxmlsFromResourceSet();
    EMFCompare comparator = createDefaultEMFCompare();
    IComparisonScope scope = new DefaultComparisonScope(oldDataProvider, getSavedReloadObject(), null);
    Comparison compare = comparator.compare(scope);
    // add the jrxml into the ResourceSet after doMatch
    addJrxmlsIntoResourceSet(rsJrxmlMap);
    EList<Diff> differences = compare.getDifferences();
    for (Diff diff : differences) {
        // ignore the move Kind
        if (diff.getKind() == DifferenceKind.MOVE) {
            continue;
        }
        if (diff instanceof ReferenceChange) {
            EObject value = ((ReferenceChange) diff).getValue();
            if (isCatalogOrSchema(value)) {
                copyRightToLeft(diff);
            }
        }
    }
    return true;
}
Also used : DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) EMFCompare(org.eclipse.emf.compare.EMFCompare) Comparison(org.eclipse.emf.compare.Comparison) Diff(org.eclipse.emf.compare.Diff) EObject(org.eclipse.emf.ecore.EObject) ReferenceChange(org.eclipse.emf.compare.ReferenceChange) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope)

Example 3 with Comparison

use of org.eclipse.emf.compare.Comparison in project tdq-studio-se by Talend.

the class TableViewComparisonLevel method compareWithReloadObject.

@Override
protected boolean compareWithReloadObject() throws ReloadCompareException {
    // remove the jrxml from the ResourceSet before doMatch
    Map<ResourceSet, List<Resource>> rsJrxmlMap = removeJrxmlsFromResourceSet();
    DBColumnFolderRepNode columnFolderRepNode = (DBColumnFolderRepNode) selectedObj;
    // Compare the two models
    EMFCompare comparator = createDefaultEMFCompare();
    IComparisonScope scope = new DefaultComparisonScope(columnFolderRepNode.getColumnSet(), getSavedReloadObject(), null);
    Comparison compare = comparator.compare(scope);
    // add the jrxml into the ResourceSet after doMatch
    addJrxmlsIntoResourceSet(rsJrxmlMap);
    EList<Diff> differences = compare.getDifferences();
    for (Diff diff : differences) {
        // ignore the move Kind
        if (diff.getKind() == DifferenceKind.MOVE) {
            continue;
        }
        // copy right to left
        copyRightToLeft(diff);
    }
    return true;
}
Also used : DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) EMFCompare(org.eclipse.emf.compare.EMFCompare) Comparison(org.eclipse.emf.compare.Comparison) Diff(org.eclipse.emf.compare.Diff) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope) DBColumnFolderRepNode(org.talend.dq.nodes.DBColumnFolderRepNode)

Example 4 with Comparison

use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.

the class GenerateSQLFromDatabaseHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    // We have to compute an emfdiff file from a comparison with an empty database
    // ---
    // First let's create an empty model containing only
    Resource resource = new DatabaseResourceImpl(URI.createURI("memory:/empty_database"));
    TableContainer rootContainer = getFirstTableContainer(selection);
    TableContainer newContainer = null;
    if (rootContainer instanceof DataBase) {
        newContainer = copyDatabase((DataBase) rootContainer);
        resource.getContents().add(newContainer);
    } else if (rootContainer instanceof Schema) {
        newContainer = copySchema((Schema) rootContainer);
        resource.getContents().add(newContainer);
    }
    // Then compare the two models
    Comparison comparison = null;
    try {
        comparison = DatabaseCompareService.compare(rootContainer, newContainer);
    } catch (Exception e) {
    }
    // The diff model can now be used to generate the SQL script
    if (comparison != null) {
        ExportAsSQLScriptsAction action = new ExportAsSQLScriptsAction();
        action.exportComparison(comparison);
    }
    return null;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) TableContainer(org.obeonetwork.dsl.database.TableContainer) DatabaseResourceImpl(org.obeonetwork.dsl.database.util.DatabaseResourceImpl) Schema(org.obeonetwork.dsl.database.Schema) ISelection(org.eclipse.jface.viewers.ISelection) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ExecutionException(org.eclipse.core.commands.ExecutionException) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 5 with Comparison

use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.

the class AbstractDatabaseCompareTest method testDatabaseCompare.

public void testDatabaseCompare(String folder) {
    TableContainer tableContainer1 = (TableContainer) loadRootObject(folder, INPUT_DATABASE_1, TableContainer.class);
    TableContainer tableContainer2 = (TableContainer) loadRootObject(folder, INPUT_DATABASE_2, TableContainer.class);
    // Comparison expectedSnapshot = (Comparison)loadRootObject(folder, EXPECTED_COMPARISON, Comparison.class);
    Comparison actualSnapshot = null;
    try {
        actualSnapshot = DatabaseCompareService.compare(tableContainer1, tableContainer2);
    } catch (Exception e) {
        Assert.fail("Exception during comparison : " + e.getMessage());
    }
    try {
        Generate generate = new Generate(actualSnapshot, new File("models/" + folder), new ArrayList<Object>());
        generate.doGenerate(new BasicMonitor());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) TableContainer(org.obeonetwork.dsl.database.TableContainer) Generate(org.obeonetwork.dsl.database.compare.tests.gen.main.Generate) EObject(org.eclipse.emf.ecore.EObject) IOException(java.io.IOException) File(java.io.File) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor) IOException(java.io.IOException)

Aggregations

Comparison (org.eclipse.emf.compare.Comparison)22 Diff (org.eclipse.emf.compare.Diff)7 DefaultComparisonScope (org.eclipse.emf.compare.scope.DefaultComparisonScope)7 IComparisonScope (org.eclipse.emf.compare.scope.IComparisonScope)7 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 EMFCompare (org.eclipse.emf.compare.EMFCompare)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 EObject (org.eclipse.emf.ecore.EObject)5 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 TableContainer (org.obeonetwork.dsl.database.TableContainer)4 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)3 BasicMonitor (org.eclipse.emf.common.util.BasicMonitor)2 Match (org.eclipse.emf.compare.Match)2 Test (org.junit.Test)2 DataBase (org.obeonetwork.dsl.database.DataBase)2 URISyntaxException (java.net.URISyntaxException)1