Search in sources :

Example 1 with CollectibleDocumentFieldNameValidator

use of com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator 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 2 with CollectibleDocumentFieldNameValidator

use of com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator 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 3 with CollectibleDocumentFieldNameValidator

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

the class InsertCommandMessage method getFieldNameValidator.

@Override
protected FieldNameValidator getFieldNameValidator() {
    Map<String, FieldNameValidator> map = new HashMap<String, FieldNameValidator>();
    map.put("documents", 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) 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)

Aggregations

CollectibleDocumentFieldNameValidator (com.mongodb.internal.validator.CollectibleDocumentFieldNameValidator)3 NoOpFieldNameValidator (com.mongodb.internal.validator.NoOpFieldNameValidator)3 MappedFieldNameValidator (com.mongodb.internal.validator.MappedFieldNameValidator)2 HashMap (java.util.HashMap)2 FieldNameValidator (org.bson.FieldNameValidator)2 UpdateRequest (com.mongodb.bulk.UpdateRequest)1 UpdateFieldNameValidator (com.mongodb.internal.validator.UpdateFieldNameValidator)1 BsonString (org.bson.BsonString)1