Search in sources :

Example 1 with DB2TablespaceChooser

use of org.jkiss.dbeaver.ext.db2.editors.DB2TablespaceChooser in project dbeaver by serge-rider.

the class DB2DataSource method getExplainTablesSchemaName.

private String getExplainTablesSchemaName(DBCSession session) throws DBCException {
    // // Schema for explain tables has already been verified. Use it as-is
    // if (CommonUtils.isNotEmpty(schemaForExplainTables)) {
    // return schemaForExplainTables;
    // }
    DBRProgressMonitor monitor = session.getProgressMonitor();
    // Verify explain table from current authorization id
    String sessionUserSchema;
    try {
        sessionUserSchema = JDBCUtils.queryString((JDBCSession) session, GET_SESSION_USER).trim();
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    }
    Boolean ok = DB2Utils.checkExplainTables(monitor, this, sessionUserSchema);
    if (ok) {
        LOG.debug("Valid explain tables found in " + sessionUserSchema);
        schemaForExplainTables = sessionUserSchema;
        return schemaForExplainTables;
    }
    // Verify explain table from SYSTOOLS
    ok = DB2Utils.checkExplainTables(monitor, this, DB2Constants.EXPLAIN_SCHEMA_NAME_DEFAULT);
    if (ok) {
        LOG.debug("Valid explain tables found in " + DB2Constants.EXPLAIN_SCHEMA_NAME_DEFAULT);
        schemaForExplainTables = DB2Constants.EXPLAIN_SCHEMA_NAME_DEFAULT;
        return schemaForExplainTables;
    }
    // No valid explain tables found, propose to create them in current authId
    String msg = String.format(DB2Messages.dialog_explain_ask_to_create, sessionUserSchema);
    if (!UIUtils.confirmAction(DB2Messages.dialog_explain_no_tables, msg)) {
        return null;
    }
    // Ask the user in what tablespace to create the Explain tables
    try {
        final List<String> listTablespaces = DB2Utils.getListOfUsableTsForExplain(monitor, (JDBCSession) session);
        // NO Usable Tablespace found: End of the game..
        if (listTablespaces.isEmpty()) {
            UIUtils.showErrorDialog(null, DB2Messages.dialog_explain_no_tablespace_found_title, DB2Messages.dialog_explain_no_tablespace_found_title);
            return null;
        }
        // Build a dialog with the list of usable tablespaces for the user to choose
        String tablespaceName = new UITask<String>() {

            @Override
            protected String runTask() {
                final DB2TablespaceChooser tsChooserDialog = new DB2TablespaceChooser(DBeaverUI.getActiveWorkbenchShell(), listTablespaces);
                if (tsChooserDialog.open() == IDialogConstants.OK_ID) {
                    return tsChooserDialog.getSelectedTablespace();
                } else {
                    return null;
                }
            }
        }.execute();
        if (tablespaceName == null) {
            return null;
        }
        // Try to create explain tables within current authorizartionID in given tablespace
        DB2Utils.createExplainTables(session.getProgressMonitor(), this, sessionUserSchema, tablespaceName);
        // Hourra!
        schemaForExplainTables = sessionUserSchema;
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    }
    return sessionUserSchema;
}
Also used : SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DB2XMLString(org.jkiss.dbeaver.ext.db2.info.DB2XMLString) DB2TablespaceChooser(org.jkiss.dbeaver.ext.db2.editors.DB2TablespaceChooser)

Aggregations

SQLException (java.sql.SQLException)1 DB2TablespaceChooser (org.jkiss.dbeaver.ext.db2.editors.DB2TablespaceChooser)1 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1