本文整理匯總了Java中com.datastax.driver.core.BatchStatement.add方法的典型用法代碼示例。如果您正苦於以下問題:Java BatchStatement.add方法的具體用法?Java BatchStatement.add怎麽用?Java BatchStatement.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.BatchStatement
的用法示例。
在下文中一共展示了BatchStatement.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public static void main(String[] args) {
Session session = Connection.connect();
BatchStatement batchStatement = new BatchStatement();
PreparedStatement preparedStatement = session.prepare("insert into user (id, name) values (?, ?)");
int i = 0;
while(i < 10) {
batchStatement.add(preparedStatement.bind(UUIDs.timeBased(), "user-" + i));
++i;
}
try {
ResultSet rs = session.execute(batchStatement);
System.out.println(rs);
} catch (Exception ex) {
ex.printStackTrace();
}
Connection.close();
}
示例2: store
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
public void store(ConfigPath key, String data) throws ConfigDbException {
final BatchStatement batchStat = new BatchStatement();
batchStat.add(getStatement(StatementName.PUT_SETTING).bind(key.toString(), "", data));
ConfigPath parent;
ConfigPath child = key;
while ((parent = child.getParent()) != null) {
batchStat.add(getStatement(StatementName.PUT_SETTING).bind(parent.toString(), child.toString(), data));
child = parent;
}
session.execute(batchStat);
}
示例3: batchInsert
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public ResultSet batchInsert(final Class<?> targetClass, final Collection<? extends Map<String, Object>> propsList, final BatchStatement.Type type) {
N.checkArgument(N.notNullOrEmpty(propsList), "'propsList' can't be null or empty.");
final BatchStatement batchStatement = new BatchStatement(type == null ? BatchStatement.Type.LOGGED : type);
if (settings != null) {
batchStatement.setConsistencyLevel(settings.getConsistency());
batchStatement.setSerialConsistencyLevel(settings.getSerialConsistency());
batchStatement.setRetryPolicy(settings.getRetryPolicy());
if (settings.traceQuery) {
batchStatement.enableTracing();
} else {
batchStatement.disableTracing();
}
}
CP pair = null;
for (Map<String, Object> props : propsList) {
pair = prepareAdd(targetClass, props);
batchStatement.add(prepareStatement(pair.cql, pair.parameters.toArray()));
}
return session.execute(batchStatement);
}
示例4: update
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
public Document update(Document entity)
{
Document old = read(entity.getId()); //will throw exception of doc is not found
entity.setCreatedAt(old.getCreatedAt());//copy over the original create date
Table table = entity.getTable();
PreparedStatement updateStmt = PreparedStatementFactory.getPreparedStatement(String.format(CREATE_CQL, table.toDbTable(), Columns.ID), getSession());
BoundStatement bs = new BoundStatement(updateStmt);
bindCreate(bs, entity);
BatchStatement batch = new BatchStatement(BatchStatement.Type.LOGGED);
batch.add(bs);//the actual update
try
{
List<BoundStatement> indexStatements = IndexMaintainerHelper.generateDocumentUpdateIndexEntriesStatements(getSession(), entity, bucketLocator);
for (BoundStatement boundIndexStatement : indexStatements)
{
batch.add(boundIndexStatement);//the index updates
}
getSession().execute(batch);
return entity;
} catch (IndexParseException e)
{
throw new RuntimeException(e);
}
}
示例5: perform
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public void perform(CassandraPersistenceSession session, Object parameter, BatchStatement flush) {
String deploymentId = (String) parameter;
Session s = session.getSession();
List<Row> processDefinitionsToDelete = s.execute(QueryBuilder.select("id", "key", "version").from(ProcessDefinitionTableHandler.TABLE_NAME).where(eq("deployment_id", deploymentId))).all();
List<String> ids = new ArrayList<String>();
for (Row processDefinitionToDelete : processDefinitionsToDelete) {
ids.add(processDefinitionToDelete.getString("id"));
flush.add(QueryBuilder.delete().all().from(ProcessDefinitionTableHandler.TABLE_NAME_IDX_VERSION)
.where(eq("key", processDefinitionToDelete.getString("key")))
.and(eq("version", processDefinitionToDelete.getInt("version"))));
}
flush.add(QueryBuilder.delete().all().from(ProcessDefinitionTableHandler.TABLE_NAME).where(in("id", ids)));
}
開發者ID:camunda,項目名稱:camunda-engine-cassandra,代碼行數:19,代碼來源:BulkDeleteProcessDefinitionByDeploymentId.java
示例6: load
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public void load(Iterator<List<Object>> rows)
{
PreparedStatement statement = session.prepare(insertQuery);
BatchStatement batch = createBatchStatement();
while (rows.hasNext()) {
if (batch.size() >= batchRowsCount) {
session.execute(batch);
batch = createBatchStatement();
}
List<Object> row = rows.next();
checkState(row.size() == columnsCount, "values count in a row is expected to be %d, but found: %d", columnsCount, row.size());
batch.add(statement.bind(row.toArray()));
}
if (batch.size() > 0) {
session.execute(batch);
}
}
示例7: delete
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void delete(final K... keys) {
if (keys == null || keys.length == 0) {
return;
}
BatchStatement batchStatement = new BatchStatement();
for (K key : keys) {
if (key != null) {
ByteBuffer serializedKey = _keySerializer.serialize(key);
BoundStatement deleteStatement = _deleteStatement.bind(serializedKey);
batchStatement.add(deleteStatement);
}
}
_session.execute(batchStatement);
}
示例8: setAll
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
public void setAll(final Map<K, V> pairs) {
if (pairs.size() == 0) {
return;
}
BatchStatement batchStatement = new BatchStatement();
for (Map.Entry<K, V> entry : pairs.entrySet()) {
batchStatement.add(getInsertStatement(entry.getKey(), entry.getValue()));
}
try {
_session.execute(batchStatement);
} catch (Exception e) {
_log.error("failed to insert batch of " + pairs.size() + " dictionary entries", e);
}
}
示例9: handleFlush_batch
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public int handleFlush_batch(String id) {
Statement query;
int flushedCount = 0;
BatchStatement batch = new BatchStatement(Type.UNLOGGED);
while ((query = queue.poll()) != null) {
flushedCount++;
batch.add(query);
}
executeQuery(id, batch, System.nanoTime());
metricCompleted.inc(flushedCount);
return flushedCount;
}
示例10: delete
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void delete(final K... keys) {
if (keys == null || keys.length == 0) {
return;
}
final BatchStatement batchStatement = new BatchStatement();
for (K key : keys) {
if (key != null) {
batchStatement.add(deleteStatement.bind(keySerializer.serialize(key)));
}
}
session.execute(batchStatement);
}
示例11: insertMetrics
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
public void insertMetrics( RetentionTable table, Collection<Metric> metrics ) {
if ( dryRun ) {
log.debug( "Inserting " + metrics.toString() + " into " + table );
return;
}
if ( session == null ) {
open();
}
BatchStatement batch = new BatchStatement();
for ( Metric metric : metrics ) {
String[] columns = { COL_NAME, COL_TIME, COL_VALUE };
Object[] values = { metric.name(), metric.timestamp(), metric.value() };
Statement stm = QueryBuilder.insertInto( table.tableName() ).values( columns, values );
batch.add( stm );
}
session.execute( batch );
}
示例12: handle
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
private void handle(final BatchStatement batchStmt, final UnmodifiableIterator<T> batchablesIt, final Function<T, ListenableFuture<Statement>> statementFetcher) {
if (batchablesIt.hasNext()) {
final ListenableFuture<Statement> statementFuture = statementFetcher.apply(batchablesIt.next());
Runnable resultHandler = new Runnable() {
@Override
public void run() {
try {
batchStmt.add(statementFuture.get());
handle(batchStmt, batchablesIt, statementFetcher);
} catch (InterruptedException | ExecutionException | RuntimeException e) {
setException(ListenableFutures.unwrapIfNecessary(e));
}
}
};
statementFuture.addListener(resultHandler, MoreExecutors.directExecutor());
} else {
set(batchStmt);
}
}
示例13: transactionMarker
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
public void transactionMarker() throws Exception {
BatchStatement batchStatement = new BatchStatement();
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (100, 'f100', 'l100')"));
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (101, 'f101', 'l101')"));
PreparedStatement preparedStatement =
session.prepare("INSERT INTO test.users (id, fname, lname) VALUES (?, ?, ?)");
for (int i = 200; i < 210; i++) {
BoundStatement boundStatement = new BoundStatement(preparedStatement);
boundStatement.bind(i, "f" + i, "l" + i);
batchStatement.add(boundStatement);
}
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (300, 'f300', 'l300')"));
session.executeAsync(batchStatement).get();
}
示例14: transactionMarker
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
@Override
public void transactionMarker() throws Exception {
BatchStatement batchStatement = new BatchStatement();
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (100, 'f100', 'l100')"));
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (101, 'f101', 'l101')"));
PreparedStatement preparedStatement =
session.prepare("INSERT INTO test.users (id, fname, lname) VALUES (?, ?, ?)");
for (int i = 200; i < 210; i++) {
BoundStatement boundStatement = new BoundStatement(preparedStatement);
boundStatement.bind(i, "f" + i, "l" + i);
batchStatement.add(boundStatement);
}
batchStatement.add(new SimpleStatement(
"INSERT INTO test.users (id, fname, lname) VALUES (300, 'f300', 'l300')"));
session.execute(batchStatement);
}
示例15: run
import com.datastax.driver.core.BatchStatement; //導入方法依賴的package包/類
/**
* Executes cql batch statements in Cassandra
*/
@Override
public void run() {
LOG.debug("[" + this + "] Executing batch write to cassandra");
try {
final PreparedStatement preparedStatement = sessionWithHost.prepare(cql);
final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED);
for (final List<Object> record : records) {
batchStatement.add(preparedStatement.bind(record.toArray(new Object[record.size()])));
}
sessionWithHost.execute(batchStatement);
} catch (Exception e) {
LOG.error("[" + this + "] Exception occurred while trying to execute batch in cassandra: " +
e.getMessage());
}
}