Search in sources :

Example 1 with DataSourceException

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

the class AbstractDataBaseBuilder method initialize.

private void initialize(DataSource source, ProgressListener progressListener, Queries queries) throws SQLException {
    connection = null;
    try {
        connection = source.getConnection();
    } catch (DataSourceException e) {
        throw new SQLException("Unable to connect to database", e.getCause());
    }
    if (connection != null) {
        try {
            this.metaData = connection.getMetaData();
        } catch (SQLException e) {
            JdbcUtils.closeConnection(connection);
            throw e;
        }
    }
    this.progressListener = progressListener;
    if (this.progressListener == null) {
        this.progressListener = new ProgressListener() {

            @Override
            public void start(int numberOfSteps) {
            }

            @Override
            public void progressTo(int step, String message) {
            }

            @Override
            public void end(String message) {
            }
        };
    }
    this.queries = queries;
    dataBase = buildDataBase(source.getDatabaseName());
    queries.registerDatabase(dataBase);
    tableContainer = dataBase;
    if (isSet(source.getSchemaName())) {
        tableContainer = buildSchema(source.getSchemaName(), (DataBase) tableContainer);
    }
    setUsedLibraries();
}
Also used : DataSourceException(org.obeonetwork.dsl.database.reverse.source.DataSourceException) ProgressListener(org.obeonetwork.dsl.database.reverse.utils.ProgressListener) SQLException(java.sql.SQLException) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 2 with DataSourceException

use of org.obeonetwork.dsl.database.reverse.source.DataSourceException 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

DataSourceException (org.obeonetwork.dsl.database.reverse.source.DataSourceException)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 IFile (org.eclipse.core.resources.IFile)1 Path (org.eclipse.core.runtime.Path)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 DataBase (org.obeonetwork.dsl.database.DataBase)1 DataSource (org.obeonetwork.dsl.database.reverse.source.DataSource)1 ProgressListener (org.obeonetwork.dsl.database.reverse.utils.ProgressListener)1