Search in sources :

Example 31 with DBCException

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

the class OracleView method loadAdditionalInfo.

private void loadAdditionalInfo(DBRProgressMonitor monitor) throws DBException {
    if (!isPersisted()) {
        additionalInfo.loaded = true;
        return;
    }
    String viewText = null;
    try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table status")) {
        boolean isOracle9 = getDataSource().isAtLeastV9();
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT TEXT,TYPE_TEXT,OID_TEXT,VIEW_TYPE_OWNER,VIEW_TYPE" + (isOracle9 ? ",SUPERVIEW_NAME" : "") + "\n" + "FROM SYS.ALL_VIEWS WHERE OWNER=? AND VIEW_NAME=?")) {
            dbStat.setString(1, getContainer().getName());
            dbStat.setString(2, getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                if (dbResult.next()) {
                    viewText = JDBCUtils.safeGetString(dbResult, "TEXT");
                    additionalInfo.setText(viewText);
                    additionalInfo.setTypeText(JDBCUtils.safeGetStringTrimmed(dbResult, "TYPE_TEXT"));
                    additionalInfo.setOidText(JDBCUtils.safeGetStringTrimmed(dbResult, "OID_TEXT"));
                    additionalInfo.typeOwner = JDBCUtils.safeGetStringTrimmed(dbResult, "VIEW_TYPE_OWNER");
                    additionalInfo.typeName = JDBCUtils.safeGetStringTrimmed(dbResult, "VIEW_TYPE");
                    if (isOracle9) {
                        String superViewName = JDBCUtils.safeGetString(dbResult, "SUPERVIEW_NAME");
                        if (!CommonUtils.isEmpty(superViewName)) {
                            additionalInfo.setSuperView(getContainer().getView(monitor, superViewName));
                        }
                    }
                } else {
                    log.warn("Cannot find view '" + getFullyQualifiedName(DBPEvaluationContext.UI) + "' metadata");
                }
                additionalInfo.loaded = true;
            }
        }
    } catch (SQLException e) {
        throw new DBCException(e, getDataSource());
    }
    if (viewText != null) {
        viewText = "CREATE OR REPLACE VIEW " + getFullyQualifiedName(DBPEvaluationContext.DDL) + " AS\n" + viewText;
    }
    additionalInfo.setText(viewText);
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 32 with DBCException

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

the class OracleContentBFILE method closeFile.

private void closeFile() throws DBCException {
    if (!opened) {
        return;
    }
    try {
        BeanUtils.invokeObjectMethod(bfile, "closeFile");
        opened = false;
    } catch (Throwable e) {
        throw new DBCException(e, dataSource);
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 33 with DBCException

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

the class OracleContentXML method bindParameter.

@Override
public void bindParameter(JDBCSession session, JDBCPreparedStatement preparedStatement, DBSTypedObject columnType, int paramIndex) throws DBCException {
    try {
        if (storage != null) {
            try (InputStream streamReader = storage.getContentStream()) {
                final Object xmlObject = createXmlObject(session, streamReader);
                preparedStatement.setObject(paramIndex, xmlObject);
            }
        } else {
            preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML);
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    } catch (IOException e) {
        throw new DBCException("IO error while reading XML", e);
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IOException(java.io.IOException)

Example 34 with DBCException

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

the class ExplainPlanViewer method explainQueryPlan.

public void explainQueryPlan(DBCExecutionContext executionContext, SQLQuery query) throws DBCException {
    this.executionContext = executionContext;
    this.query = query;
    if (this.executionContext != null) {
        DBPDataSource dataSource = executionContext.getDataSource();
        planner = DBUtils.getAdapter(DBCQueryPlanner.class, dataSource);
    } else {
        planner = null;
    }
    planTree.clearListData();
    refreshPlanAction.setEnabled(false);
    if (planner == null) {
        throw new DBCException("This datasource doesn't support execution plans");
    }
    if (planTree.isLoading()) {
        UIUtils.showMessageBox(getControl().getShell(), "Can't explain plan", "Explain plan already running", SWT.ICON_ERROR);
        return;
    }
    sqlText.setText(query.getQuery());
    planTree.init(this.executionContext, planner, query.getQuery());
    planTree.loadData();
    refreshPlanAction.setEnabled(true);
    toggleViewAction.setEnabled(true);
}
Also used : DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource)

Example 35 with DBCException

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

the class DB2Utils method createExplainTables.

public static void createExplainTables(DBRProgressMonitor monitor, DB2DataSource dataSource, String explainTableSchemaName, String tablespaceName) throws DBCException {
    LOG.debug("Create EXPLAIN tables in " + explainTableSchemaName);
    monitor.beginTask("Create EXPLAIN Tables", 1);
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Create EXPLAIN tables")) {
        try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_INST_OBJ)) {
            // EXPLAIN
            stmtSP.setString(1, "EXPLAIN");
            // Create
            stmtSP.setString(2, "C");
            // Tablespace
            stmtSP.setString(3, tablespaceName);
            // Schema
            stmtSP.setString(4, explainTableSchemaName);
            stmtSP.executeUpdate();
            LOG.debug("Creation EXPLAIN Tables : OK");
        } catch (SQLException e) {
            LOG.error("SQLException occured during EXPLAIN tables creation in schema " + explainTableSchemaName, e);
            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)

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