Search in sources :

Example 1 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator in project mongo-java-driver by mongodb.

the class DeleteMessage method encodeMessageBodyWithMetadata.

@Override
protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput, final int messageStartPosition) {
    DeleteRequest deleteRequest = deleteRequests.get(0);
    // reserved
    bsonOutput.writeInt32(0);
    bsonOutput.writeCString(getCollectionName());
    if (deleteRequest.isMulti()) {
        bsonOutput.writeInt32(0);
    } else {
        bsonOutput.writeInt32(1);
    }
    int firstDocumentStartPosition = bsonOutput.getPosition();
    addDocument(deleteRequest.getFilter(), bsonOutput, new NoOpFieldNameValidator());
    if (deleteRequests.size() == 1) {
        return new EncodingMetadata(null, firstDocumentStartPosition);
    } else {
        return new EncodingMetadata(new DeleteMessage(getCollectionName(), deleteRequests.subList(1, deleteRequests.size()), getSettings()), firstDocumentStartPosition);
    }
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) DeleteRequest(com.mongodb.bulk.DeleteRequest)

Example 2 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator in project mongo-java-driver by mongodb.

the class FindAndReplaceOperation method getValidator.

private FieldNameValidator getValidator() {
    Map<String, FieldNameValidator> map = new HashMap<String, FieldNameValidator>();
    map.put("update", new CollectibleDocumentFieldNameValidator());
    return new MappedFieldNameValidator(new NoOpFieldNameValidator(), map);
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) HashMap(java.util.HashMap) MappedFieldNameValidator(com.mongodb.internal.validator.MappedFieldNameValidator) BsonString(org.bson.BsonString) CollectibleDocumentFieldNameValidator(com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) MappedFieldNameValidator(com.mongodb.internal.validator.MappedFieldNameValidator) FieldNameValidator(org.bson.FieldNameValidator) CollectibleDocumentFieldNameValidator(com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator)

Example 3 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator in project mongo-java-driver by mongodb.

the class UpdateMessage method encodeMessageBodyWithMetadata.

@Override
protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOutput, final int messageStartPosition) {
    // reserved
    bsonOutput.writeInt32(0);
    bsonOutput.writeCString(getCollectionName());
    UpdateRequest updateRequest = updates.get(0);
    int flags = 0;
    if (updateRequest.isUpsert()) {
        flags |= 1;
    }
    if (updateRequest.isMulti()) {
        flags |= 2;
    }
    bsonOutput.writeInt32(flags);
    int firstDocumentStartPosition = bsonOutput.getPosition();
    addDocument(updateRequest.getFilter(), bsonOutput, new NoOpFieldNameValidator());
    if (updateRequest.getType() == REPLACE) {
        addCollectibleDocument(updateRequest.getUpdate(), bsonOutput, new CollectibleDocumentFieldNameValidator());
    } else {
        int bufferPosition = bsonOutput.getPosition();
        addDocument(updateRequest.getUpdate(), bsonOutput, new UpdateFieldNameValidator());
        if (bsonOutput.getPosition() == bufferPosition + 5) {
            throw new IllegalArgumentException("Invalid BSON document for an update");
        }
    }
    if (updates.size() == 1) {
        return new EncodingMetadata(null, firstDocumentStartPosition);
    } else {
        return new EncodingMetadata(new UpdateMessage(getCollectionName(), updates.subList(1, updates.size()), getSettings()), firstDocumentStartPosition);
    }
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) UpdateRequest(com.mongodb.bulk.UpdateRequest) CollectibleDocumentFieldNameValidator(com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator) UpdateFieldNameValidator(com.mongodb.internal.validator.UpdateFieldNameValidator)

Example 4 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator in project mongo-java-driver by mongodb.

the class CommandOperationHelper method createReadCommandAndExecute.

static <D, T> T createReadCommandAndExecute(final RetryState retryState, final ReadBinding binding, final ConnectionSource source, final String database, final CommandCreator commandCreator, final Decoder<D> decoder, final CommandReadTransformer<D, T> transformer, final Connection connection) {
    BsonDocument command = commandCreator.create(source.getServerDescription(), connection.getDescription());
    retryState.attach(AttachmentKeys.commandDescriptionSupplier(), command::getFirstKey, false);
    logRetryExecute(retryState);
    return transformer.apply(connection.command(database, command, new NoOpFieldNameValidator(), source.getReadPreference(), decoder, binding.getSessionContext(), binding.getServerApi(), binding.getRequestContext()), source, connection);
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) BsonDocument(org.bson.BsonDocument)

Example 5 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator in project mongo-java-driver by mongodb.

the class TransactionOperation method executeAsync.

@Override
public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<Void> callback) {
    isTrue("in transaction", binding.getSessionContext().hasActiveTransaction());
    executeRetryableWriteAsync(binding, "admin", null, new NoOpFieldNameValidator(), new BsonDocumentCodec(), getCommandCreator(), writeConcernErrorTransformerAsync(), getRetryCommandModifier(), errorHandlingCallback(callback, LOGGER));
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Aggregations

NoOpFieldNameValidator (com.mongodb.internal.validator.NoOpFieldNameValidator)19 MappedFieldNameValidator (com.mongodb.internal.validator.MappedFieldNameValidator)6 HashMap (java.util.HashMap)6 FieldNameValidator (org.bson.FieldNameValidator)6 UpdateFieldNameValidator (com.mongodb.internal.validator.UpdateFieldNameValidator)5 BsonString (org.bson.BsonString)5 CollectibleDocumentFieldNameValidator (com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator)4 BsonDocument (org.bson.BsonDocument)4 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)4 ReplacingDocumentFieldNameValidator (com.mongodb.internal.validator.ReplacingDocumentFieldNameValidator)2 MongoException (com.mongodb.MongoException)1 ServerAddress (com.mongodb.ServerAddress)1 DeleteRequest (com.mongodb.bulk.DeleteRequest)1 UpdateRequest (com.mongodb.bulk.UpdateRequest)1 ClusterDescription (com.mongodb.connection.ClusterDescription)1 ServerDescription (com.mongodb.connection.ServerDescription)1 Connection (com.mongodb.internal.connection.Connection)1 ReadPreferenceServerSelector (com.mongodb.internal.selector.ReadPreferenceServerSelector)1 ServerAddressSelector (com.mongodb.internal.selector.ServerAddressSelector)1 ServerSelector (com.mongodb.selector.ServerSelector)1