Search in sources :

Example 11 with BulkWriteResult

use of com.mongodb.bulk.BulkWriteResult in project aion by aionnetwork.

the class MongoDB method doBulkWrite.

/**
 * Private helper method for writing a collection of edits into the database
 *
 * @param edits The edits to write
 * @return A summary of the write results
 */
private WriteBatchResult doBulkWrite(WriteBatch edits) {
    if (this.isReadOnly) {
        LOG.info("Skipping writing because database is read only");
        return new WriteBatchResult(true);
    }
    BulkWriteResult writeResult = this.collection.bulkWrite(this.clientSession, edits.getEdits());
    WriteBatchResult result = new WriteBatchResult(writeResult);
    if (result.totalDeletes != edits.getDeleteCount()) {
        LOG.debug("Expected {} deletes but only deleted {}", edits.getDeleteCount(), result.totalDeletes);
    }
    if (result.totalUpdates != edits.getUpdateCount()) {
        LOG.debug("Expected {} upserts but only got {}", edits.getUpdateCount(), result.totalUpdates);
    }
    LOG.debug("Successfully wrote {} edits", edits.getEdits().size());
    return result;
}
Also used : BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Example 12 with BulkWriteResult

use of com.mongodb.bulk.BulkWriteResult in project mongo-java-driver by mongodb.

the class UpdateCommandProtocol method execute.

@Override
public BulkWriteResult execute(final InternalConnection connection) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Updating documents in namespace %s on connection [%s] to server %s", getNamespace(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress()));
    }
    BulkWriteResult writeResult = super.execute(connection);
    LOGGER.debug("Update completed");
    return writeResult;
}
Also used : BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Example 13 with BulkWriteResult

use of com.mongodb.bulk.BulkWriteResult in project mongo-java-driver by mongodb.

the class WriteCommandProtocol method sendMessageAsync.

private void sendMessageAsync(final InternalConnection connection, final ByteBufferBsonOutput buffer, final BaseWriteCommandMessage message, final long startTimeNanos, final SingleResultCallback<BulkWriteResult> clientCallback, final SingleResultCallback<BsonDocument> callback) {
    SingleResultCallback<ResponseBuffers> receiveCallback = new CommandResultCallback<BsonDocument>(callback, new BsonDocumentCodec(), message.getId(), connection.getDescription().getServerAddress());
    connection.sendMessageAsync(buffer.getByteBuffers(), message.getId(), new SendMessageCallback<BulkWriteResult>(connection, buffer, message, message.getCommandName(), startTimeNanos, commandListener, clientCallback, receiveCallback));
}
Also used : BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) WriteCommandResultHelper.getBulkWriteResult(com.mongodb.connection.WriteCommandResultHelper.getBulkWriteResult)

Example 14 with BulkWriteResult

use of com.mongodb.bulk.BulkWriteResult in project mongo-java-driver by mongodb.

the class DeleteCommandProtocol method execute.

@Override
public BulkWriteResult execute(final InternalConnection connection) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Deleting documents from namespace %s on connection [%s] to server %s", getNamespace(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress()));
    }
    BulkWriteResult writeResult = super.execute(connection);
    LOGGER.debug("Delete completed");
    return writeResult;
}
Also used : BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Example 15 with BulkWriteResult

use of com.mongodb.bulk.BulkWriteResult in project mongo-java-driver by mongodb.

the class MongoCollectionImpl method insertOne.

@Override
public void insertOne(final TDocument document, final InsertOneOptions options, final SingleResultCallback<Void> callback) {
    TDocument insertDocument = document;
    if (getCodec() instanceof CollectibleCodec) {
        insertDocument = ((CollectibleCodec<TDocument>) getCodec()).generateIdIfAbsentFromDocument(insertDocument);
    }
    executeSingleWriteRequest(new InsertRequest(documentToBsonDocument(insertDocument)), options.getBypassDocumentValidation(), new SingleResultCallback<BulkWriteResult>() {

        @Override
        public void onResult(final BulkWriteResult result, final Throwable t) {
            callback.onResult(null, t);
        }
    });
}
Also used : CollectibleCodec(org.bson.codecs.CollectibleCodec) InsertRequest(com.mongodb.bulk.InsertRequest) BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Aggregations

BulkWriteResult (com.mongodb.bulk.BulkWriteResult)17 MongoException (com.mongodb.MongoException)5 BsonDocument (org.bson.BsonDocument)5 MongoBulkWriteException (com.mongodb.MongoBulkWriteException)4 Assertions (com.mongodb.assertions.Assertions)4 BulkWriteOptions (com.mongodb.client.model.BulkWriteOptions)4 WriteModel (com.mongodb.client.model.WriteModel)4 ArrayList (java.util.ArrayList)4 WriteConcern (com.mongodb.WriteConcern)3 ConnectionDescription (com.mongodb.connection.ConnectionDescription)3 AsyncCallbackLoop (com.mongodb.internal.async.function.AsyncCallbackLoop)3 AsyncCallbackRunnable (com.mongodb.internal.async.function.AsyncCallbackRunnable)3 LoopState (com.mongodb.internal.async.function.LoopState)3 RetryState (com.mongodb.internal.async.function.RetryState)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 BsonString (org.bson.BsonString)3 Document (org.bson.Document)3 MongoNamespace (com.mongodb.MongoNamespace)2