Search in sources :

Example 1 with RecordsBatch

use of herddb.utils.RecordsBatch in project herddb by diennea.

the class RoutedClientSideConnection method executeScan.

@Override
public ScanResultSet executeScan(String tableSpace, String query, boolean usePreparedStatement, List<Object> params, long tx, int maxRows, int fetchSize, boolean keepReadLocks) throws HDBException, ClientSideMetadataProviderException {
    Channel channel = ensureOpen();
    Pdu reply = null;
    try {
        long scannerId = scannerIdGenerator.incrementAndGet();
        long requestId = channel.generateRequestId();
        long statementId = usePreparedStatement ? prepareQuery(tableSpace, query) : 0;
        query = statementId > 0 ? "" : query;
        ByteBuf message = PduCodec.OpenScanner.write(requestId, tableSpace, query, scannerId, tx, params, statementId, fetchSize, maxRows, keepReadLocks);
        LOGGER.log(Level.FINEST, "open scanner {0} for query {1}, params {2}", new Object[] { scannerId, query, params });
        reply = channel.sendMessageWithPduReply(requestId, message, timeout);
        if (reply.type == Pdu.TYPE_ERROR) {
            handleGenericError(reply, statementId, true);
            // not possible
            return null;
        } else if (reply.type != Pdu.TYPE_RESULTSET_CHUNK) {
            HDBException err = new HDBException(reply);
            reply.close();
            throw err;
        }
        boolean last = PduCodec.ResultSetChunk.readIsLast(reply);
        long transactionId = PduCodec.ResultSetChunk.readTx(reply);
        RecordsBatch data = PduCodec.ResultSetChunk.startReadingData(reply);
        // LOGGER.log(Level.SEVERE, "received first " + initialFetchBuffer.size() + " records for query " + query);
        ScanResultSetImpl impl = new ScanResultSetImpl(scannerId, data, fetchSize, last, transactionId, channel);
        return impl;
    } catch (InterruptedException err) {
        if (reply != null) {
            reply.close();
        }
        Thread.currentThread().interrupt();
        throw new HDBException(err);
    } catch (TimeoutException err) {
        if (reply != null) {
            reply.close();
        }
        throw new HDBException(err);
    }
}
Also used : Pdu(herddb.proto.Pdu) Channel(herddb.network.Channel) ByteBuf(io.netty.buffer.ByteBuf) RecordsBatch(herddb.utils.RecordsBatch) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

HDBOperationTimeoutException (herddb.client.impl.HDBOperationTimeoutException)1 Channel (herddb.network.Channel)1 Pdu (herddb.proto.Pdu)1 RecordsBatch (herddb.utils.RecordsBatch)1 ByteBuf (io.netty.buffer.ByteBuf)1 TimeoutException (java.util.concurrent.TimeoutException)1