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());
}
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");
}
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);
}
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());
}
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);
}
}
Aggregations