Search in sources :

Example 36 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec 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));
}
Also used : BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) WriteCommandResultHelper.getBulkWriteResult(com.mongodb.connection.WriteCommandResultHelper.getBulkWriteResult)

Example 37 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class FindOperation method createExplainableQueryOperation.

private FindOperation<BsonDocument> createExplainableQueryOperation() {
    FindOperation<BsonDocument> explainFindOperation = new FindOperation<BsonDocument>(namespace, new BsonDocumentCodec());
    BsonDocument explainModifiers = new BsonDocument();
    if (modifiers != null) {
        explainModifiers.putAll(modifiers);
    }
    explainModifiers.append("$explain", BsonBoolean.TRUE);
    return explainFindOperation.filter(filter).projection(projection).sort(sort).skip(skip).limit(Math.abs(limit) * -1).modifiers(explainModifiers);
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Example 38 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class ByteBufBsonDocument method toBsonDocument.

private BsonDocument toBsonDocument() {
    ByteBuf duplicateByteBuf = byteBuf.duplicate();
    BsonBinaryReader bsonReader = new BsonBinaryReader(new ByteBufferBsonInput(duplicateByteBuf));
    try {
        return new BsonDocumentCodec().decode(bsonReader, DecoderContext.builder().build());
    } finally {
        duplicateByteBuf.release();
        bsonReader.close();
    }
}
Also used : BsonBinaryReader(org.bson.BsonBinaryReader) ByteBuf(org.bson.ByteBuf) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) ByteBufferBsonInput(org.bson.io.ByteBufferBsonInput)

Example 39 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class ClientMetadataHelper method clientMetadataDocumentTooLarge.

static boolean clientMetadataDocumentTooLarge(final BsonDocument document) {
    BasicOutputBuffer buffer = new BasicOutputBuffer(MAXIMUM_CLIENT_METADATA_ENCODED_SIZE);
    new BsonDocumentCodec().encode(new BsonBinaryWriter(buffer), document, EncoderContext.builder().build());
    return buffer.getPosition() > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE;
}
Also used : BsonBinaryWriter(org.bson.BsonBinaryWriter) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BasicOutputBuffer(org.bson.io.BasicOutputBuffer)

Example 40 with BsonDocumentCodec

use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.

the class CommandMonitoringTest method getWritableCloneOfCommand.

private BsonDocument getWritableCloneOfCommand(final BsonDocument original) {
    BsonDocument clone = new BsonDocument();
    BsonDocumentWriter writer = new BsonDocumentWriter(clone);
    new BsonDocumentCodec(CODEC_REGISTRY_HACK).encode(writer, original, EncoderContext.builder().build());
    return clone;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDocumentWriter(org.bson.BsonDocumentWriter) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Aggregations

BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)56 BsonDocument (org.bson.BsonDocument)29 MongoNamespace (com.mongodb.MongoNamespace)9 BsonBinaryReader (org.bson.BsonBinaryReader)8 BasicOutputBuffer (org.bson.io.BasicOutputBuffer)8 BsonBinaryWriter (org.bson.BsonBinaryWriter)5 ByteBufferBsonInput (org.bson.io.ByteBufferBsonInput)5 JsonReader (org.bson.json.JsonReader)5 Test (org.junit.Test)5 CollectionHelper (com.mongodb.client.test.CollectionHelper)4 NoOpFieldNameValidator (com.mongodb.internal.validator.NoOpFieldNameValidator)4 StringWriter (java.io.StringWriter)4 BsonArray (org.bson.BsonArray)4 BsonString (org.bson.BsonString)4 JsonWriter (org.bson.json.JsonWriter)4 ByteBuffer (java.nio.ByteBuffer)3 BsonDocumentWriter (org.bson.BsonDocumentWriter)3 Before (org.junit.Before)3 MongoClientSettings (com.mongodb.MongoClientSettings)2 MongoCommandException (com.mongodb.MongoCommandException)2