Search in sources :

Example 11 with DBCException

use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.

the class DB2Utils method checkExplainTables.

public static Boolean checkExplainTables(DBRProgressMonitor monitor, DB2DataSource dataSource, String explainTableSchemaName) throws DBCException {
    LOG.debug("Check EXPLAIN tables in '" + explainTableSchemaName + "'");
    monitor.beginTask("Check EXPLAIN tables", 1);
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Verify EXPLAIN tables")) {
        // First Check with given schema
        try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_INST_OBJ)) {
            // EXPLAIN
            stmtSP.setString(1, "EXPLAIN");
            // Verify
            stmtSP.setString(2, "V");
            // Tablespace
            stmtSP.setString(3, "");
            // Schema
            stmtSP.setString(4, explainTableSchemaName);
            stmtSP.execute();
            LOG.debug("EXPLAIN tables with schema " + explainTableSchemaName + " found.");
            return true;
        } catch (SQLException e) {
            LOG.debug("RC:" + e.getErrorCode() + " SQLState:" + e.getSQLState() + " " + e.getMessage());
            if (e.getErrorCode() == CALL_INST_OBJ_BAD_RC) {
                LOG.debug("No valid EXPLAIN tables found in schema '" + explainTableSchemaName + "'.");
                return false;
            }
            throw new DBCException(e, dataSource);
        }
    } finally {
        monitor.done();
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCCallableStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCCallableStatement)

Example 12 with DBCException

use of org.jkiss.dbeaver.model.exec.DBCException 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)

Example 13 with DBCException

use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.

the class DB2DataSource method planQueryExecution.

// --------------
// Plan Tables
// --------------
@Override
public DBCPlan planQueryExecution(DBCSession session, String query) throws DBCException {
    String ptSchemaname = getExplainTablesSchemaName(session);
    if (ptSchemaname == null) {
        throw new DBCException(DB2Messages.dialog_explain_no_tables_found_ex);
    }
    DB2PlanAnalyser plan = new DB2PlanAnalyser(query, ptSchemaname);
    plan.explain((JDBCSession) session);
    return plan;
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) DB2XMLString(org.jkiss.dbeaver.ext.db2.info.DB2XMLString) DB2PlanAnalyser(org.jkiss.dbeaver.ext.db2.model.plan.DB2PlanAnalyser)

Example 14 with DBCException

use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.

the class OracleMaintenanceDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<T> getScriptListener() {
    return new SQLScriptStatusDialog<T>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull T object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
        }

        @Override
        public void endObjectProcessing(@NotNull T object, Exception error) {
            super.endObjectProcessing(object, error);
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                treeItem.setText(1, error == null ? "Done" : error.getMessage());
            }
        }
    };
}
Also used : SWT(org.eclipse.swt.SWT) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) Nullable(org.jkiss.code.Nullable) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 15 with DBCException

use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.

the class OracleCompilerDialog method performCompilation.

private void performCompilation(DBRProgressMonitor monitor, List<OracleSourceObject> units) {
    compileLog.layoutLog();
    for (OracleSourceObject unit : units) {
        if (monitor.isCanceled()) {
            break;
        }
        final String message = NLS.bind(OracleMessages.views_oracle_compiler_dialog_message_compile_unit, unit.getSourceType().name(), unit.getName());
        compileLog.info(message);
        boolean success = false;
        try {
            success = CompileHandler.compileUnit(monitor, compileLog, unit);
        } catch (DBCException e) {
            log.error("Compile error", e);
        }
        compileLog.info(!success ? OracleMessages.views_oracle_compiler_dialog_message_compilation_error : OracleMessages.views_oracle_compiler_dialog_message_compilation_success);
        //$NON-NLS-1$
        compileLog.info("");
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Aggregations

DBCException (org.jkiss.dbeaver.model.exec.DBCException)60 SQLException (java.sql.SQLException)28 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)16 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)14 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)13 DBException (org.jkiss.dbeaver.DBException)11 NotNull (org.jkiss.code.NotNull)9 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)5 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)5 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)4 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Tree (org.eclipse.swt.widgets.Tree)3 TreeColumn (org.eclipse.swt.widgets.TreeColumn)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 Nullable (org.jkiss.code.Nullable)3 DBPPlatform (org.jkiss.dbeaver.model.app.DBPPlatform)3 TemporaryContentStorage (org.jkiss.dbeaver.model.impl.TemporaryContentStorage)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3