use of org.obeonetwork.dsl.database.util.DatabaseResourceImpl 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.obeonetwork.dsl.database.util.DatabaseResourceImpl in project InformationSystem by ObeoNetwork.
the class ImportRunnable method saveIntoFile.
private void saveIntoFile(DataBase database, String filename) throws IOException {
ResourceSet set = new ResourceSetImpl();
Resource resource = set.createResource(URI.createPlatformResourceURI(filename, true));
((DatabaseResourceImpl) resource).setEncoding(ResourcesPlugin.getEncoding());
resource.getContents().add(database);
resource.save(null);
}
Aggregations