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


Java BatchStatement.add方法代碼示例

本文整理匯總了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();

	}
 
開發者ID:abulbasar,項目名稱:cassandra-java-driver-examples,代碼行數:22,代碼來源:BatchStatementExample.java

示例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);
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:17,代碼來源:CassandraConfigDb.java

示例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);
}
 
開發者ID:landawn,項目名稱:AbacusUtil,代碼行數:27,代碼來源:CassandraExecutor.java

示例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);
    }
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:27,代碼來源:DocumentRepositoryImpl.java

示例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);
    }
}
 
開發者ID:prestodb,項目名稱:tempto,代碼行數:20,代碼來源:CassandraBatchLoader.java

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

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

示例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;
}
 
開發者ID:openstack,項目名稱:monasca-persister,代碼行數:17,代碼來源:CassandraRepo.java

示例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);
}
 
開發者ID:spaziocodice,項目名稱:jena-nosql,代碼行數:18,代碼來源:Cassandra2xMapDAO.java

示例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 );
}
 
開發者ID:Tetha,項目名稱:bifroest,代碼行數:20,代碼來源:CassandraAccessLayer.java

示例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);
    }
}
 
開發者ID:1and1,項目名稱:Troilus,代碼行數:24,代碼來源:MutationQuery.java

示例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();
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:19,代碼來源:CassandraAsyncIT.java

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

示例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());
    }
}
 
開發者ID:Stratio,項目名稱:deep-spark,代碼行數:19,代碼來源:DeepCqlRecordWriter.java


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