Search in sources :

Example 6 with BsonInt32

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

the class QueryBatchCursor method asGetMoreCommandDocument.

private BsonDocument asGetMoreCommandDocument() {
    BsonDocument document = new BsonDocument("getMore", new BsonInt64(serverCursor.getId())).append("collection", new BsonString(namespace.getCollectionName()));
    int batchSizeForGetMoreCommand = Math.abs(getNumberToReturn(limit, this.batchSize, count));
    if (batchSizeForGetMoreCommand != 0) {
        document.append("batchSize", new BsonInt32(batchSizeForGetMoreCommand));
    }
    if (maxTimeMS != 0) {
        document.append("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    return document;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 7 with BsonInt32

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

the class DropDatabaseOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1));
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    return commandDocument;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

Example 8 with BsonInt32

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

the class WriteProtocol method createGetLastErrorCommandDocument.

private BsonDocument createGetLastErrorCommandDocument() {
    BsonDocument command = new BsonDocument("getlasterror", new BsonInt32(1));
    command.putAll(writeConcern.asDocument());
    return command;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

Example 9 with BsonInt32

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

the class WriteProtocol method getResponseDocument.

private BsonDocument getResponseDocument(final RequestMessage curMessage, final RequestMessage nextMessage, final WriteConcernResult writeConcernResult, final WriteConcernException writeConcernException) {
    BsonDocument response = new BsonDocument("ok", new BsonInt32(1));
    if (writeConcern.isAcknowledged()) {
        if (writeConcernException == null) {
            appendToWriteCommandResponseDocument(curMessage, nextMessage, writeConcernResult, response);
        } else {
            response.put("n", new BsonInt32(0));
            BsonDocument writeErrorDocument = new BsonDocument("index", new BsonInt32(0)).append("code", new BsonInt32(writeConcernException.getErrorCode()));
            if (writeConcernException.getErrorMessage() != null) {
                writeErrorDocument.append("errmsg", new BsonString(writeConcernException.getErrorMessage()));
            }
            response.put("writeErrors", new BsonArray(singletonList(writeErrorDocument)));
        }
    }
    return response;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 10 with BsonInt32

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

the class DBObjectCodecTest method shouldEncodeIterableMapAsMap.

@Test
public void shouldEncodeIterableMapAsMap() {
    IterableMap iterableMap = new IterableMap();
    iterableMap.put("first", 1);
    DBObjectCodec dbObjectCodec = new DBObjectCodec(fromProviders(asList(new ValueCodecProvider(), new DBObjectCodecProvider(), new BsonValueCodecProvider())));
    DBObject doc = new BasicDBObject("map", iterableMap);
    BsonDocumentWriter writer = new BsonDocumentWriter(new BsonDocument());
    dbObjectCodec.encode(writer, doc, EncoderContext.builder().build());
    assertEquals(new BsonDocument("map", new BsonDocument("first", new BsonInt32(1))), writer.getDocument());
}
Also used : ValueCodecProvider(org.bson.codecs.ValueCodecProvider) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider) BsonInt32(org.bson.BsonInt32) BsonDocumentWriter(org.bson.BsonDocumentWriter) BsonDocument(org.bson.BsonDocument) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider) Test(org.junit.Test)

Aggregations

BsonInt32 (org.bson.BsonInt32)32 BsonDocument (org.bson.BsonDocument)28 BsonString (org.bson.BsonString)18 Test (org.junit.Test)8 BsonArray (org.bson.BsonArray)6 BsonInt64 (org.bson.BsonInt64)6 BsonValue (org.bson.BsonValue)6 Document (org.bson.Document)3 BsonValueCodecProvider (org.bson.codecs.BsonValueCodecProvider)3 ValueCodecProvider (org.bson.codecs.ValueCodecProvider)3 HashMap (java.util.HashMap)2 BsonDocumentWriter (org.bson.BsonDocumentWriter)2 BsonDouble (org.bson.BsonDouble)2 BsonNumber (org.bson.BsonNumber)2 ServerAddress (com.mongodb.ServerAddress)1 SingleResultCallback (com.mongodb.async.SingleResultCallback)1 UpdateRequest (com.mongodb.bulk.UpdateRequest)1 UpdateResult (com.mongodb.client.result.UpdateResult)1 DescriptionHelper.createServerDescription (com.mongodb.connection.DescriptionHelper.createServerDescription)1 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)1