本文整理汇总了Java中com.datastax.driver.core.querybuilder.Batch.add方法的典型用法代码示例。如果您正苦于以下问题:Java Batch.add方法的具体用法?Java Batch.add怎么用?Java Batch.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.querybuilder.Batch
的用法示例。
在下文中一共展示了Batch.add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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
示例3: 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;
}
示例4: 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);
}
示例5: 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));
}
示例6: 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);
}
}
示例7: create
import com.datastax.driver.core.querybuilder.Batch; //导入方法依赖的package包/类
@Override
public <T> T create(T object, ConsistencyLevel consistency) {
checkNotNull(object, "object argument");
checkNotNull(consistency, "consistency argument");
checkState(m_isOpen, format("%s is closed", getClass().getSimpleName()));
checkArgument(
object.getClass().isAnnotationPresent(ENTITY),
format("%s not annotated with @%s", getClass().getSimpleName(), ENTITY.getCanonicalName()));
Schema schema = getSchema(object);
checkArgument(
schema.getID().getValue(object) == null,
format("property annotated with @%s must be null", ID.getCanonicalName()));
// Object persistence (incl. indices)
UUID id = UUID.randomUUID();
Batch batch = batch();
Insert insertStatement = insertInto(schema.getTableName()).value(schema.getID().getName(), id);
for (ColumnSpec colSpec : schema.getColumns()) {
insertStatement.value(colSpec.getName(), colSpec.getValue(object));
if (colSpec.isIndexed()) {
String tableName = indexTableName(schema.getTableName(), colSpec.getName());
batch.add(
insertInto(tableName)
.value(colSpec.getName(), colSpec.getValue(object))
.value(joinColumnName(schema.getTableName()), id)
);
}
}
batch.add(insertStatement);
// One-to-Many relationship persistence
for (OneToManySpec relationSpec : schema.getOneToManys()) {
Schema s = relationSpec.getSchema();
Object relations = relationSpec.getValue(object);
if (relations == null) {
continue;
}
for (Object item : (Collection<?>) relations) {
UUID relationID = (UUID) s.getID().getValue(item);
if (relationID == null) {
throw new IllegalStateException(
"encountered relation with null ID property (entity not persisted?)");
}
String joinTable = joinTableName(schema.getTableName(), s.getTableName());
batch.add(
insertInto(joinTable)
.value(joinColumnName(schema.getTableName()), id)
.value(joinColumnName(s.getTableName()), relationID)
);
}
}
executeStatement(batch, consistency);
schema.getID().setValue(object, id);
cacheInstance(object);
return object;
}
示例8: deletePath
import com.datastax.driver.core.querybuilder.Batch; //导入方法依赖的package包/类
@Override
public void deletePath(K rowKey, Path path, BatchContext batchContext) {
Batch batch = validateAndGetBatch(batchContext);
validateArgs(rowKey, path);
// converting from a string and back normalizes the path, e.g. makes sure ends with the delimiter character
String start = path.toString();
String finish = getFinishString(start);
// would like to just do a delete with a where clause, but unfortunately Cassandra can't do that in CQL (either)
// with >= and <=
// Since the path column is in the primary key, we need to just delete whole rows.
Object[] args = {rowKey,start,finish};
ResultSet resultSet = session.execute(readForDeleteQuery.bind(args));
if (resultSet.isExhausted()) {
// not found
return;
}
Delete deleteStatement = delete().from(tableName);
deleteStatement
.using(timestamp(getCurrentMicros()))
.where(eq(partitionKeyColumnName, rowKey))
.and(eq(pathColumnName, bindMarker()));
batch = batchContext == null ? batch() : batch;
List<Object> bindArguments = batchContext == null ?
new ArrayList<Object>() :
((CqlBatchContext)batchContext).getBindArguments();
for (Row row : resultSet) {
String pathToDelete = row.getString(0);
batch.add(deleteStatement);
bindArguments.add(pathToDelete);
}
if (batchContext == null) {
BoundStatement query = session.prepare(batch.getQueryString()).bind(bindArguments.toArray());
query.setConsistencyLevel(defaultConsistencyLevel);
session.execute(query);
}
}
示例9: updateAcl
import com.datastax.driver.core.querybuilder.Batch; //导入方法依赖的package包/类
public void updateAcl(AclObjectIdentity aoi, List<AclEntry> entries) throws AclNotFoundException {
assertAclObjectIdentity(aoi);
if (LOG.isDebugEnabled()) {
LOG.debug("BEGIN updateAcl: aclObjectIdentity: " + aoi + ", entries: " + entries);
}
// Check this object identity is already persisted
AclObjectIdentity persistedAoi = findAclObjectIdentity(aoi);
if (persistedAoi == null) {
throw new AclNotFoundException("Object identity '" + aoi + "' does not exist");
}
// Update AOI & delete existing ACLs
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() }));
batch.add(QueryBuilder.delete().all().from(KEYSPACE, ACL_TABLE).where(QueryBuilder.eq("id", aoi.getRowId())));
// Check if parent is different and delete from children table
boolean parentChanged = false;
if (!(persistedAoi.getParentRowId() == null ? aoi.getParentRowId() == null : persistedAoi.getParentRowId().equals(aoi.getParentRowId()))) {
parentChanged = true;
if (persistedAoi.getParentRowId() != null) {
batch.add(QueryBuilder.delete().all().from(KEYSPACE, CHILDREN_TABLE).where(QueryBuilder.eq("id", persistedAoi.getParentRowId())).and(QueryBuilder.eq("childId", aoi.getRowId())));
}
}
session.execute(batch);
// Update ACLs & children table
batch = QueryBuilder.batch();
boolean executeBatch = false;
if (entries != null && !entries.isEmpty()) {
for (AclEntry entry : entries) {
batch.add(QueryBuilder.insertInto(KEYSPACE, ACL_TABLE).values(ACL_KEYS, new Object[] { aoi.getRowId(), entry.getOrder(), entry.getSid(), entry.getMask(), entry.isSidPrincipal(),
entry.isGranting(), entry.isAuditSuccess(), entry.isAuditFailure() }));
}
executeBatch = true;
}
if (parentChanged) {
if (aoi.getParentRowId() != null) {
batch.add(QueryBuilder.insertInto(KEYSPACE, CHILDREN_TABLE).values(CHILD_KEYS, new Object[] { aoi.getParentRowId(), aoi.getRowId(), aoi.getId(), aoi.getObjectClass() }));
}
executeBatch = true;
}
if (executeBatch) {
session.execute(batch);
}
if (LOG.isDebugEnabled()) {
LOG.debug("END updateAcl");
}
}
开发者ID:RigasGrigoropoulos,项目名称:spring-security-acl-cassandra,代码行数:56,代码来源:CassandraAclRepositoryImpl.java