use of java.sql.SQLException in project dbeaver by serge-rider.
the class JDBCReference method getReferencedObject.
@Override
public Object getReferencedObject(DBCSession session) throws DBCException {
if (refObject == null) {
try {
session.getProgressMonitor().beginTask("Retrieve references object", 3);
try {
session.getProgressMonitor().worked(1);
Object refValue = value.getObject();
session.getProgressMonitor().worked(1);
DBDValueHandler valueHandler = DBUtils.findValueHandler(session, type);
refObject = valueHandler.getValueFromObject(session, type, refValue, false);
session.getProgressMonitor().worked(1);
} finally {
session.getProgressMonitor().done();
}
} catch (SQLException e) {
throw new DBCException("Can't obtain object reference");
}
}
return refObject;
}
use of java.sql.SQLException 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 java.sql.SQLException 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 java.sql.SQLException in project dbeaver by serge-rider.
the class DB2DataSource method initialize.
// -----------------------
// Initialisation/Structure
// -----------------------
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
super.initialize(monitor);
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load data source meta info")) {
// First try to get active schema from special register 'CURRENT SCHEMA'
this.activeSchemaName = determineActiveSchema(session);
this.db2CurrentUserPrivileges = new DB2CurrentUserPrivileges(monitor, session, activeSchemaName, this);
} catch (SQLException e) {
LOG.warn("Error reading active schema", e);
}
try {
this.dataTypeCache.getAllObjects(monitor, this);
} catch (DBException e) {
LOG.warn("Error reading types info", e);
this.dataTypeCache.setCache(Collections.<DB2DataType>emptyList());
}
}
use of java.sql.SQLException in project dbeaver by serge-rider.
the class DB2IndexColumn method getDependentView.
// -----------------
// Helpers
// -----------------
private DB2View getDependentView(DBRProgressMonitor monitor, DB2DataSource db2DataSource, String indexSchema, String indexName) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, db2DataSource, "Read Index view dependency")) {
try (JDBCPreparedStatement stmtSel = session.prepareStatement(I_DEP)) {
stmtSel.setString(1, indexSchema);
stmtSel.setString(2, indexName);
JDBCResultSet dbResult = stmtSel.executeQuery();
if (dbResult.next()) {
String viewSchema = dbResult.getString("BSCHEMA").trim();
String viewName = dbResult.getString("BNAME");
return DB2Utils.findViewBySchemaNameAndName(monitor, db2DataSource, viewSchema, viewName);
} else {
return null;
}
}
} catch (SQLException e) {
throw new DBException(e, db2DataSource);
}
}
Aggregations