Search in sources :

Example 1 with DatabaseGen

use of org.obeonetwork.dsl.database.sqlgen.DatabaseGen in project InformationSystem by ObeoNetwork.

the class DatabaseEvolutionScriptGenerationTestSuite method generateEvolutionScripts.

private List<File> generateEvolutionScripts(Comparison dbevolution) {
    final File targetBaseFolder = new File("sql-gen/");
    System.out.println("Generating to: " + targetBaseFolder.getAbsolutePath());
    // // Initialize a resourceset to be sure the model is contained within
    // a
    // // resource (or Acceleo will throw a NPE)
    // ResourceSet set = new ResourceSetImpl();
    // Resource resource = new ResourceImpl();
    // resource.getContents().add(dbevolution);
    // set.getResources().add(resource);
    List<File> generatedFiles = new ArrayList<>();
    try {
        DatabaseGen databaseGen = new DatabaseGen(dbevolution, targetBaseFolder, Collections.emptyList());
        databaseGen.doGenerate(new BasicMonitor());
        // for (String maybeGeneratedFileName : DatabaseGen.SQL_FILES) {
        // File maybeGeneratedFile = new File(databaseGen.getTargetFolder(),
        // maybeGeneratedFileName);
        // if (maybeGeneratedFile.exists()) {
        // generatedFiles.add(maybeGeneratedFile);
        // }
        // }
        generatedFiles.add(new File(databaseGen.getTargetFolder(), "all.sql"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return generatedFiles;
}
Also used : DatabaseGen(org.obeonetwork.dsl.database.sqlgen.DatabaseGen) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor)

Example 2 with DatabaseGen

use of org.obeonetwork.dsl.database.sqlgen.DatabaseGen in project InformationSystem by ObeoNetwork.

the class AbstractSQLGenerationTest method assertGenerationEquals.

public void assertGenerationEquals(TableContainer source, TableContainer target, String expectationsFolderPath) {
    File targetFolder = createTargetFolder();
    File expectationsFolder = createExpectationsFolder(expectationsFolderPath);
    try {
        // Compare
        Comparison comparison = DatabaseCompareService.compare(source, target);
        // and generate sql scripts based on the comparison
        DatabaseGen generator = new DatabaseGen(comparison, targetFolder, Collections.emptyList());
        generator.doGenerate(new BasicMonitor());
    } catch (Exception e) {
        deleteFile(targetFolder);
        deleteFile(expectationsFolder);
        fail("Comparison failed with an exception : " + e.getMessage());
    }
    compareFolders(targetFolder, expectationsFolder);
    // Delete targetFolder and expectationsFolder
    deleteFile(targetFolder);
    deleteFile(expectationsFolder);
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) DatabaseGen(org.obeonetwork.dsl.database.sqlgen.DatabaseGen) File(java.io.File) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 3 with DatabaseGen

use of org.obeonetwork.dsl.database.sqlgen.DatabaseGen in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method exportComparison.

public void exportComparison(final Comparison comparison) {
    final IResource containingFolder = getContainingFolder(comparison);
    if (containingFolder == null) {
        // No containing folder means the user aborted the export action
        return;
    }
    final File targetFolder = getTargetfolder(containingFolder);
    if (targetFolder == null) {
        return;
    }
    // Initialize a resourceset to be sure the model is contained within a resource (or Acceleo will throw a NPE)
    ResourceSet set = new ResourceSetImpl();
    Resource resource = new ResourceImpl();
    resource.getContents().add(comparison);
    set.getResources().add(resource);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
            try {
                DatabaseGen databaseGen = new DatabaseGen(comparison, targetFolder, Collections.emptyList());
                databaseGen.doGenerate(new BasicMonitor());
            } catch (IOException e) {
                MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "SQL Generation", "A problem occured during the generation. See Error Log view for more details.");
                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
            }
            // Refreshing the target folder
            try {
                containingFolder.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
            } catch (CoreException e) {
                IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                Activator.getDefault().getLog().log(status);
            }
        }
    };
    // Launch operation
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, false, operation);
    } catch (Exception e) {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "SQL Generation", "A problem occured during the generation. See Error Log view for more details.");
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) DatabaseGen(org.obeonetwork.dsl.database.sqlgen.DatabaseGen) Resource(org.eclipse.emf.ecore.resource.Resource) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) IResource(org.eclipse.core.resources.IResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

File (java.io.File)3 IOException (java.io.IOException)3 BasicMonitor (org.eclipse.emf.common.util.BasicMonitor)3 DatabaseGen (org.obeonetwork.dsl.database.sqlgen.DatabaseGen)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 CDOResource (org.eclipse.emf.cdo.eresource.CDOResource)1 Comparison (org.eclipse.emf.compare.Comparison)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 ILocalResource (org.eclipse.team.svn.core.resource.ILocalResource)1 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)1