Search in sources :

Example 1 with JdbcQuery

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

the class JdbcThinPreparedStatement method addBatch.

/**
 * {@inheritDoc}
 */
@Override
public void addBatch() throws SQLException {
    ensureNotClosed();
    checkStatementEligibleForBatching(sql);
    checkStatementBatchEmpty();
    batchSize++;
    if (conn.isStream())
        conn.addBatch(sql, args);
    else {
        if (batch == null) {
            batch = new ArrayList<>();
            batch.add(new JdbcQuery(sql, args.toArray(new Object[args.size()])));
        } else
            batch.add(new JdbcQuery(null, args.toArray(new Object[args.size()])));
    }
    args = null;
}
Also used : JdbcQuery(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery)

Example 2 with JdbcQuery

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

the class JdbcThinStatement method addBatch.

/**
 * {@inheritDoc}
 */
@Override
public void addBatch(String sql) throws SQLException {
    ensureNotClosed();
    checkStatementEligibleForBatching(sql);
    checkStatementBatchEmpty();
    batchSize++;
    if (conn.isStream()) {
        conn.addBatch(sql, null);
        return;
    }
    if (batch == null)
        batch = new ArrayList<>();
    batch.add(new JdbcQuery(sql, null));
}
Also used : JdbcQuery(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery) ArrayList(java.util.ArrayList)

Example 3 with JdbcQuery

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

the class JdbcThinConnection method addBatch.

/**
 * Add another query for batched execution.
 * @param sql Query.
 * @param args Arguments.
 * @throws SQLException On error.
 */
void addBatch(String sql, List<Object> args) throws SQLException {
    boolean newQry = (args == null || !F.eq(lastStreamQry, sql));
    // Providing null as SQL here allows for recognizing subbatches on server and handling them more efficiently.
    JdbcQuery q = new JdbcQuery(newQry ? sql : null, args != null ? args.toArray() : null);
    if (streamBatch == null)
        streamBatch = new ArrayList<>(streamBatchSize);
    streamBatch.add(q);
    // Null args means "addBatch(String)" was called on non-prepared Statement,
    // we don't want to remember its query string.
    lastStreamQry = (args != null ? sql : null);
    if (streamBatch.size() == streamBatchSize)
        executeBatch(false);
}
Also used : JdbcQuery(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery) ArrayList(java.util.ArrayList)

Example 4 with JdbcQuery

use of org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery 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

JdbcQuery (org.apache.ignite.internal.processors.odbc.jdbc.JdbcQuery)4 ArrayList (java.util.ArrayList)2 JdbcBatchExecuteRequest (org.apache.ignite.internal.processors.odbc.jdbc.JdbcBatchExecuteRequest)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