Search in sources :

Example 1 with DbLoaderContext

use of org.apache.cayenne.modeler.dialog.db.load.DbLoaderContext in project cayenne by apache.

the class ReverseEngineeringAction method performAction.

/**
 * Connects to DB and delegates processing to DbLoaderController, starting it asynchronously.
 */
@Override
public void performAction(ActionEvent event) {
    final DbLoaderContext context = new DbLoaderContext();
    final DataSourceWizard connectWizard = dataSourceWizardDialog("Reengineer DB Schema: Connect to Database");
    if (connectWizard == null) {
        return;
    }
    context.setProjectController(getProjectController());
    try {
        context.setConnection(connectWizard.getDataSource().getConnection());
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(Application.getFrame(), ex.getMessage(), "Error loading schemas dialog", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final DbLoaderOptionsDialog loaderOptionsDialog = loaderOptionDialog(connectWizard);
    if (!context.buildConfig(connectWizard, loaderOptionsDialog)) {
        try {
            context.getConnection().close();
        } catch (SQLException ignored) {
        }
        return;
    }
    runLoaderInThread(context, new Runnable() {

        @Override
        public void run() {
            application.getUndoManager().discardAllEdits();
            try {
                context.getConnection().close();
            } catch (SQLException ignored) {
            }
        }
    });
}
Also used : DataSourceWizard(org.apache.cayenne.modeler.dialog.db.DataSourceWizard) SQLException(java.sql.SQLException) DbLoaderContext(org.apache.cayenne.modeler.dialog.db.load.DbLoaderContext) DbLoaderOptionsDialog(org.apache.cayenne.modeler.dialog.db.load.DbLoaderOptionsDialog)

Aggregations

SQLException (java.sql.SQLException)1 DataSourceWizard (org.apache.cayenne.modeler.dialog.db.DataSourceWizard)1 DbLoaderContext (org.apache.cayenne.modeler.dialog.db.load.DbLoaderContext)1 DbLoaderOptionsDialog (org.apache.cayenne.modeler.dialog.db.load.DbLoaderOptionsDialog)1