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);
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations