Search in sources :

Example 1 with DataSourceWizard

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

the class MigrateAction method performAction.

public void performAction(ActionEvent e) {
    DataSourceWizard connectWizard = dataSourceWizardDialog("Migrate DB Schema: Connect to Database");
    if (connectWizard == null) {
        return;
    }
    DataMap map = getProjectController().getCurrentDataMap();
    if (map == null) {
        throw new IllegalStateException("No current DataMap selected.");
    }
    dialogShown = false;
    DbActionOptionsDialog optionsDialog = loaderOptionDialog(connectWizard);
    if (dialogShown && optionsDialog == null) {
        return;
    }
    String selectedCatalog = optionsDialog == null ? null : optionsDialog.getSelectedCatalog();
    String selectedSchema = optionsDialog == null ? null : optionsDialog.getSelectedSchema();
    MergerTokenFactoryProvider mergerTokenFactoryProvider = getApplication().getInjector().getInstance(MergerTokenFactoryProvider.class);
    // ... show dialog...
    new MergerOptions(getProjectController(), "Migrate DB Schema: Options", connectWizard.getConnectionInfo(), map, selectedCatalog, selectedSchema, mergerTokenFactoryProvider).startupAction();
}
Also used : DataSourceWizard(org.apache.cayenne.modeler.dialog.db.DataSourceWizard) MergerTokenFactoryProvider(org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider) MergerOptions(org.apache.cayenne.modeler.dialog.db.merge.MergerOptions) DbActionOptionsDialog(org.apache.cayenne.modeler.dialog.db.DbActionOptionsDialog) DataMap(org.apache.cayenne.map.DataMap)

Example 2 with DataSourceWizard

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

the class DBGeneratorOptions method generateSchemaAction.

/**
 * Performs configured schema operations via DbGenerator.
 */
public void generateSchemaAction() {
    DataSourceWizard connectWizard = new DataSourceWizard(this.getParent(), "Generate DB Schema: Connect to Database");
    if (!connectWizard.startupAction()) {
        return;
    }
    this.connectionInfo = connectWizard.getConnectionInfo();
    refreshGeneratorAction();
    Collection<ValidationResult> failures = new ArrayList<ValidationResult>();
    // sanity check...
    for (DbGenerator generator : generators) {
        if (generator.isEmpty(true)) {
            JOptionPane.showMessageDialog(getView(), "Nothing to generate.");
            return;
        }
        try {
            generator.runGenerator(connectWizard.getDataSource());
            failures.add(generator.getFailures());
        } catch (Throwable th) {
            reportError("Schema Generation Error", th);
        }
    }
    if (failures.size() == 0) {
        JOptionPane.showMessageDialog(getView(), "Schema Generation Complete.");
    } else {
        new ValidationResultBrowser(this).startupAction("Schema Generation Complete", "Schema generation finished. The following problem(s) were ignored.", failures);
    }
}
Also used : DataSourceWizard(org.apache.cayenne.modeler.dialog.db.DataSourceWizard) ArrayList(java.util.ArrayList) ValidationResultBrowser(org.apache.cayenne.modeler.dialog.ValidationResultBrowser) ValidationResult(org.apache.cayenne.validation.ValidationResult) DbGenerator(org.apache.cayenne.access.DbGenerator)

Example 3 with DataSourceWizard

use of org.apache.cayenne.modeler.dialog.db.DataSourceWizard 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

DataSourceWizard (org.apache.cayenne.modeler.dialog.db.DataSourceWizard)3 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DbGenerator (org.apache.cayenne.access.DbGenerator)1 MergerTokenFactoryProvider (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider)1 DataMap (org.apache.cayenne.map.DataMap)1 ValidationResultBrowser (org.apache.cayenne.modeler.dialog.ValidationResultBrowser)1 DbActionOptionsDialog (org.apache.cayenne.modeler.dialog.db.DbActionOptionsDialog)1 DbLoaderContext (org.apache.cayenne.modeler.dialog.db.load.DbLoaderContext)1 DbLoaderOptionsDialog (org.apache.cayenne.modeler.dialog.db.load.DbLoaderOptionsDialog)1 MergerOptions (org.apache.cayenne.modeler.dialog.db.merge.MergerOptions)1 ValidationResult (org.apache.cayenne.validation.ValidationResult)1