Search in sources :

Example 1 with DbActionOptionsDialog

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

the class MigrateAction method performAction.

public void performAction(ActionEvent e) {
    DataSourceWizard connectWizard = getDataSourceWizard("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 DbActionOptionsDialog

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

the class MigrateAction method loaderOptionDialog.

protected DbActionOptionsDialog loaderOptionDialog(DataSourceWizard connectWizard) {
    // use this catalog as the default...
    List<String> catalogs;
    List<String> schemas;
    String currentCatalog;
    String currentSchema = null;
    try (Connection connection = connectWizard.getDataSource().getConnection()) {
        catalogs = getCatalogs(connectWizard, connection);
        schemas = getSchemas(connection);
        if (catalogs.isEmpty() && schemas.isEmpty()) {
            return null;
        }
        currentCatalog = connection.getCatalog();
        try {
            currentSchema = connection.getSchema();
        } catch (Throwable th) {
            LOGGER.warn("Error getting schema.", th);
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(Application.getFrame(), ex.getMessage(), "Error loading schemas dialog", JOptionPane.ERROR_MESSAGE);
        return null;
    }
    DbActionOptionsDialog optionsDialog = getStartDialog(catalogs, schemas, currentCatalog, currentSchema);
    optionsDialog.setVisible(true);
    while ((optionsDialog.getChoice() != DbActionOptionsDialog.CANCEL)) {
        if (optionsDialog.getChoice() == DbActionOptionsDialog.SELECT) {
            return optionsDialog;
        }
        optionsDialog = createDialog(catalogs, schemas, currentCatalog, currentSchema, optionsDialog.getChoice());
        optionsDialog.setVisible(true);
    }
    return null;
}
Also used : Connection(java.sql.Connection) DbActionOptionsDialog(org.apache.cayenne.modeler.dialog.db.DbActionOptionsDialog)

Aggregations

DbActionOptionsDialog (org.apache.cayenne.modeler.dialog.db.DbActionOptionsDialog)2 Connection (java.sql.Connection)1 MergerTokenFactoryProvider (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider)1 DataMap (org.apache.cayenne.map.DataMap)1 DataSourceWizard (org.apache.cayenne.modeler.dialog.db.DataSourceWizard)1 MergerOptions (org.apache.cayenne.modeler.dialog.db.merge.MergerOptions)1