Search in sources :

Example 1 with ProgressListener

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

use of org.obeonetwork.dsl.database.reverse.utils.ProgressListener in project InformationSystem by ObeoNetwork.

the class ImportRunnable method execute.

@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    ProgressListener progressListener = new ProgressListener() {

        private int stepsToBeDone = 0;

        public void start(int nbSteps) {
            // +2 because there is one more step to save the file
            monitor.beginTask("Importing database", nbSteps + 1);
        }

        public void progressTo(int stepsToBeDone, String message) {
            if (this.stepsToBeDone != 0) {
                monitor.worked(this.stepsToBeDone);
            }
            monitor.subTask(message);
            this.stepsToBeDone = stepsToBeDone;
        }

        public void end(String message) {
            if (this.stepsToBeDone != 0) {
                monitor.worked(this.stepsToBeDone);
            }
        }
    };
    DataBase database = DatabaseReverser.reverse(dataSourceInfos, queries, progressListener);
    if (database != null) {
        // Store the model into a file
        monitor.subTask("Saving model file");
        try {
            saveIntoFile(database, modelFilename);
            result = true;
        } catch (IOException e) {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while saving database into model file", e));
        }
        monitor.worked(1);
    } else {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while importing database : No database found."));
    }
    monitor.done();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProgressListener(org.obeonetwork.dsl.database.reverse.utils.ProgressListener) IOException(java.io.IOException) DataBase(org.obeonetwork.dsl.database.DataBase)

Aggregations

DataBase (org.obeonetwork.dsl.database.DataBase)2 ProgressListener (org.obeonetwork.dsl.database.reverse.utils.ProgressListener)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 DataSourceException (org.obeonetwork.dsl.database.reverse.source.DataSourceException)1