Search in sources :

Example 1 with JdbcBatchExecuteRequest

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

the class JdbcThinConnection method executeBatch.

/**
 * @param lastBatch Whether open data streamers must be flushed and closed after this batch.
 * @throws SQLException if failed.
 */
private void executeBatch(boolean lastBatch) throws SQLException {
    JdbcBatchExecuteResult res = sendRequest(new JdbcBatchExecuteRequest(schema, streamBatch, lastBatch));
    streamBatch = null;
    lastStreamQry = null;
    if (res.errorCode() != ClientListenerResponse.STATUS_SUCCESS) {
        throw new BatchUpdateException(res.errorMessage(), IgniteQueryErrorCode.codeToSqlState(res.errorCode()), res.errorCode(), res.updateCounts());
    }
}
Also used : JdbcBatchExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest) JdbcBatchExecuteResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteResult) BatchUpdateException(java.sql.BatchUpdateException)

Example 2 with JdbcBatchExecuteRequest

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

the class JdbcThinStatement method executeBatch.

/**
 * {@inheritDoc}
 */
@Override
public int[] executeBatch() throws SQLException {
    ensureNotClosed();
    closeResults();
    checkStatementBatchEmpty();
    if (conn.isStream()) {
        int[] res = new int[batchSize];
        batchSize = 0;
        return res;
    }
    if (F.isEmpty(batch))
        return new int[0];
    JdbcBatchExecuteRequest req = new JdbcBatchExecuteRequest(conn.getSchema(), batch, conn.getAutoCommit(), false);
    try {
        JdbcBatchExecuteResult res = conn.sendRequest(req, this, null).response();
        if (res.errorCode() != ClientListenerResponse.STATUS_SUCCESS) {
            throw new BatchUpdateException(res.errorMessage(), IgniteQueryErrorCode.codeToSqlState(res.errorCode()), res.errorCode(), res.updateCounts());
        }
        return res.updateCounts();
    } finally {
        batchSize = 0;
        batch = null;
    }
}
Also used : JdbcBatchExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest) JdbcBatchExecuteResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteResult) BatchUpdateException(java.sql.BatchUpdateException)

Example 3 with JdbcBatchExecuteRequest

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

the class JdbcThinTcpIo method guessCapacity.

/**
 * Try to guess request capacity.
 *
 * @param req Request.
 * @return Expected capacity.
 */
private static int guessCapacity(JdbcRequest req) {
    int cap;
    if (req instanceof JdbcBatchExecuteRequest) {
        List<JdbcQuery> qrys = ((JdbcBatchExecuteRequest) req).queries();
        int cnt = !F.isEmpty(qrys) ? Math.min(MAX_BATCH_QRY_CNT, qrys.size()) : 0;
        // One additional byte for autocommit and last batch flags.
        cap = cnt * DYNAMIC_SIZE_MSG_CAP + 2;
    } else if (req instanceof JdbcQueryCloseRequest)
        cap = QUERY_CLOSE_MSG_SIZE;
    else if (req instanceof JdbcQueryMetadataRequest)
        cap = QUERY_META_MSG_SIZE;
    else if (req instanceof JdbcQueryFetchRequest)
        cap = QUERY_FETCH_MSG_SIZE;
    else
        cap = DYNAMIC_SIZE_MSG_CAP;
    return cap;
}
Also used : JdbcQuery(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery) JdbcBatchExecuteRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest) JdbcQueryMetadataRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryMetadataRequest) JdbcQueryCloseRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryCloseRequest) IpcClientTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint) JdbcQueryFetchRequest(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryFetchRequest)

Aggregations

JdbcBatchExecuteRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest)3 BatchUpdateException (java.sql.BatchUpdateException)2 JdbcBatchExecuteResult (org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteResult)2 JdbcQuery (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery)1 JdbcQueryCloseRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryCloseRequest)1 JdbcQueryFetchRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryFetchRequest)1 JdbcQueryMetadataRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryMetadataRequest)1 IpcClientTcpEndpoint (org.apache.ignite.internal.util.ipc.loopback.IpcClientTcpEndpoint)1