use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class GridFSFileCodec method encode.
@Override
public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) {
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.put("_id", value.getId());
bsonDocument.put("filename", new BsonString(value.getFilename()));
bsonDocument.put("length", new BsonInt64(value.getLength()));
bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize()));
bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime()));
Document metadata = value.getMetadata();
if (metadata != null) {
bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec));
}
bsonDocumentCodec.encode(writer, bsonDocument, encoderContext);
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AtlasDataLakeKillCursorsProseTest method testKillCursorsOnAtlasDataLake.
@Test
public void testKillCursorsOnAtlasDataLake() {
// Initiate find command
MongoCursor<Document> cursor = client.getDatabase(DATABASE_NAME).getCollection(COLLECTION_NAME).find().batchSize(2).cursor();
CommandSucceededEvent findCommandSucceededEvent = commandListener.getCommandSucceededEvent("find");
BsonDocument findCommandResponse = findCommandSucceededEvent.getResponse();
MongoNamespace cursorNamespace = new MongoNamespace(findCommandResponse.getDocument("cursor").getString("ns").getValue());
// Initiate killCursors command
cursor.close();
CommandStartedEvent killCursorsCommandStartedEvent = commandListener.getCommandStartedEvent("killCursors");
CommandSucceededEvent killCursorsCommandSucceededEvent = commandListener.getCommandSucceededEvent("killCursors");
BsonDocument killCursorsCommand = killCursorsCommandStartedEvent.getCommand();
assertEquals(cursorNamespace.getDatabaseName(), killCursorsCommandStartedEvent.getDatabaseName());
assertEquals(cursorNamespace.getCollectionName(), killCursorsCommand.getString("killCursors").getValue());
BsonInt64 cursorId = findCommandResponse.getDocument("cursor").getInt64("id");
assertEquals(cursorId, killCursorsCommand.getArray("cursors").getValues().get(0).asInt64());
assertEquals(cursorId, killCursorsCommandSucceededEvent.getResponse().getArray("cursorsKilled").get(0).asInt64());
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AbstractRetryableReadsTest method processFiles.
private List<BsonDocument> processFiles(final BsonArray bsonArray, final List<BsonDocument> documents) {
for (BsonValue rawDocument : bsonArray.getValues()) {
if (rawDocument.isDocument()) {
BsonDocument document = rawDocument.asDocument();
if (document.get("length").isInt32()) {
document.put("length", new BsonInt64(document.getInt32("length").getValue()));
}
if (document.containsKey("metadata") && document.getDocument("metadata").isEmpty()) {
document.remove("metadata");
}
if (document.containsKey("aliases") && document.getArray("aliases").getValues().size() == 0) {
document.remove("aliases");
}
if (document.containsKey("contentType") && document.getString("contentType").getValue().length() == 0) {
document.remove("contentType");
}
documents.add(document);
}
}
return documents;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class QueryProtocol method asFindCommandResponseDocument.
private BsonDocument asFindCommandResponseDocument(final ResponseBuffers responseBuffers, final QueryResult<T> queryResult, final boolean isExplain) {
List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
if (responseBuffers.getReplyHeader().getNumberReturned() > 0) {
responseBuffers.reset();
rawResultDocuments = ByteBufBsonDocument.createList(responseBuffers);
}
if (isExplain) {
BsonDocument explainCommandResponseDocument = new BsonDocument("ok", new BsonDouble(1));
explainCommandResponseDocument.putAll(rawResultDocuments.get(0));
return explainCommandResponseDocument;
} else {
BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("firstBatch", new BsonArray(rawResultDocuments));
return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
}
use of org.bson.BsonInt64 in project immutables by immutables.
the class BsonReaderTest method bsonToGson.
/**
* Reading from BSON to GSON
*/
@Test
public void bsonToGson() throws Exception {
BsonDocument document = new BsonDocument();
document.append("boolean", new BsonBoolean(true));
document.append("int32", new BsonInt32(32));
document.append("int64", new BsonInt64(64));
document.append("double", new BsonDouble(42.42D));
document.append("string", new BsonString("foo"));
document.append("null", new BsonNull());
document.append("array", new BsonArray());
document.append("object", new BsonDocument());
JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
check(element.isJsonObject());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");
check(element.getAsJsonObject().get("null").isJsonNull());
check(element.getAsJsonObject().get("array").isJsonArray());
check(element.getAsJsonObject().get("object").isJsonObject());
}
Aggregations