Search in sources :

Example 1 with DataSource

use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.

the class DatabaseImportHelper method importDatabaseIntoModel.

public static boolean importDatabaseIntoModel(DatabaseInfos databaseInfos, String modelFilename, Collection<IFile> referencedFiles) {
    DataSource dataSource = databaseInfos.getDataSource();
    // Override this resolver to resolve external dependencies (i.e.: tables store in another schema)
    MultiDataBaseQueries queries = new MultiDataBaseQueries();
    for (IFile referencedFile : referencedFiles) {
        addFileToResolver(queries, referencedFile);
    }
    ImportRunnable runnable = new ImportRunnable(dataSource, modelFilename, queries);
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
    } catch (Exception e) {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while importing database", e));
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error occured while importing database", "An error occured while importing the database. See Error Log view for more details.");
    }
    return runnable.getResult();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) MultiDataBaseQueries(org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource)

Example 2 with DataSource

use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.

the class TestReverse method testMySQL.

@Test
public void testMySQL() {
    DataSource dataSource = new DataSource("northwind", null);
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/northwind");
    dataSource.setJdbcUsername("root");
    dataSource.setJdbcPassword(null);
    dataSource.setVendor("MySQL-5");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/mysql/outputRef.database", "pathmap://NativeDBTypes/MySQL-5");
    checkEquality(database, databaseRef);
}
Also used : MultiDataBaseQueries(org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource) DataBase(org.obeonetwork.dsl.database.DataBase) Test(org.junit.Test)

Example 3 with DataSource

use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.

the class TestReverse method testSQLServer.

@Test
public void testSQLServer() {
    DataSource dataSource = new DataSource("Northwind", "dbo");
    dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=Northwind");
    dataSource.setJdbcUsername("testUser");
    dataSource.setJdbcPassword("test");
    dataSource.setVendor("SQLServer-2008");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/sqlserver/outputRef.database", "pathmap://NativeDBTypes/SQLServer-2008");
    checkEquality(database, databaseRef);
}
Also used : MultiDataBaseQueries(org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource) DataBase(org.obeonetwork.dsl.database.DataBase) Test(org.junit.Test)

Example 4 with DataSource

use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.

the class TestReverse method testH2Embedded.

@Test
public void testH2Embedded() {
    String databaseLocation = getH2DatabaseLocation(this.getClass(), "input");
    DataSource dataSource = new DataSource("appli1", "PUBLIC");
    dataSource.setJdbcUrl("jdbc:h2:" + databaseLocation);
    dataSource.setJdbcUsername("sa");
    dataSource.setVendor("H2-1.3");
    DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
    DataBase databaseRef = loadModel("resources/h2/outputRef.database", "pathmap://NativeDBTypes/H2-1.3");
    checkEquality(database, databaseRef);
}
Also used : MultiDataBaseQueries(org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource) DataBase(org.obeonetwork.dsl.database.DataBase) Test(org.junit.Test)

Example 5 with DataSource

use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.

the class DatabaseImportWizard method performFinish.

/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
public boolean performFinish() {
    // First, check if a connection to the database can be established
    if (databaseInfos != null) {
        Connection connection = null;
        DataSource dataSource = databaseInfos.getDataSource();
        if (dataSource != null) {
            try {
                connection = dataSource.getConnection();
            } catch (DataSourceException e) {
                // Unable to connect
                String message = "Unable to connect to database.\n\nReason : " + e.getCause().getMessage();
                MessageDialog.openError(getShell(), "Import database...", message);
                return false;
            } finally {
                JdbcUtils.closeConnection(connection);
            }
        }
    }
    String filename = mainPage.getTxtModelFile().getText();
    boolean result = DatabaseImportHelper.importDatabaseIntoModel(databaseInfos, filename, mainPage.getReferencedFiles());
    if (result == true) {
        MessageDialog.openInformation(getShell(), "Database imported", "The database has been imported.\nThe model file '" + filename + "' has been created.");
        IViewPart explorer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.ui.navigator.ProjectExplorer");
        if (explorer != null) {
            if (explorer instanceof ProjectExplorer) {
                ProjectExplorer projectExplorer = (ProjectExplorer) explorer;
                // Create a selection to point on the generated file
                final IFile generatedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
                projectExplorer.selectReveal(new StructuredSelection(generatedFile));
            }
        }
    } else {
        MessageDialog.openError(getShell(), "Error while importing database", "The database could not be imported.");
    }
    return result;
}
Also used : ProjectExplorer(org.eclipse.ui.navigator.resources.ProjectExplorer) Path(org.eclipse.core.runtime.Path) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) DataSourceException(org.obeonetwork.dsl.database.reverse.source.DataSourceException) Connection(java.sql.Connection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DataSource(org.obeonetwork.dsl.database.reverse.source.DataSource)

Aggregations

DataSource (org.obeonetwork.dsl.database.reverse.source.DataSource)9 MultiDataBaseQueries (org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries)7 Test (org.junit.Test)6 DataBase (org.obeonetwork.dsl.database.DataBase)6 IFile (org.eclipse.core.resources.IFile)2 Connection (java.sql.Connection)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IViewPart (org.eclipse.ui.IViewPart)1 ProjectExplorer (org.eclipse.ui.navigator.resources.ProjectExplorer)1 DataSourceException (org.obeonetwork.dsl.database.reverse.source.DataSourceException)1