Search in sources :

Example 21 with ColumnDefinitions

use of com.datastax.oss.driver.api.core.cql.ColumnDefinitions in project java-driver by datastax.

the class BoundStatementCcmIT method should_set_all_occurrences_of_variable.

@Test
public void should_set_all_occurrences_of_variable() {
    CqlSession session = sessionRule.session();
    PreparedStatement ps = session.prepare("INSERT INTO test3 (pk1, pk2, v) VALUES (:i, :i, :i)");
    CqlIdentifier id = CqlIdentifier.fromCql("i");
    ColumnDefinitions variableDefinitions = ps.getVariableDefinitions();
    assertThat(variableDefinitions.allIndicesOf(id)).containsExactly(0, 1, 2);
    should_set_all_occurrences_of_variable(ps.bind().setInt(id, 12));
    should_set_all_occurrences_of_variable(ps.boundStatementBuilder().setInt(id, 12).build());
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.Test)

Example 22 with ColumnDefinitions

use of com.datastax.oss.driver.api.core.cql.ColumnDefinitions in project java-driver by datastax.

the class CqlPrepareHandlerTest method assertMatchesSimplePrepared.

private static void assertMatchesSimplePrepared(PreparedStatement statement) {
    assertThat(Bytes.toHexString(statement.getId())).isEqualTo("0xffff");
    ColumnDefinitions variableDefinitions = statement.getVariableDefinitions();
    assertThat(variableDefinitions).hasSize(1);
    assertThat(variableDefinitions.get(0).getName().asInternal()).isEqualTo("key");
    ColumnDefinitions resultSetDefinitions = statement.getResultSetDefinitions();
    assertThat(resultSetDefinitions).hasSize(1);
    assertThat(resultSetDefinitions.get(0).getName().asInternal()).isEqualTo("message");
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions)

Example 23 with ColumnDefinitions

use of com.datastax.oss.driver.api.core.cql.ColumnDefinitions in project java-driver by datastax.

the class DefaultReactiveResultSetIT method should_write.

@Test
public void should_write() {
    SimpleStatement statement = SimpleStatement.builder("INSERT INTO test_reactive_write (pk, cc, v) VALUES (?, ?, ?)").addPositionalValue(0).addPositionalValue(1).addPositionalValue(2).setExecutionProfile(sessionRule.slowProfile()).build();
    ReactiveResultSet rs = sessionRule.session().executeReactive(statement);
    List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).isEmpty();
    List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1);
    List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(EmptyColumnDefinitions.INSTANCE);
    List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(true);
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) EmptyColumnDefinitions(com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) Test(org.junit.Test)

Example 24 with ColumnDefinitions

use of com.datastax.oss.driver.api.core.cql.ColumnDefinitions in project java-driver by datastax.

the class DefaultReactiveResultSetIT method should_write_batch_cas.

@Test
public void should_write_batch_cas() {
    BatchStatement batch = createCASBatch();
    CqlSession session = sessionRule.session();
    // execute batch for the first time: all inserts should succeed and the server should return
    // only one acknowledgement row with just the [applied] column = true
    ReactiveResultSet rs = session.executeReactive(batch);
    List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).hasSize(1);
    ReactiveRow row = results.get(0);
    assertThat(row.getExecutionInfo()).isNotNull();
    assertThat(row.getColumnDefinitions()).hasSize(1);
    assertThat(row.wasApplied()).isTrue();
    assertThat(row.getBoolean("[applied]")).isTrue();
    List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
    List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
    List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
    // delete 5 out of 10 rows
    partiallyDeleteInsertedRows();
    // re-execute same statement: server should return 5 rows for the 5 failed inserts, each one
    // with [applied] = false
    rs = session.executeReactive(batch);
    results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).hasSize(5);
    for (int i = 0; i < 5; i++) {
        row = results.get(i);
        assertThat(row.getExecutionInfo()).isNotNull();
        assertThat(row.getColumnDefinitions()).hasSize(4);
        assertThat(row.wasApplied()).isFalse();
        assertThat(row.getBoolean("[applied]")).isFalse();
        assertThat(row.getInt("pk")).isEqualTo(0);
        assertThat(row.getInt("cc")).isEqualTo(i);
        assertThat(row.getInt("v")).isEqualTo(i + 1);
    }
    execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
    colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
    wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) EmptyColumnDefinitions(com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions) BatchStatement(com.datastax.oss.driver.api.core.cql.BatchStatement) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 25 with ColumnDefinitions

use of com.datastax.oss.driver.api.core.cql.ColumnDefinitions in project java-driver by datastax.

the class PreparedStatementIT method should_update_metadata_when_schema_changed_across_executions.

@Test
@CassandraRequirement(min = "4.0")
public void should_update_metadata_when_schema_changed_across_executions() {
    // Given
    CqlSession session = sessionRule.session();
    PreparedStatement ps = session.prepare("SELECT * FROM prepared_statement_test WHERE a = ?");
    ByteBuffer idBefore = ps.getResultMetadataId();
    // When
    session.execute(SimpleStatement.builder("ALTER TABLE prepared_statement_test ADD d int").setExecutionProfile(sessionRule.slowProfile()).build());
    BoundStatement bs = ps.bind(1);
    ResultSet rows = session.execute(bs);
    // Then
    ByteBuffer idAfter = ps.getResultMetadataId();
    assertThat(Bytes.toHexString(idAfter)).isNotEqualTo(Bytes.toHexString(idBefore));
    for (ColumnDefinitions columnDefinitions : ImmutableList.of(ps.getResultSetDefinitions(), bs.getPreparedStatement().getResultSetDefinitions(), rows.getColumnDefinitions())) {
        assertThat(columnDefinitions).hasSize(4);
        assertThat(columnDefinitions.get("d").getType()).isEqualTo(DataTypes.INT);
    }
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ByteBuffer(java.nio.ByteBuffer) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Aggregations

ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)25 Test (org.junit.Test)14 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)13 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)11 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)7 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)6 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)6 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)6 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)5 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)4 Row (com.datastax.oss.driver.api.core.cql.Row)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 EmptyColumnDefinitions (com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)4 ByteBuffer (java.nio.ByteBuffer)4 BatchStatement (com.datastax.oss.driver.api.core.cql.BatchStatement)3 ContinuousReactiveResultSet (com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet)2