Search in sources :

Example 1 with JdbcQueryExecuteRequest

use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest in project ignite by apache.

the class JdbcThinConnection method executeNative.

/**
 * @param sql Statement.
 * @param cmd Parsed form of {@code sql}.
 * @throws SQLException if failed.
 */
void executeNative(String sql, SqlCommand cmd) throws SQLException {
    if (cmd instanceof SqlSetStreamingCommand) {
        // If streaming is already on, we have to disable it first.
        if (stream) {
            // We have to send request regardless of actual batch size.
            executeBatch(true);
            stream = false;
        }
        boolean newVal = ((SqlSetStreamingCommand) cmd).isTurnOn();
        // Actual ON, if needed.
        if (newVal) {
            sendRequest(new JdbcQueryExecuteRequest(JdbcStatementType.ANY_STATEMENT_TYPE, schema, 1, 1, sql, null));
            streamBatchSize = ((SqlSetStreamingCommand) cmd).batchSize();
            stream = true;
        }
    } else
        throw IgniteQueryErrorCode.createJdbcSqlException("Unsupported native statement: " + sql, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
Also used : JdbcQueryExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)

Example 2 with JdbcQueryExecuteRequest

use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest in project ignite by apache.

the class JdbcThinStatement method execute0.

/**
 * @param stmtType Expected statement type.
 * @param sql Sql query.
 * @param args Query parameters.
 *
 * @throws SQLException Onj error.
 */
protected void execute0(JdbcStatementType stmtType, String sql, List<Object> args) throws SQLException {
    ensureNotClosed();
    closeResults();
    if (sql == null || sql.isEmpty())
        throw new SQLException("SQL query is empty.");
    checkStatementBatchEmpty();
    SqlCommand nativeCmd = null;
    if (stmtType != JdbcStatementType.SELECT_STATEMENT_TYPE && isEligibleForNativeParsing(sql))
        nativeCmd = tryParseNative(sql);
    if (nativeCmd != null) {
        conn.executeNative(sql, nativeCmd);
        resultSets = Collections.singletonList(resultSetForUpdate(0));
        // as an ordinary batch citizen.
        return;
    }
    if (conn.isStream()) {
        if (stmtType == JdbcStatementType.SELECT_STATEMENT_TYPE)
            throw new SQLException("executeQuery() method is not allowed in streaming mode.", SqlStateCode.INTERNAL_ERROR, IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
        conn.addBatch(sql, args);
        resultSets = Collections.singletonList(resultSetForUpdate(0));
        return;
    }
    JdbcResult res0 = conn.sendRequest(new JdbcQueryExecuteRequest(stmtType, schema, pageSize, maxRows, sql, args == null ? null : args.toArray(new Object[args.size()])));
    assert res0 != null;
    if (res0 instanceof JdbcBulkLoadAckResult)
        res0 = sendFile((JdbcBulkLoadAckResult) res0);
    if (res0 instanceof JdbcQueryExecuteResult) {
        JdbcQueryExecuteResult res = (JdbcQueryExecuteResult) res0;
        resultSets = Collections.singletonList(new JdbcThinResultSet(this, res.getQueryId(), pageSize, res.last(), res.items(), res.isQuery(), conn.autoCloseServerCursor(), res.updateCount(), closeOnCompletion));
    } else if (res0 instanceof JdbcQueryExecuteMultipleStatementsResult) {
        JdbcQueryExecuteMultipleStatementsResult res = (JdbcQueryExecuteMultipleStatementsResult) res0;
        List<JdbcResultInfo> resInfos = res.results();
        resultSets = new ArrayList<>(resInfos.size());
        boolean firstRes = true;
        for (JdbcResultInfo rsInfo : resInfos) {
            if (!rsInfo.isQuery())
                resultSets.add(resultSetForUpdate(rsInfo.updateCount()));
            else {
                if (firstRes) {
                    firstRes = false;
                    resultSets.add(new JdbcThinResultSet(this, rsInfo.queryId(), pageSize, res.isLast(), res.items(), true, conn.autoCloseServerCursor(), -1, closeOnCompletion));
                } else {
                    resultSets.add(new JdbcThinResultSet(this, rsInfo.queryId(), pageSize, false, null, true, conn.autoCloseServerCursor(), -1, closeOnCompletion));
                }
            }
        }
    } else
        throw new SQLException("Unexpected result [res=" + res0 + ']');
    assert resultSets.size() > 0 : "At least one results set is expected";
}
Also used : JdbcBulkLoadAckResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBulkLoadAckResult) JdbcQueryExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest) JdbcResultInfo(org.apache.ignite.internal.processors.odbc.jdbc.JdbcResultInfo) JdbcQueryExecuteMultipleStatementsResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteMultipleStatementsResult) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) JdbcQueryExecuteResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteResult) ArrayList(java.util.ArrayList) List(java.util.List) JdbcResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcResult) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand)

Aggregations

JdbcQueryExecuteRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteRequest)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JdbcBulkLoadAckResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcBulkLoadAckResult)1 JdbcQueryExecuteMultipleStatementsResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteMultipleStatementsResult)1 JdbcQueryExecuteResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteResult)1 JdbcResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcResult)1 JdbcResultInfo (org.apache.ignite.internal.processors.odbc.jdbc.JdbcResultInfo)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 SqlCommand (org.apache.ignite.internal.sql.command.SqlCommand)1 SqlSetStreamingCommand (org.apache.ignite.internal.sql.command.SqlSetStreamingCommand)1