All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tarantool.driver.api.cursor.OffsetCursor Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.api.cursor;

import io.tarantool.driver.api.conditions.Conditions;
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.exceptions.TarantoolClientException;
import io.tarantool.driver.protocol.Packable;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.ExecutionException;

/**
 * Cursor implementation that uses server 'limit' and 'offset'
 * methods under the hood.
 * 

* Note: it is possible to use this class with standalone server only. *

* See {@link TarantoolCursor} for more details on cursors. * * @author Vladimir Rogach */ public class OffsetCursor> extends TarantoolCursorBase { private final TarantoolSpaceOperations space; private final Conditions initConditions; // size of a batch for single invocation of client private final long batchSize; private long spaceOffset; private Iterator resultIter = Collections.emptyIterator(); private T currentValue; public OffsetCursor( TarantoolSpaceOperations space, Conditions conditions, int batchSize) { this.space = space; this.initConditions = conditions; this.spaceOffset = 0; this.batchSize = batchSize; } /** * Perform a call o server for fetching the next batch. * * @throws TarantoolClientException if select query was interrupted by client. */ @Override protected void fetchNextTuples() throws TarantoolClientException { long limit = calcLimit(initConditions.getLimit(), batchSize, spaceOffset); if (limit <= 0) { return; } Conditions conditions = new Conditions(initConditions) .withLimit(limit) .withOffset(spaceOffset); try { resultIter = space .select(conditions) .get() .iterator(); } catch (InterruptedException | ExecutionException e) { throw new TarantoolClientException(e); } } @Override protected boolean advanceIterator() { if (resultIter.hasNext()) { currentValue = resultIter.next(); spaceOffset += 1; return true; } currentValue = null; return false; } @Override protected T getCurrentValue() { return currentValue; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy