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();
}
}
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;
}
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;
}
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());
}
}
};
}
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("");
}
}
Aggregations