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;
}
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;
}
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));
}
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;
}
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);
}
});
}
Aggregations