當前位置: 首頁>>代碼示例>>Java>>正文


Java BatchStatement.getStatements方法代碼示例

本文整理匯總了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);
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:25,代碼來源:InterpreterLogicTest.java

示例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);
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:26,代碼來源:InterpreterLogicTest.java

示例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);
		}
	}
}
 
開發者ID:nea,項目名稱:vertx-mod-cassandra-persistor,代碼行數:53,代碼來源:CassandraPersistor.java


注:本文中的com.datastax.driver.core.BatchStatement.getStatements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。