本文整理匯總了Java中com.datastax.driver.core.BatchStatement.addAll方法的典型用法代碼示例。如果您正苦於以下問題:Java BatchStatement.addAll方法的具體用法?Java BatchStatement.addAll怎麽用?Java BatchStatement.addAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.BatchStatement
的用法示例。
在下文中一共展示了BatchStatement.addAll方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public boolean run() throws Exception
{
List<BoundStatement> stmts = new ArrayList<>();
partitionCount = partitions.size();
for (PartitionIterator iterator : partitions)
while (iterator.hasNext())
stmts.add(bindRow(iterator.next()));
rowCount += stmts.size();
// 65535 is max number of stmts per batch, so if we have more, we need to manually batch them
for (int j = 0 ; j < stmts.size() ; j += 65535)
{
List<BoundStatement> substmts = stmts.subList(j, Math.min(j + stmts.size(), j + 65535));
Statement stmt;
if (stmts.size() == 1)
{
stmt = substmts.get(0);
}
else
{
BatchStatement batch = new BatchStatement(batchType);
batch.setConsistencyLevel(JavaDriverClient.from(cl));
batch.addAll(substmts);
stmt = batch;
}
try
{
validate(client.getSession().execute(stmt));
}
catch (ClassCastException e)
{
e.printStackTrace();
}
}
return true;
}
示例2: multiPut
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void multiPut(List<List<Object>> keys, List<T> values) {
LOG.debug("Putting the following keys: {} with values: {}", keys, values);
try {
List<Statement> statements = new ArrayList<Statement>();
// Retrieve the mapping statement for the key,val pair
for (int i = 0; i < keys.size(); i++) {
List<Object> key = keys.get(i);
T val = values.get(i);
Statement retrievedStatment = mapper.map(key, val);
if (retrievedStatment instanceof BatchStatement) { // Allows for BatchStatements to be returned by the mapper.
BatchStatement batchedStatment = (BatchStatement) retrievedStatment;
statements.addAll(batchedStatment.getStatements());
} else {
statements.add(retrievedStatment);
}
}
// Execute all the statements as a batch.
BatchStatement batch = new BatchStatement(batchType);
batch.addAll(statements);
session.execute(batch);
_mwrites.incrBy(statements.size());
} catch (Exception e) {
checkCassandraException(e);
LOG.error("Exception {} caught.", e);
}
}
示例3: run
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public boolean run() throws Exception
{
List<BoundStatement> stmts = new ArrayList<>();
partitionCount = partitions.size();
for (PartitionIterator iterator : partitions)
while (iterator.hasNext())
stmts.add(bindRow(iterator.next()));
rowCount += stmts.size();
// 65535 is max number of stmts per batch, so if we have more, we need to manually batch them
for (int j = 0 ; j < stmts.size() ; j += 65535)
{
List<BoundStatement> substmts = stmts.subList(j, Math.min(j + stmts.size(), j + 65535));
Statement stmt;
if (stmts.size() == 1)
{
stmt = substmts.get(0);
}
else
{
BatchStatement batch = new BatchStatement(batchType);
batch.setConsistencyLevel(JavaDriverClient.from(cl));
batch.addAll(substmts);
stmt = batch;
}
client.getSession().execute(stmt);
}
return true;
}
示例4: executeUpdatesSynchronous
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
private void executeUpdatesSynchronous(DBTransaction transaction) {
BatchStatement batchState = new BatchStatement(Type.UNLOGGED);
batchState.addAll(getMutations(transaction));
executeBatch(batchState);
}
示例5: writeSchedule
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
protected void writeSchedule(
ScheduleUpdate update,
Map<ScheduleRef.Entry, EquivalentScheduleEntry> content
) throws WriteException {
DateTime now = clock.now();
ImmutableMultimap<LocalDate, BroadcastRow> currentBroadcastRows = resolveBroadcasts(
update.getSource(),
update.getSchedule().getChannel(),
update.getSchedule().getInterval()
);
ImmutableList<EquivalentScheduleEntry> updateEntries = getEquivalentScheduleEntries(
update.getSchedule(),
content
);
ImmutableSet<BroadcastRef> updateBroadcastRefs = updateEntries
.stream()
.map(EquivalentScheduleEntry::getBroadcast)
.map(Broadcast::toRef)
.collect(MoreCollectors.toImmutableSet());
Set<BroadcastRow> staleBroadcasts = getStaleBroadcasts(
updateBroadcastRefs,
currentBroadcastRows
);
List<Statement> deletes = deleteStatements(
update.getSource(),
update.getSchedule().getChannel(),
staleBroadcasts
);
log.info(
"Processing equivalent schedule update for {} {} {}: content: {}, "
+ "currentEntries:{}, update:{}, stale broadcasts from update:{}, "
+ "stale broadcasts:{}",
update.getSource(),
update.getSchedule().getChannel().longValue(),
update.getSchedule().getInterval(),
content,
currentBroadcastRows.values()
.stream()
.map(BroadcastRow::toString)
.collect(Collectors.joining(",")),
updateLog(updateBroadcastRefs),
updateLog(update.getStaleBroadcasts()),
staleBroadcasts.stream()
.map(BroadcastRow::toString)
.collect(Collectors.joining(","))
);
ImmutableList<Statement> updates = updateEntries
.stream()
.flatMap(entry -> statementsForEntry(update.getSource(), entry, now).stream())
.collect(MoreCollectors.toImmutableList());
if (updates.isEmpty() && deletes.isEmpty()) {
return;
}
BatchStatement updateBatch = new BatchStatement();
updateBatch.addAll(Iterables.concat(updates, deletes));
try {
session.execute(updateBatch.setConsistencyLevel(write));
log.info(
"Processed equivalent schedule update for {} {} {}, updates: {}, "
+ "deletes: {}",
update.getSource(),
update.getSchedule().getChannel().longValue(),
update.getSchedule().getInterval(),
updates.size(),
deletes.size()
);
} catch (NoHostAvailableException | QueryExecutionException e) {
throw new WriteException(e);
}
}