本文整理汇总了Java中com.mongodb.bulk.BulkWriteResult类的典型用法代码示例。如果您正苦于以下问题:Java BulkWriteResult类的具体用法?Java BulkWriteResult怎么用?Java BulkWriteResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BulkWriteResult类属于com.mongodb.bulk包,在下文中一共展示了BulkWriteResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public CompletableFuture<BulkWriteResult> bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests) {
return asyncExecutor.execute(new Callable<BulkWriteResult>() {
@Override
public BulkWriteResult call() throws Exception {
return dbExecutor.bulkWrite(collectionName, requests);
}
});
}
示例2: updateAll
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public <P extends ParaObject> void updateAll(String appid, List<P> objects) {
if (StringUtils.isBlank(appid) || objects == null) {
return;
}
try {
ArrayList<WriteModel<Document>> updates = new ArrayList<WriteModel<Document>>();
List<String> ids = new ArrayList<String>(objects.size());
for (P object : objects) {
if (object != null) {
object.setUpdated(Utils.timestamp());
Document id = new Document(ID, object.getId());
Document data = new Document("$set", toRow(object, Locked.class, true));
UpdateOneModel<Document> um = new UpdateOneModel<Document>(id, data);
updates.add(um);
ids.add(object.getId());
}
}
BulkWriteResult res = getTable(appid).bulkWrite(updates, new BulkWriteOptions().ordered(true));
logger.debug("Updated: " + res.getModifiedCount() + ", keys: " + ids);
} catch (Exception e) {
logger.error(null, e);
}
logger.debug("DAO.updateAll() {}", objects.size());
}
示例3: bulkDelete
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public long bulkDelete(List<?> ids) {
StopWatch watch = new StopWatch();
int deletedRows = 0;
try {
List<DeleteOneModel<T>> models = new ArrayList<>(ids.size());
for (Object id : ids) {
models.add(new DeleteOneModel<>(Filters.eq("_id", id)));
}
BulkWriteResult result = collection().bulkWrite(models, new BulkWriteOptions().ordered(false));
deletedRows = result.getDeletedCount();
return deletedRows;
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("mongoDB", elapsedTime, 0, deletedRows);
logger.debug("bulkDelete, collection={}, size={}, elapsedTime={}", collectionName, ids.size(), elapsedTime);
checkSlowOperation(elapsedTime);
}
}
示例4: toMessage
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public static String toMessage(final String context,
final BulkWriteResult result,
final int objectCount) {
final StringBuilder message = new StringBuilder(128);
message.append("processed ").append(objectCount).append(" ").append(context);
if (result.wasAcknowledged()) {
final int updates = result.getMatchedCount();
final int inserts = objectCount - updates;
message.append(" with ").append(inserts).append(" inserts and ");
message.append(updates).append(" updates");
} else {
message.append(" (result NOT acknowledged)");
}
return message.toString();
}
示例5: bulkDeleteDocuments
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public BulkOperationResult bulkDeleteDocuments(
String dbName,
String collName,
BsonDocument filter,
BsonDocument shardedKeys) {
MongoDatabase mdb = client.getDatabase(dbName);
MongoCollection<BsonDocument> mcoll
= mdb.getCollection(collName, BsonDocument.class);
List<WriteModel<BsonDocument>> deletes = new ArrayList<>();
Bson _filter;
if (shardedKeys != null) {
_filter = and(filter, shardedKeys);
} else {
_filter = filter;
}
deletes.add(new DeleteManyModel<>(_filter));
BulkWriteResult result = mcoll.bulkWrite(deletes);
return new BulkOperationResult(HttpStatus.SC_OK, null, result);
}
示例6: bulkUpsertDocuments
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public static BulkOperationResult bulkUpsertDocuments(
final MongoCollection<BsonDocument> coll,
final BsonArray documents,
final BsonDocument filter,
final BsonDocument shardKeys) {
Objects.requireNonNull(coll);
Objects.requireNonNull(documents);
ObjectId newEtag = new ObjectId();
List<WriteModel<BsonDocument>> wm = getBulkWriteModel(
coll,
documents,
filter,
shardKeys,
newEtag);
BulkWriteResult result = coll.bulkWrite(wm);
return new BulkOperationResult(HttpStatus.SC_OK, newEtag, result);
}
示例7: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public BulkWriteResult bulkWrite(final List<? extends WriteModel<? extends Document>> requests, final BulkWriteOptions options) {
if (options == null) {
return coll.bulkWrite(requests);
} else {
return coll.bulkWrite(requests, options);
}
}
示例8: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public CompletableFuture<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends Document>> requests) {
return asyncExecutor.execute(new Callable<BulkWriteResult>() {
@Override
public BulkWriteResult call() throws Exception {
return collExecutor.bulkWrite(requests);
}
});
}
示例9: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public Observable<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests,
final BulkWriteOptions options) {
return RxObservables.create(Observables.observe(new Block<SingleResultCallback<BulkWriteResult>>() {
@Override
public void apply(final SingleResultCallback<BulkWriteResult> callback) {
wrapped.bulkWrite(requests, options, callback);
}
}), observableAdapter);
}
示例10: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public Publisher<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests,
final BulkWriteOptions options) {
return new ObservableToPublisher<BulkWriteResult>(observe(new Block<SingleResultCallback<BulkWriteResult>>(){
@Override
public void apply(final SingleResultCallback<BulkWriteResult> callback) {
wrapped.bulkWrite(requests, options, callback);
}
}));
}
示例11: saveResolvedTiles
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
/**
* Saves the specified tile spec to the database.
*
* @param stackId stack identifier.
* @param resolvedTileSpecs collection of resolved tile specs (with referenced transforms).
*
* @throws IllegalArgumentException
* if any required parameters or transform spec references are missing.
*/
public void saveResolvedTiles(final StackId stackId,
final ResolvedTileSpecCollection resolvedTileSpecs)
throws IllegalArgumentException {
MongoUtil.validateRequiredParameter("stackId", stackId);
MongoUtil.validateRequiredParameter("resolvedTileSpecs", resolvedTileSpecs);
final Collection<TransformSpec> transformSpecs = resolvedTileSpecs.getTransformSpecs();
final Collection<TileSpec> tileSpecs = resolvedTileSpecs.getTileSpecs();
if (transformSpecs.size() > 0) {
saveResolvedTransforms(stackId, transformSpecs);
}
if (tileSpecs.size() > 0) {
final MongoCollection<Document> tileCollection = getTileCollection(stackId);
final List<WriteModel<Document>> modelList = new ArrayList<>(tileSpecs.size());
Document query = new Document();
Document tileSpecObject;
for (final TileSpec tileSpec : tileSpecs) {
query = new Document("tileId", tileSpec.getTileId());
tileSpecObject = Document.parse(tileSpec.toJson());
modelList.add(new ReplaceOneModel<>(query, tileSpecObject, MongoUtil.UPSERT_OPTION));
}
final BulkWriteResult result = tileCollection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION);
if (LOG.isDebugEnabled()) {
final String bulkResultMessage = MongoUtil.toMessage("tile specs", result, tileSpecs.size());
LOG.debug("saveResolvedTiles: {} using {}.initializeUnorderedBulkOp()",
bulkResultMessage, MongoUtil.fullName(tileCollection), query.toJson());
}
}
}
示例12: toMongoClientBulkWriteResult
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
private SingleResultCallback<BulkWriteResult> toMongoClientBulkWriteResult(Handler<AsyncResult<MongoClientBulkWriteResult>> resultHandler) {
return convertCallback(resultHandler, result -> {
if (result.wasAcknowledged()) {
return convertToMongoClientBulkWriteResult(result.getInsertedCount(),
result.getMatchedCount(), result.getDeletedCount(), result.isModifiedCountAvailable()
? result.getModifiedCount() : (int) MongoClientBulkWriteResult.DEFAULT_MODIFIED_COUNT,
result.getUpserts());
} else {
return null;
}
});
}
示例13: bulkPatchDocuments
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
@Override
public BulkOperationResult bulkPatchDocuments(
String dbName,
String collName,
BsonDocument filter,
BsonDocument shardedKeys,
BsonDocument data) {
MongoDatabase mdb = client.getDatabase(dbName);
MongoCollection<BsonDocument> mcoll
= mdb.getCollection(collName, BsonDocument.class);
List<WriteModel<BsonDocument>> patches = new ArrayList<>();
Bson _filter;
if (shardedKeys != null) {
_filter = and(filter, shardedKeys);
} else {
_filter = filter;
}
patches.add(new UpdateManyModel<>(
_filter,
DAOUtils.getUpdateDocument(data),
DAOUtils.U_NOT_UPSERT_OPS));
BulkWriteResult result = mcoll.bulkWrite(patches);
return new BulkOperationResult(HttpStatus.SC_OK, null, result);
}
示例14: addWriteResult
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
private void addWriteResult(
final BulkWriteResult wr,
final Representation rep,
final String requestPath) {
Representation nrep = new Representation();
if (wr.wasAcknowledged()) {
if (wr.getUpserts() != null) {
nrep.addProperty("inserted",
new BsonInt32(wr.getUpserts().size()));
// add links to new, upserted documents
wr.getUpserts().stream().
forEach(update -> {
nrep.addLink(
new Link("rh:newdoc",
URLUtils
.getReferenceLink(
requestPath,
update.getId())),
true);
});
}
nrep.addProperty("deleted",
new BsonInt32(wr.getDeletedCount()));
if (wr.isModifiedCountAvailable()) {
nrep.addProperty("modified",
new BsonInt32(wr.getModifiedCount()));
}
nrep.addProperty("matched",
new BsonInt32(wr.getMatchedCount()));
rep.addRepresentation("rh:result", nrep);
}
}
示例15: bulkWrite
import com.mongodb.bulk.BulkWriteResult; //导入依赖的package包/类
public BulkWriteResult bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests) {
return collExecutor(collectionName).bulkWrite(requests);
}