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


Java BatchStatement.addAll方法代碼示例

本文整理匯總了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;
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:40,代碼來源:SchemaInsert.java

示例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);
    }
}
 
開發者ID:hpcc-systems,項目名稱:storm-cassandra-cql,代碼行數:32,代碼來源:CassandraCqlMapState.java

示例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;
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:33,代碼來源:SchemaInsert.java

示例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);
}
 
開發者ID:QSFT,項目名稱:Doradus,代碼行數:6,代碼來源:CQLTransaction.java

示例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);
    }
}
 
開發者ID:atlasapi,項目名稱:atlas-deer,代碼行數:82,代碼來源:CassandraEquivalentScheduleStore.java


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