com.datastax.oss.driver.api.core.cql.BatchStatement Java Examples

The following examples show how to use com.datastax.oss.driver.api.core.cql.BatchStatement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InterpreterLogicTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_generate_batch_statement() throws Exception {
  //Given
  SimpleStatement st1 = SimpleStatement.newInstance("SELECT * FROM users LIMIT 10;");
  SimpleStatement st2 = SimpleStatement.newInstance("INSERT INTO users(id) VALUES(10);");
  SimpleStatement st3 = SimpleStatement.newInstance(
          "UPDATE users SET name = 'John DOE' WHERE id=10;");
  CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
          Option.<ConsistencyLevel>empty(),
          Option.empty(),
          Option.empty(),
          Option.empty());

  //When
  BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options,
          toScalaList(asList(st1, st2, st3)));

  //Then
  assertThat(actual).isNotNull();
  List<BatchableStatement> statements = new ArrayList<BatchableStatement>();
  for (BatchableStatement b: actual) {
    statements.add(b);
  }
  assertThat(statements).hasSize(3);
  assertThat(statements.get(0)).isSameAs(st1);
  assertThat(statements.get(1)).isSameAs(st2);
  assertThat(statements.get(2)).isSameAs(st3);
  assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
Example #2
Source File: PersistentActorUpdateEventProcessor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
private void executeBatchV3AndUp(List<PersistentActorUpdateEvent> events) {
    BatchStatement batchStatement = BatchStatement.newInstance(UNLOGGED);
    for (PersistentActorUpdateEvent event : events) {
        if (event.getPersistentActorBytes() != null) {
            batchStatement.add(insertStatement.bind(event.getRowKey()[0], event.getRowKey()[1], event.getPersistentActorId(), event.getPersistentActorBytes()));
        } else {
            // it's a delete
            batchStatement.add(deleteStatement.bind(event.getRowKey()[0], event.getRowKey()[1], event.getPersistentActorId()));
        }
    }
    executeWithRetry(cassandraSession, batchStatement, logger);
}