本文整理匯總了Java中com.datastax.driver.core.BatchStatement.getStatements方法的典型用法代碼示例。如果您正苦於以下問題:Java BatchStatement.getStatements方法的具體用法?Java BatchStatement.getStatements怎麽用?Java BatchStatement.getStatements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.BatchStatement
的用法示例。
在下文中一共展示了BatchStatement.getStatements方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: should_generate_batch_statement
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Test
public void should_generate_batch_statement() throws Exception {
//Given
Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
Option.<ConsistencyLevel>empty(),
Option.empty(),
Option.<RetryPolicy>empty(),
Option.empty());
//When
BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));
//Then
assertThat(actual).isNotNull();
final List<Statement> statements = new ArrayList<>(actual.getStatements());
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);
}
示例2: should_generate_batch_statement
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Test
public void should_generate_batch_statement() throws Exception {
//Given
Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
Option.<ConsistencyLevel>empty(),
Option.empty(),
Option.<RetryPolicy>empty(),
Option.empty(),
Option.empty());
//When
BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));
//Then
assertThat(actual).isNotNull();
final List<Statement> statements = new ArrayList<>(actual.getStatements());
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);
}
示例3: prepared
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
/**
* Processes a Cassandra CQL3 prepared statement and returns the resultset as JsonArray if a SELECT query was fired.
* Just error or ok in the case of altering statements.
*
* @param message
*/
protected void prepared(Message<JsonObject> message) {
//
JsonObject preparedMessage = message.body();
//
String statement = preparedMessage.getString("statement");
JsonArray values = preparedMessage.getArray("values");
//
PreparedStatement preparedStmt = getPreparedStatementCache().addAndGet(statement);
//
BatchStatement query = new BatchStatement();
//
for(int i = 0; i < values.size(); i++) {
//
JsonArray valueList = values.get(i);
//
query.add(preparedStmt.bind(parseArray(valueList.toArray())));
}
//
if(statement.trim().toLowerCase().startsWith("select")) {
//
JsonArray retVals = new JsonArray();
//
for(Statement stmt : query.getStatements()) {
ResultSet resultSet = execute(stmt, message);
// Error or empty => Continue
if(resultSet == null || resultSet.getAvailableWithoutFetching() <= 0) {
continue;
}
//
processResult(resultSet, retVals);
}
// Return the result array
message.reply(retVals);
} else {
//
if(execute(query, message) != null) {
sendOK(message);
}
}
}