本文整理汇总了Java中com.datastax.driver.core.querybuilder.Batch类的典型用法代码示例。如果您正苦于以下问题:Java Batch类的具体用法?Java Batch怎么用?Java Batch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Batch类属于com.datastax.driver.core.querybuilder包,在下文中一共展示了Batch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeAccessTokenUsingRefreshToken
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
String tokenValue = refreshToken.getValue();
// Lookup RefreshTokenToAccessToken table for locating access token
RefreshTokenToAccessToken refreshTokenToAccessToken = refreshTokenToAccessTokenRepository.findOne(tokenValue);
if (refreshTokenToAccessToken != null) {
String accessTokenKey = refreshTokenToAccessToken.getAccessTokenKey();
AccessToken accessToken = accessTokenRepository.findOne(accessTokenKey);
String jsonOAuth2AccessToken = accessToken.getoAuth2AccessToken();
OAuth2AccessToken oAuth2AccessToken = OAuthUtil.deserializeOAuth2AccessToken(jsonOAuth2AccessToken);
// Delete access token from all related tables
List<RegularStatement> statementList = prepareRemoveAccessTokenStatements(oAuth2AccessToken);
// Delete from RefreshTokenToAccessToken table
Delete refreshTokenToAccessTokenDelete = CassandraTemplate.createDeleteQuery(RefreshTokenToAccessToken.TABLE, refreshTokenToAccessToken, null, cassandraTemplate.getConverter());
statementList.add(refreshTokenToAccessTokenDelete);
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
}
示例2: tuneStatementExecutionOptions
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
/**
* Tunes CQL statement execution options (consistency level, fetch option and etc.).
*
* @param statement Statement.
* @return Modified statement.
*/
private Statement tuneStatementExecutionOptions(Statement statement) {
String qry = "";
if (statement instanceof BoundStatement) {
qry = ((BoundStatement)statement).preparedStatement().getQueryString().trim().toLowerCase();
}
else if (statement instanceof PreparedStatement) {
qry = ((PreparedStatement)statement).getQueryString().trim().toLowerCase();
}
boolean readStatement = qry.startsWith("select");
boolean writeStatement = statement instanceof Batch || statement instanceof BatchStatement ||
qry.startsWith("insert") || qry.startsWith("delete") || qry.startsWith("update");
if (readStatement && readConsistency != null) {
statement.setConsistencyLevel(readConsistency);
}
if (writeStatement && writeConsistency != null) {
statement.setConsistencyLevel(writeConsistency);
}
if (fetchSize != null) {
statement.setFetchSize(fetchSize);
}
return statement;
}
示例3: tuneStatementExecutionOptions
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
/**
* Tunes CQL statement execution options (consistency level, fetch option and etc.).
*
* @param statement Statement.
* @return Modified statement.
*/
private Statement tuneStatementExecutionOptions(Statement statement) {
String qry = "";
if (statement instanceof BoundStatement)
qry = ((BoundStatement)statement).preparedStatement().getQueryString().trim().toLowerCase();
else if (statement instanceof PreparedStatement)
qry = ((PreparedStatement)statement).getQueryString().trim().toLowerCase();
boolean readStatement = qry.startsWith("select");
boolean writeStatement = statement instanceof Batch || statement instanceof BatchStatement ||
qry.startsWith("insert") || qry.startsWith("delete") || qry.startsWith("update");
if (readStatement && readConsistency != null)
statement.setConsistencyLevel(readConsistency);
if (writeStatement && writeConsistency != null)
statement.setConsistencyLevel(writeConsistency);
if (fetchSize != null)
statement.setFetchSize(fetchSize);
return statement;
}
示例4: runBatchInsert
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
private void runBatchInsert(List<Insert> insertRequest) {
try {
Batch batch;
if (config.getLoggedBatch()) {
batch = QueryBuilder.batch(insertRequest
.toArray(new RegularStatement[insertRequest.size()]));
} else {
batch = QueryBuilder.unloggedBatch(insertRequest
.toArray(new RegularStatement[insertRequest.size()]));
}
totalCassandraInsertRequest.addAndGet(insertRequest.size());
ResultSetFuture future = cassandraSession.executeAsync(batch);
CallBackListener listener = new CallBackListener(future, null);
future.addListener(listener, pool);
incrementBatchInsertCounter();
pendingRequestCounter.incrementAndGet();
} catch (Throwable ex) {
LOGGER.error("Error publising metrics in MetricCassandraCollector:" + ex.getMessage());
cassandraErrorCount.increment();
registerError(ex);
} finally {
insertRequest.clear();
}
}
示例5: runBatchUpdate
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
private void runBatchUpdate(List<Update> updateRequest) {
try {
Batch batch;
if (config.getLoggedBatch()) {
batch = QueryBuilder.batch(updateRequest
.toArray(new RegularStatement[updateRequest.size()]));
} else {
batch = QueryBuilder.unloggedBatch(updateRequest
.toArray(new RegularStatement[updateRequest.size()]));
}
totalCassandraUpdateRequest.addAndGet(updateRequest.size());
ResultSetFuture future = cassandraSession.executeAsync(batch);
CallBackListener listener = new CallBackListener(future, null);
future.addListener(listener, pool);
incrementBatchUpdateCounter();
pendingRequestCounter.incrementAndGet();
} catch (Throwable ex) {
LOGGER.error("Error publising metrics in MetricCassandraCollector:" + ex.getMessage());
cassandraErrorCount.increment();
registerError(ex);
} finally {
updateRequest.clear();
}
}
示例6: deleteAcls
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
public void deleteAcls(List<AclObjectIdentity> objectIdsToDelete) {
assertAclObjectIdentityList(objectIdsToDelete);
if (LOG.isDebugEnabled()) {
LOG.debug("BEGIN deleteAcls: objectIdsToDelete: " + objectIdsToDelete);
}
List<String> ids = new ArrayList<String>();
for (AclObjectIdentity entry : objectIdsToDelete) {
ids.add(entry.getRowId());
}
Batch batch = QueryBuilder.batch();
batch.add(QueryBuilder.delete().all().from(KEYSPACE, AOI_TABLE).where(QueryBuilder.in("id", ids.toArray())));
batch.add(QueryBuilder.delete().all().from(KEYSPACE, CHILDREN_TABLE).where(QueryBuilder.in("id", ids.toArray())));
session.execute(batch);
if (LOG.isDebugEnabled()) {
LOG.debug("END deleteAcls");
}
}
开发者ID:RigasGrigoropoulos,项目名称:spring-security-acl-cassandra,代码行数:21,代码来源:CassandraAclRepositoryImpl.java
示例7: saveAcl
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
public void saveAcl(AclObjectIdentity aoi) throws AclAlreadyExistsException {
assertAclObjectIdentity(aoi);
if (LOG.isDebugEnabled()) {
LOG.debug("BEGIN saveAcl: aclObjectIdentity: " + aoi);
}
// Check this object identity hasn't already been persisted
if (findAclObjectIdentity(aoi) != null) {
throw new AclAlreadyExistsException("Object identity '" + aoi + "' already exists");
}
Batch batch = QueryBuilder.batch();
batch.add(QueryBuilder.insertInto(KEYSPACE, AOI_TABLE).values(AOI_KEYS, new Object[] { aoi.getRowId(), aoi.getId(), aoi.getObjectClass(), aoi.isEntriesInheriting(),
aoi.getOwnerId(), aoi.isOwnerPrincipal(), aoi.getParentObjectId(), aoi.getParentObjectClass() }));
if (aoi.getParentRowId() != null) {
batch.add(QueryBuilder.insertInto(KEYSPACE, CHILDREN_TABLE).values(CHILD_KEYS, new Object[] { aoi.getParentRowId(), aoi.getRowId(), aoi.getId(), aoi.getObjectClass() }));
}
session.execute(batch);
if (LOG.isDebugEnabled()) {
LOG.debug("END saveAcl");
}
}
开发者ID:RigasGrigoropoulos,项目名称:spring-security-acl-cassandra,代码行数:26,代码来源:CassandraAclRepositoryImpl.java
示例8: storeRefreshToken
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
List<RegularStatement> statementList = new ArrayList<RegularStatement>();
byte[] serializedRefreshToken = SerializationUtils.serialize(refreshToken);
ByteBuffer bufferedRefreshToken = ByteBuffer.wrap(serializedRefreshToken);
byte[] serializedAuthentication = SerializationUtils.serialize(authentication);
ByteBuffer bufferedAuthentication = ByteBuffer.wrap(serializedAuthentication);
WriteOptions refreshWriteOptions = new WriteOptions();
if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken;
Date expiration = expiringRefreshToken.getExpiration();
if (expiration != null) {
int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue();
refreshWriteOptions.setTtl(seconds);
}
}
// Insert into RefreshToken table
Insert accessInsert = CassandraTemplate.createInsertQuery(RefreshToken.TABLE, new RefreshToken(refreshToken.getValue(), bufferedRefreshToken), refreshWriteOptions, cassandraTemplate.getConverter());
statementList.add(accessInsert);
// Insert into RefreshTokenAuthentication table
Insert authInsert = CassandraTemplate.createInsertQuery(RefreshTokenAuthentication.TABLE, new RefreshTokenAuthentication(refreshToken.getValue(), bufferedAuthentication), refreshWriteOptions, cassandraTemplate.getConverter());
statementList.add(authInsert);
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
示例9: removeRefreshToken
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@Override
public void removeRefreshToken(OAuth2RefreshToken token) {
String tokenValue = token.getValue();
List<RegularStatement> statementList = new ArrayList<RegularStatement>();
// Delete from RefreshToken table
statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshToken.class, tokenValue));
// Delete from RefreshTokenAuthentication table
statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshTokenAuthentication.class, tokenValue));
// Delete from RefreshTokenToAccessToken table
statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshTokenToAccessToken.class, tokenValue));
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
示例10: insert
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@SafeVarargs
public final CassandraUtils insert(Map<String, String>... paramss) {
Batch batch = QueryBuilder.unloggedBatch();
for (Map<String, String> params : paramss) {
String columns = "";
String values = "";
for (String s : params.keySet()) {
if (!s.equals(indexColumn)) {
columns += s + ",";
values = values + params.get(s) + ",";
}
}
columns = columns.substring(0, columns.length() - 1);
values = values.substring(0, values.length() - 1);
batch.add(new SimpleStatement(new StringBuilder().append("INSERT INTO ")
.append(qualifiedTable)
.append(" (")
.append(columns)
.append(") VALUES (")
.append(values)
.append(");")
.toString()));
}
execute(batch);
return this;
}
示例11: doCql3SaveToCassandra
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
public static <W> void doCql3SaveToCassandra(RDD<W> rdd, ICassandraDeepJobConfig<W> writeConfig,
Function1<W, Tuple2<Cells, Cells>> transformer) {
if (!writeConfig.getIsWriteConfig()) {
throw new IllegalArgumentException("Provided configuration object is not suitable for writing");
}
Tuple2<Map<String, ByteBuffer>, Map<String, ByteBuffer>> tuple = new Tuple2<>(null, null);
RDD<Tuple2<Cells, Cells>> mappedRDD = rdd.map(transformer,
ClassTag$.MODULE$.<Tuple2<Cells, Cells>>apply(tuple.getClass()));
((CassandraDeepJobConfig) writeConfig).createOutputTableIfNeeded(mappedRDD.first());
final int pageSize = writeConfig.getBatchSize();
int offset = 0;
List<Tuple2<Cells, Cells>> elements = Arrays.asList((Tuple2<Cells, Cells>[]) mappedRDD.collect());
List<Tuple2<Cells, Cells>> split;
do {
split = elements.subList(pageSize * (offset++), Math.min(pageSize * offset, elements.size()));
Batch batch = QueryBuilder.batch();
for (Tuple2<Cells, Cells> t : split) {
Tuple2<String[], Object[]> bindVars = Utils.prepareTuple4CqlDriver(t);
Insert insert = QueryBuilder
.insertInto(quote(writeConfig.getKeyspace()), quote(writeConfig.getTable()))
.values(bindVars._1(), bindVars._2());
batch.add(insert);
}
writeConfig.getSession().execute(batch);
} while (!split.isEmpty() && split.size() == pageSize);
}
示例12: prepareBatch
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
private Batch prepareBatch(RegularStatement... statement) {
Batch batch;
if (batchType != null && batchType.equals(CassandraBatchType.UNLOGGED)) {
batch = QueryBuilder.unloggedBatch(statement);
} else {
batch = QueryBuilder.batch(statement);
}
batch.setConsistencyLevel(getWriteConsistencyLevel());
return batch;
}
示例13: delete
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@Override
public <T> void delete(T obj, ConsistencyLevel consistency) {
checkNotNull(obj, "object argument");
checkNotNull(consistency, "consistency level argument");
checkState(m_isOpen, format("%s is closed", getClass().getSimpleName()));
Schema schema = getSchema(obj);
Batch batchStatement = batch(QueryBuilder.delete().from(schema.getTableName())
.where(eq(schema.getID().getName(), schema.getID().getValue(obj))));
// Remove index entries
for (ColumnSpec colSpec : schema.getColumns()) {
if (colSpec.isIndexed()) {
String tableName = indexTableName(schema.getTableName(), colSpec.getName());
Clause columnClause = eq(colSpec.getName(), colSpec.getValue(obj));
Clause idClause = eq(joinColumnName(schema.getTableName()), schema.getID().getValue(obj));
batchStatement.add(QueryBuilder.delete().from(tableName).where(columnClause).and(idClause));
}
}
// Remove one-to-many relationships
for (OneToManySpec relSpec : schema.getOneToManys()) {
String joinTable = joinTableName(schema.getTableName(), relSpec.getSchema().getTableName());
batchStatement.add(
QueryBuilder.delete().from(joinTable)
.where(eq(joinColumnName(schema.getTableName()), schema.getID().getValue(obj)))
);
}
executeStatement(batchStatement, consistency);
m_instanceCache.remove(getInstanceID(obj));
}
示例14: writeToPath
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
@Override
public void writeToPath(K rowKey,
Path path,
Object structuredValue,
BatchContext batchContext) {
Batch batch = validateAndGetBatch(batchContext);
validateArgs(rowKey, path);
Object simplifiedStructure = writeMapper.convertValue(structuredValue, Object.class);
Map<Path,Object> pathMap = Collections.singletonMap(path, simplifiedStructure);
Map<Path,Object> objectMap = Decomposer.get().decompose(pathMap);
batch = batchContext == null ? batch() : batch;
List<Object> bindArguments = batchContext == null ?
new ArrayList<Object>() :
((CqlBatchContext)batchContext).getBindArguments();
Statement insertStatement = insertInto(tableName)
.value(partitionKeyColumnName, bindMarker())
.value(pathColumnName, bindMarker())
.value(valueColumnName, bindMarker())
.using(timestamp(getCurrentMicros()));
insertStatement.setConsistencyLevel(defaultConsistencyLevel);
for (Map.Entry<Path,Object> entry : objectMap.entrySet()) {
batch.add(insertStatement);
String stringValue = StructureConverter.get().toString(entry.getValue());
bindArguments.add(rowKey);
bindArguments.add(entry.getKey().toString());
bindArguments.add(stringValue);
}
if (batchContext == null) {
Query boundStatement = session.prepare(batch.getQueryString()).bind(bindArguments.toArray());
boundStatement.setConsistencyLevel(defaultConsistencyLevel);
session.execute(boundStatement);
}
}
示例15: validateAndGetBatch
import com.datastax.driver.core.querybuilder.Batch; //导入依赖的package包/类
private Batch validateAndGetBatch(BatchContext batchContext) {
if (batchContext == null) {
return null;
}
if (!(batchContext instanceof CqlBatchContext)) {
throw new IllegalArgumentException("batchContext is not a CQL batch context");
}
return ((CqlBatchContext)batchContext).getBatch();
}