use of com.mongodb.WriteConcernResult in project mongo-java-driver by mongodb.
the class DeleteProtocol method execute.
@Override
public WriteConcernResult 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()));
}
WriteConcernResult writeConcernResult = super.execute(connection);
LOGGER.debug("Delete completed");
return writeConcernResult;
}
use of com.mongodb.WriteConcernResult in project mongo-java-driver by mongodb.
the class UpdateProtocol method execute.
@Override
public WriteConcernResult 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()));
}
WriteConcernResult writeConcernResult = super.execute(connection);
LOGGER.debug("Update completed");
return writeConcernResult;
}
use of com.mongodb.WriteConcernResult in project mongo-java-driver by mongodb.
the class MixedBulkWriteOperation method executeLegacyBatchesAsync.
private void executeLegacyBatchesAsync(final AsyncWriteBinding binding, final AsyncConnection connection, final SingleResultCallback<BulkWriteResult> callback) {
List<? extends WriteRequest> writeRequests = getWriteRequests();
LoopState loopState = new LoopState();
AsyncCallbackRunnable loop = new AsyncCallbackLoop(loopState, iterationCallback -> {
int i = loopState.iteration();
if (loopState.breakAndCompleteIf(() -> i == writeRequests.size(), iterationCallback)) {
return;
}
WriteRequest writeRequest = writeRequests.get(i);
SingleResultCallback<WriteConcernResult> commandCallback = (ignored, t) -> iterationCallback.onResult(null, t);
if (writeRequest.getType() == INSERT) {
connection.insertAsync(getNamespace(), isOrdered(), (InsertRequest) writeRequest, binding.getRequestContext(), commandCallback);
} else if (writeRequest.getType() == UPDATE || writeRequest.getType() == REPLACE) {
connection.updateAsync(getNamespace(), isOrdered(), (UpdateRequest) writeRequest, binding.getRequestContext(), commandCallback);
} else {
connection.deleteAsync(getNamespace(), isOrdered(), (DeleteRequest) writeRequest, binding.getRequestContext(), commandCallback);
}
});
loop.run((voidResult, t) -> {
if (t != null) {
callback.onResult(null, t);
} else {
callback.onResult(BulkWriteResult.unacknowledged(), null);
}
});
}
use of com.mongodb.WriteConcernResult in project mongo-java-driver by mongodb.
the class MongoOperationPublisher method createSingleWriteRequestMono.
private Mono<BulkWriteResult> createSingleWriteRequestMono(final Supplier<AsyncWriteOperation<BulkWriteResult>> operation, @Nullable final ClientSession clientSession, final WriteRequest.Type type) {
return createWriteOperationMono(operation, clientSession).onErrorMap(MongoBulkWriteException.class, e -> {
MongoException exception;
WriteConcernError writeConcernError = e.getWriteConcernError();
if (e.getWriteErrors().isEmpty() && writeConcernError != null) {
WriteConcernResult writeConcernResult;
if (type == WriteRequest.Type.INSERT) {
writeConcernResult = WriteConcernResult.acknowledged(e.getWriteResult().getInsertedCount(), false, null);
} else if (type == WriteRequest.Type.DELETE) {
writeConcernResult = WriteConcernResult.acknowledged(e.getWriteResult().getDeletedCount(), false, null);
} else {
writeConcernResult = WriteConcernResult.acknowledged(e.getWriteResult().getMatchedCount() + e.getWriteResult().getUpserts().size(), e.getWriteResult().getMatchedCount() > 0, e.getWriteResult().getUpserts().isEmpty() ? null : e.getWriteResult().getUpserts().get(0).getId());
}
exception = new MongoWriteConcernException(writeConcernError, writeConcernResult, e.getServerAddress());
} else if (!e.getWriteErrors().isEmpty()) {
exception = new MongoWriteException(new WriteError(e.getWriteErrors().get(0)), e.getServerAddress());
} else {
exception = new MongoWriteException(new WriteError(-1, "Unknown write error", new BsonDocument()), e.getServerAddress());
}
for (final String errorLabel : e.getErrorLabels()) {
exception.addLabel(errorLabel);
}
return exception;
});
}
use of com.mongodb.WriteConcernResult in project mongo-java-driver by mongodb.
the class UpdateProtocol method execute.
@Override
public WriteConcernResult 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()));
}
WriteConcernResult writeConcernResult = super.execute(connection);
LOGGER.debug("Update completed");
return writeConcernResult;
}
Aggregations