Java Code Examples for com.datastax.driver.core.PreparedStatement#setConsistencyLevel()

The following examples show how to use com.datastax.driver.core.PreparedStatement#setConsistencyLevel() . 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: SchemaStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public SchemaStatement(Timer timer, StressSettings settings, DataSpec spec,
                       PreparedStatement statement, Integer thriftId, ConsistencyLevel cl, ValidationType validationType)
{
    super(timer, settings, spec);
    this.statement = statement;
    this.thriftId = thriftId;
    this.cl = cl;
    this.validationType = validationType;
    argumentIndex = new int[statement.getVariables().size()];
    bindBuffer = new Object[argumentIndex.length];
    int i = 0;
    for (ColumnDefinitions.Definition definition : statement.getVariables())
        argumentIndex[i++] = spec.partitionGenerator.indexOf(definition.getName());

    statement.setConsistencyLevel(JavaDriverClient.from(cl));
}
 
Example 2
Source File: GeneratePlacePartitionId.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public void execute(ExecutionContext context, boolean autoRollback) throws CommandExecutionException {
   Session session = context.getSession();
   PreparedStatement update = session.prepare(UPSERT_PARTITIONID);
   update.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
   
   BoundStatement select = session.prepare(SELECT).bind();
   select.setConsistencyLevel(ConsistencyLevel.ALL);
   ResultSet rs = context.getSession().execute(select);
   int count = 0;
   int [] hubsPerPartition = new int[partitionCount];
   logger.info("Preparing to partition place ids");
   long startTimeNs = System.nanoTime();
   for(Row row: rs) {
      UUID placeId = row.getUUID("id");
      int partitionId = (int) (Math.floorMod(placeId.getLeastSignificantBits(), partitionCount));

      logger.debug("Adding [{}] to partition [{}]", placeId, partitionId);
      BoundStatement bs = update.bind(partitionId, placeId);
      session.execute(bs);
      
      count++;
      hubsPerPartition[partitionId]++;
   }
   long duration = System.nanoTime() - startTimeNs;
   logger.info("Partitioned {} place in {} secs", count, duration / (float) TimeUnit.NANOSECONDS.toSeconds(1));
   for(int i=0; i<partitionCount; i++) {
      logger.info(String.format("%03d: %3d places", i, hubsPerPartition[i]));
   }
}
 
Example 3
Source File: CassandraPreparedBuilder.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public PreparedStatement prepare(Session session, String query, ConsistencyLevel consistency, RetryPolicy retryPolicy) {
   PreparedStatement ps = session.prepare(query);
   ps.setConsistencyLevel(consistency);
   if(retryPolicy != null) {
      ps.setRetryPolicy(retryPolicy);
   }
   return ps;
}
 
Example 4
Source File: CassandraStorage.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
private void prepare(String cql, RetryPolicy petryPolicy) {
    logger.info("Preparing cql stmt {}", cql);
    PreparedStatement pstmt = session.prepare(cql);
    pstmt.setConsistencyLevel(consistencyLevel);
    pstmt.setRetryPolicy(petryPolicy);
    pstmt.setIdempotent(true);
    preparedStatements.put(cql, pstmt);
}
 
Example 5
Source File: PersonDAOImpl.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private PreparedStatement prepareOptimisticUpdate() {
	PreparedStatement stmt = session.prepare(OPTIMISTIC_UPDATE);
	stmt.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
	return stmt;
}