Search in sources :

Example 11 with NoOpFieldNameValidator

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

the class FindAndUpdateOperation method getValidator.

private FieldNameValidator getValidator() {
    Map<String, FieldNameValidator> map = new HashMap<String, FieldNameValidator>();
    map.put("update", new UpdateFieldNameValidator());
    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) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) MappedFieldNameValidator(com.mongodb.internal.validator.MappedFieldNameValidator) FieldNameValidator(org.bson.FieldNameValidator) UpdateFieldNameValidator(com.mongodb.internal.validator.UpdateFieldNameValidator) UpdateFieldNameValidator(com.mongodb.internal.validator.UpdateFieldNameValidator)

Example 12 with NoOpFieldNameValidator

use of com.mongodb.internal.validator.NoOpFieldNameValidator 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)

Example 13 with NoOpFieldNameValidator

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

the class SingleServerClusterTest method shouldSuccessfullyQueryASecondaryWithPrimaryReadPreference.

@Test
public void shouldSuccessfullyQueryASecondaryWithPrimaryReadPreference() {
    // given
    ServerAddress secondary = getSecondary();
    setUpCluster(secondary);
    String collectionName = getClass().getName();
    Connection connection = cluster.selectServer(new ServerAddressSelector(secondary)).getServer().getConnection();
    // when
    BsonDocument result = connection.command(getDefaultDatabaseName(), new BsonDocument("count", new BsonString(collectionName)), new NoOpFieldNameValidator(), ReadPreference.primary(), new BsonDocumentCodec(), NoOpSessionContext.INSTANCE, getServerApi(), IgnorableRequestContext.INSTANCE);
    // then
    assertEquals(new BsonDouble(1.0).intValue(), result.getNumber("ok").intValue());
}
Also used : ServerAddressSelector(com.mongodb.internal.selector.ServerAddressSelector) NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) ServerAddress(com.mongodb.ServerAddress) BsonDouble(org.bson.BsonDouble) BsonString(org.bson.BsonString) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) Test(org.junit.Test)

Example 14 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) {
    // 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());
    return new EncodingMetadata(firstDocumentStartPosition);
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator)

Example 15 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) {
    // reserved
    bsonOutput.writeInt32(0);
    bsonOutput.writeCString(getCollectionName());
    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 && updateRequest.getUpdateValue().isDocument()) {
        addDocument(updateRequest.getUpdateValue().asDocument(), bsonOutput, new ReplacingDocumentFieldNameValidator());
    } else {
        int bufferPosition = bsonOutput.getPosition();
        BsonValue update = updateRequest.getUpdateValue();
        if (update.isDocument()) {
            addDocument(update.asDocument(), bsonOutput, new UpdateFieldNameValidator());
        } else {
            throw new IllegalArgumentException("Invalid update filter in update request. The filter must be a document.");
        }
        if (bsonOutput.getPosition() == bufferPosition + 5) {
            throw new IllegalArgumentException("Invalid BSON document for an update");
        }
    }
    return new EncodingMetadata(firstDocumentStartPosition);
}
Also used : NoOpFieldNameValidator(com.mongodb.internal.validator.NoOpFieldNameValidator) ReplacingDocumentFieldNameValidator(com.mongodb.internal.validator.ReplacingDocumentFieldNameValidator) UpdateFieldNameValidator(com.mongodb.internal.validator.UpdateFieldNameValidator) BsonValue(org.bson.BsonValue)

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