Search in sources :

Example 56 with SQLException

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;
}
Also used : SQLException(java.sql.SQLException) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 57 with SQLException

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();
    }
}
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 58 with SQLException

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;
}
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 59 with SQLException

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());
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException)

Example 60 with SQLException

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);
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)

Aggregations

SQLException (java.sql.SQLException)8258 PreparedStatement (java.sql.PreparedStatement)3681 ResultSet (java.sql.ResultSet)3014 Connection (java.sql.Connection)2768 Statement (java.sql.Statement)1373 ArrayList (java.util.ArrayList)1227 Test (org.junit.Test)918 IOException (java.io.IOException)449 List (java.util.List)362 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)298 HashMap (java.util.HashMap)286 Properties (java.util.Properties)265 DatabaseException (net.jforum.exceptions.DatabaseException)249 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)190 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)184 Timestamp (java.sql.Timestamp)180 CallableStatement (java.sql.CallableStatement)177 DalHints (com.ctrip.platform.dal.dao.DalHints)169 Map (java.util.Map)162 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)160