Search in sources :

Example 1 with DatabaseResourceImpl

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;
}
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 2 with DatabaseResourceImpl

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);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DatabaseResourceImpl(org.obeonetwork.dsl.database.util.DatabaseResourceImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)2 DatabaseResourceImpl (org.obeonetwork.dsl.database.util.DatabaseResourceImpl)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IResource (org.eclipse.core.resources.IResource)1 Comparison (org.eclipse.emf.compare.Comparison)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 ISelection (org.eclipse.jface.viewers.ISelection)1 DataBase (org.obeonetwork.dsl.database.DataBase)1 Schema (org.obeonetwork.dsl.database.Schema)1 TableContainer (org.obeonetwork.dsl.database.TableContainer)1