Java 类com.mongodb.bulk.BulkWriteResult 实例源码

项目:AbacusUtil    文件:AsyncMongoDBExecutor.java   
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);
        }
    });
}
项目:para-dao-mongodb    文件:MongoDBDAO.java   
@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());
}
项目:core-ng-project    文件:MongoCollectionImpl.java   
@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);
    }
}
项目:render    文件:MongoUtil.java   
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();
}
项目:restheart    文件:DocumentDAO.java   
@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);
}
项目:restheart    文件:DAOUtils.java   
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);
}
项目:AbacusUtil    文件:AsyncMongoDBExecutor.java   
public CompletableFuture<BulkWriteResult> bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests,
        final BulkWriteOptions options) {
    return asyncExecutor.execute(new Callable<BulkWriteResult>() {
        @Override
        public BulkWriteResult call() throws Exception {
            return dbExecutor.bulkWrite(collectionName, requests, options);
        }
    });
}
项目:AbacusUtil    文件:MongoCollectionExecutor.java   
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);
    }
}
项目:AbacusUtil    文件:AsyncMongoCollectionExecutor.java   
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);
        }
    });
}
项目:AbacusUtil    文件:AsyncMongoCollectionExecutor.java   
public CompletableFuture<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends Document>> requests, final BulkWriteOptions options) {
    return asyncExecutor.execute(new Callable<BulkWriteResult>() {
        @Override
        public BulkWriteResult call() throws Exception {
            return collExecutor.bulkWrite(requests, options);
        }
    });
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@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);
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@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);
        }
    }));
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<BulkWriteResult> bulkWrite(final ClientSession clientSession,
                                            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(clientSession, requests, options, callback);
        }
    }));
}
项目:render    文件:RenderDao.java   
/**
 * 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());
        }
    }

}
项目:vertx-mongo-client    文件:MongoClientImpl.java   
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;
    }
  });
}
项目:restheart    文件:DocumentDAO.java   
@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);
}
项目:restheart    文件:BulkResultRepresentationFactory.java   
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);
    }
}
项目:AbacusUtil    文件:MongoDBExecutor.java   
public BulkWriteResult bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests) {
    return collExecutor(collectionName).bulkWrite(requests);
}
项目:AbacusUtil    文件:MongoDBExecutor.java   
public BulkWriteResult bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests,
        final BulkWriteOptions options) {
    return collExecutor(collectionName).bulkWrite(requests, options);
}
项目:AbacusUtil    文件:MongoCollectionExecutor.java   
public BulkWriteResult bulkWrite(final List<? extends WriteModel<? extends Document>> requests) {
    return bulkWrite(requests, null);
}
项目:mongo-java-driver-rx    文件:MongoCollectionImpl.java   
@Override
public Observable<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests) {
    return bulkWrite(requests, new BulkWriteOptions());
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests) {
    return bulkWrite(requests, new BulkWriteOptions());
}
项目:mongo-java-driver-reactivestreams    文件:MongoCollectionImpl.java   
@Override
public Publisher<BulkWriteResult> bulkWrite(final ClientSession clientSession,
                                            final List<? extends WriteModel<? extends TDocument>> requests) {
    return bulkWrite(clientSession, requests, new BulkWriteOptions());
}
项目:render    文件:MatchDao.java   
public void saveMatches(final MatchCollectionId collectionId,
                        final List<CanvasMatches> matchesList)
        throws IllegalArgumentException {

    MongoUtil.validateRequiredParameter("collectionId", collectionId);
    MongoUtil.validateRequiredParameter("matchesList", matchesList);

    LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}",
              collectionId, matchesList.size());

    if (matchesList.size() > 0) {

        final MongoCollection<Document> collection =
                matchDatabase.getCollection(collectionId.getDbCollectionName());

        ensureMatchIndexes(collection);

        final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size());

        final UpdateOptions upsertOption = new UpdateOptions().upsert(true);
        Document filter;
        Document matchesObject;
        for (final CanvasMatches canvasMatches : matchesList) {
            canvasMatches.normalize();
            filter = new Document(
                    "pGroupId", canvasMatches.getpGroupId()).append(
                    "pId", canvasMatches.getpId()).append(
                    "qGroupId", canvasMatches.getqGroupId()).append(
                    "qId", canvasMatches.getqId());
            matchesObject = Document.parse(canvasMatches.toJson());
            modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption));
        }

        final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION);

        if (LOG.isDebugEnabled()) {
            final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size());
            LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()",
                      bulkResultMessage, MongoUtil.fullName(collection));
        }
    }
}
项目:restheart    文件:BulkOperationResult.java   
public BulkOperationResult(int httpCode, Object etag, BulkWriteResult bulkResult) {
    super(httpCode, etag);

    this.bulkResult = bulkResult;
}
项目:restheart    文件:BulkOperationResult.java   
/**
 * @return the writeResult
 */
public BulkWriteResult getBulkResult() {
    return bulkResult;
}
项目:restheart    文件:BulkResultRepresentationFactory.java   
private void addBulkResult(
        final BulkOperationResult result,
        final RequestContext context,
        final Representation rep,
        final String requestPath) {
    Representation nrep = new Representation();

    BulkWriteResult wr = result.getBulkResult();

    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(
                                                        context,
                                                        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);
    }
}
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param requests the writes to execute
 * @return an Observable with a single element the BulkWriteResult
 */
Observable<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests);
项目:mongo-java-driver-rx    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param requests the writes to execute
 * @param options  the options to apply to the bulk write operation
 * @return an Observable with a single element the BulkWriteResult
 */
Observable<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param requests the writes to execute
 * @return a publisher with a single element the BulkWriteResult
 */
Publisher<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param requests the writes to execute
 * @param options  the options to apply to the bulk write operation
 * @return a publisher with a single element the BulkWriteResult
 */
Publisher<BulkWriteResult> bulkWrite(List<? extends WriteModel<? extends TDocument>> requests, BulkWriteOptions options);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param requests the writes to execute
 * @return a publisher with a single element the BulkWriteResult
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<BulkWriteResult> bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests);
项目:mongo-java-driver-reactivestreams    文件:MongoCollection.java   
/**
 * Executes a mix of inserts, updates, replaces, and deletes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param requests the writes to execute
 * @param options  the options to apply to the bulk write operation
 * @return a publisher with a single element the BulkWriteResult
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<BulkWriteResult> bulkWrite(ClientSession clientSession, List<? extends WriteModel<? extends TDocument>> requests,
                                     BulkWriteOptions options);