Search in sources :

Example 1 with Execute

use of com.datastax.oss.protocol.internal.request.Execute in project java-driver by datastax.

the class BoundStatementSimulacronIT method should_use_consistencies_from_simple_statement.

@Test
public void should_use_consistencies_from_simple_statement() {
    try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
        SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
        PreparedStatement prepared = session.prepare(st);
        SIMULACRON_RULE.cluster().clearLogs();
        // since query is unprimed, we use a text value for bind parameter as this is
        // what simulacron expects for unprimed statements.
        session.execute(prepared.bind("0"));
        List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
        assertThat(logs).hasSize(1);
        QueryLog log = logs.get(0);
        Message message = log.getFrame().message;
        assertThat(message).isInstanceOf(Execute.class);
        Execute execute = (Execute) message;
        assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.TWO.getProtocolCode());
        assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.LOCAL_SERIAL.getProtocolCode());
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 2 with Execute

use of com.datastax.oss.protocol.internal.request.Execute in project java-driver by datastax.

the class BoundStatementSimulacronIT method should_use_consistencies.

@Test
public void should_use_consistencies() {
    try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
        // set consistencies on simple statement, but they will be unused since
        // overridden by bound statement.
        SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
        PreparedStatement prepared = session.prepare(st);
        SIMULACRON_RULE.cluster().clearLogs();
        // since query is unprimed, we use a text value for bind parameter as this is
        // what simulacron expects for unprimed statements.
        session.execute(prepared.boundStatementBuilder("0").setConsistencyLevel(DefaultConsistencyLevel.THREE).setSerialConsistencyLevel(DefaultConsistencyLevel.SERIAL).build());
        List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
        assertThat(logs).hasSize(1);
        QueryLog log = logs.get(0);
        Message message = log.getFrame().message;
        assertThat(message).isInstanceOf(Execute.class);
        Execute execute = (Execute) message;
        assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.THREE.getProtocolCode());
        assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.SERIAL.getProtocolCode());
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 3 with Execute

use of com.datastax.oss.protocol.internal.request.Execute in project java-driver by datastax.

the class StatementAttributesIT method validateQueryOptions.

private void validateQueryOptions(QueryLog log, boolean validatePageState) {
    Message message = log.getFrame().message;
    assertThat(message).isInstanceOf(Execute.class);
    Execute queryExecute = (Execute) message;
    assertThat(queryExecute.options.consistency).isEqualTo(DefaultConsistencyLevel.ANY.getProtocolCode());
    assertThat(queryExecute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.QUORUM.getProtocolCode());
    assertThat(queryExecute.options.pageSize).isEqualTo(PAGE_SIZE);
    if (validatePageState) {
        String pagingState = UTF_8.decode(queryExecute.options.pagingState).toString();
        assertThat(pagingState).isEqualTo(PAGING_STATE);
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute)

Example 4 with Execute

use of com.datastax.oss.protocol.internal.request.Execute in project java-driver by datastax.

the class ProfileIT method assertServerSideCl.

private void assertServerSideCl(ConsistencyLevel expectedCl) {
    List<QueryLog> queryLogs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
    QueryLog lastLog = queryLogs.get(queryLogs.size() - 1);
    Message message = lastLog.getFrame().message;
    assertThat(message).isInstanceOf(Execute.class);
    Execute queryExecute = (Execute) message;
    assertThat(queryExecute.options.consistency).isEqualTo(expectedCl.getProtocolCode());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog)

Example 5 with Execute

use of com.datastax.oss.protocol.internal.request.Execute 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

Execute (com.datastax.oss.protocol.internal.request.Execute)6 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)4 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)4 Message (com.datastax.oss.protocol.internal.Message)4 QueryLog (com.datastax.oss.simulacron.common.cluster.QueryLog)3 ConsistencyLevel (com.datastax.oss.driver.api.core.ConsistencyLevel)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)2 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)2 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)2 ConsistencyLevelRegistry (com.datastax.oss.driver.internal.core.ConsistencyLevelRegistry)2 ProtocolVersionRegistry (com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)2 Query (com.datastax.oss.protocol.internal.request.Query)2 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 ContinuousPagingOptions (com.datastax.dse.protocol.internal.request.query.ContinuousPagingOptions)1 DseQueryOptions (com.datastax.dse.protocol.internal.request.query.DseQueryOptions)1 BatchStatement (com.datastax.oss.driver.api.core.cql.BatchStatement)1 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)1