Search in sources :

Example 1 with ContinuousPagingOptions

use of com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions in project java-driver by datastax.

the class GraphConversions method createContinuousMessageFromGraphStatement.

public static Message createContinuousMessageFromGraphStatement(GraphStatement<?> statement, GraphProtocol subProtocol, DriverExecutionProfile config, InternalDriverContext context, GraphBinaryModule graphBinaryModule) {
    final List<ByteBuffer> encodedQueryParams;
    if (!(statement instanceof ScriptGraphStatement) || ((ScriptGraphStatement) statement).getQueryParams().isEmpty()) {
        encodedQueryParams = Collections.emptyList();
    } else {
        try {
            Map<String, Object> queryParams = ((ScriptGraphStatement) statement).getQueryParams();
            if (subProtocol.isGraphBinary()) {
                Buffer graphBinaryParams = graphBinaryModule.serialize(queryParams);
                encodedQueryParams = Collections.singletonList(graphBinaryParams.nioBuffer());
                graphBinaryParams.release();
            } else {
                encodedQueryParams = Collections.singletonList(GraphSONUtils.serializeToByteBuffer(queryParams, subProtocol));
            }
        } catch (IOException e) {
            throw new UncheckedIOException("Couldn't serialize parameters for GraphStatement: " + statement, e);
        }
    }
    int consistencyLevel = DefaultConsistencyLevel.valueOf(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).getProtocolCode();
    long timestamp = statement.getTimestamp();
    if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
        timestamp = context.getTimestampGenerator().next();
    }
    int pageSize = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE);
    int maxPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES);
    int maxPagesPerSecond = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND);
    int maxEnqueuedPages = config.getInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES);
    ContinuousPagingOptions options = new ContinuousPagingOptions(maxPages, maxPagesPerSecond, maxEnqueuedPages);
    DseQueryOptions queryOptions = new DseQueryOptions(consistencyLevel, encodedQueryParams, // ignored by the DSE Graph server
    Collections.emptyMap(), // also ignored
    true, pageSize, null, // also ignored
    ProtocolConstants.ConsistencyLevel.LOCAL_SERIAL, timestamp, // also ignored
    null, // graph CP does not support sizeInBytes
    false, options);
    if (statement instanceof ScriptGraphStatement) {
        return new Query(((ScriptGraphStatement) statement).getScript(), queryOptions);
    } else {
        return new RawBytesQuery(getQueryBytes(statement, subProtocol), queryOptions);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.tinkerpop.gremlin.structure.io.Buffer) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Query(com.datastax.oss.protocol.internal.request.Query) ContinuousPagingOptions(com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ByteBuffer(java.nio.ByteBuffer) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions)

Example 2 with ContinuousPagingOptions

use of com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions in project java-driver by datastax.

the class DseConversions method toContinuousPagingMessage.

public static Message toContinuousPagingMessage(Statement<?> statement, DriverExecutionProfile config, InternalDriverContext context) {
    ConsistencyLevelRegistry consistencyLevelRegistry = context.getConsistencyLevelRegistry();
    ConsistencyLevel consistency = statement.getConsistencyLevel();
    int consistencyCode = (consistency == null) ? consistencyLevelRegistry.nameToCode(config.getString(DefaultDriverOption.REQUEST_CONSISTENCY)) : consistency.getProtocolCode();
    int pageSize = config.getInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE);
    boolean pageSizeInBytes = config.getBoolean(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE_BYTES);
    int maxPages = config.getInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES);
    int maxPagesPerSecond = config.getInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND);
    int maxEnqueuedPages = config.getInt(DseDriverOption.CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES);
    ContinuousPagingOptions options = new ContinuousPagingOptions(maxPages, maxPagesPerSecond, maxEnqueuedPages);
    ConsistencyLevel serialConsistency = statement.getSerialConsistencyLevel();
    int serialConsistencyCode = (serialConsistency == null) ? consistencyLevelRegistry.nameToCode(config.getString(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY)) : serialConsistency.getProtocolCode();
    long timestamp = statement.getQueryTimestamp();
    if (timestamp == Statement.NO_DEFAULT_TIMESTAMP) {
        timestamp = context.getTimestampGenerator().next();
    }
    CodecRegistry codecRegistry = context.getCodecRegistry();
    ProtocolVersion protocolVersion = context.getProtocolVersion();
    ProtocolVersionRegistry protocolVersionRegistry = context.getProtocolVersionRegistry();
    CqlIdentifier keyspace = statement.getKeyspace();
    if (statement instanceof SimpleStatement) {
        SimpleStatement simpleStatement = (SimpleStatement) statement;
        List<Object> positionalValues = simpleStatement.getPositionalValues();
        Map<CqlIdentifier, Object> namedValues = simpleStatement.getNamedValues();
        if (!positionalValues.isEmpty() && !namedValues.isEmpty()) {
            throw new IllegalArgumentException("Can't have both positional and named values in a statement.");
        }
        if (keyspace != null && !protocolVersionRegistry.supports(protocolVersion, DefaultProtocolFeature.PER_REQUEST_KEYSPACE)) {
            throw new IllegalArgumentException("Can't use per-request keyspace with protocol " + protocolVersion);
        }
        DseQueryOptions queryOptions = new DseQueryOptions(consistencyCode, Conversions.encode(positionalValues, codecRegistry, protocolVersion), Conversions.encode(namedValues, codecRegistry, protocolVersion), false, pageSize, statement.getPagingState(), serialConsistencyCode, timestamp, (keyspace == null) ? null : keyspace.asInternal(), pageSizeInBytes, options);
        return new Query(simpleStatement.getQuery(), queryOptions);
    } else if (statement instanceof BoundStatement) {
        BoundStatement boundStatement = (BoundStatement) statement;
        if (!protocolVersionRegistry.supports(protocolVersion, DefaultProtocolFeature.UNSET_BOUND_VALUES)) {
            Conversions.ensureAllSet(boundStatement);
        }
        boolean skipMetadata = boundStatement.getPreparedStatement().getResultSetDefinitions().size() > 0;
        DseQueryOptions queryOptions = new DseQueryOptions(consistencyCode, boundStatement.getValues(), Collections.emptyMap(), skipMetadata, pageSize, statement.getPagingState(), serialConsistencyCode, timestamp, null, pageSizeInBytes, options);
        PreparedStatement preparedStatement = boundStatement.getPreparedStatement();
        ByteBuffer id = preparedStatement.getId();
        ByteBuffer resultMetadataId = preparedStatement.getResultMetadataId();
        return new Execute(Bytes.getArray(id), (resultMetadataId == null) ? null : Bytes.getArray(resultMetadataId), queryOptions);
    } else {
        throw new IllegalArgumentException("Unsupported statement type: " + statement.getClass().getName());
    }
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) Execute(com.datastax.oss.protocol.internal.request.Execute) ContinuousPagingOptions(com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) ProtocolVersion(com.datastax.oss.driver.api.core.ProtocolVersion) ProtocolVersionRegistry(com.datastax.oss.driver.internal.core.ProtocolVersionRegistry) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ByteBuffer(java.nio.ByteBuffer) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) ConsistencyLevelRegistry(com.datastax.oss.driver.internal.core.ConsistencyLevelRegistry) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions) CodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Aggregations

ContinuousPagingOptions (com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions)2 DseQueryOptions (com.datastax.dse.protocol.internal.request.query.DseQueryOptions)2 Query (com.datastax.oss.protocol.internal.request.Query)2 ByteBuffer (java.nio.ByteBuffer)2 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)1 RawBytesQuery (com.datastax.dse.protocol.internal.request.RawBytesQuery)1 ConsistencyLevel (com.datastax.oss.driver.api.core.ConsistencyLevel)1 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)1 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)1 ConsistencyLevelRegistry (com.datastax.oss.driver.internal.core.ConsistencyLevelRegistry)1 ProtocolVersionRegistry (com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)1 Execute (com.datastax.oss.protocol.internal.request.Execute)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Buffer (org.apache.tinkerpop.gremlin.structure.io.Buffer)1