use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CommandMonitoringTest method massageActualCommandSucceededEvent.
private CommandSucceededEvent massageActualCommandSucceededEvent(final CommandSucceededEvent actual) {
BsonDocument response = getWritableCloneOfCommand(actual.getResponse());
// massage numbers that are the wrong BSON type
response.put("ok", new BsonDouble(response.getNumber("ok").doubleValue()));
if (response.containsKey("n")) {
response.put("n", new BsonInt32(response.getNumber("n").intValue()));
}
if (actual.getCommandName().equals("find") || actual.getCommandName().equals("getMore")) {
if (response.containsKey("cursor")) {
if (response.getDocument("cursor").containsKey("id") && !response.getDocument("cursor").getInt64("id").equals(new BsonInt64(0))) {
response.getDocument("cursor").put("id", new BsonInt64(42));
}
}
} else if (actual.getCommandName().equals("killCursors")) {
response.getArray("cursorsUnknown").set(0, new BsonInt64(42));
} else if (isWriteCommand(actual.getCommandName())) {
if (response.containsKey("writeErrors")) {
for (Iterator<BsonValue> iter = response.getArray("writeErrors").iterator(); iter.hasNext(); ) {
BsonDocument cur = iter.next().asDocument();
cur.put("code", new BsonInt32(42));
cur.put("errmsg", new BsonString(""));
}
}
if (actual.getCommandName().equals("update")) {
response.remove("nModified");
}
}
return new CommandSucceededEvent(actual.getRequestId(), actual.getConnectionDescription(), actual.getCommandName(), response, actual.getElapsedTime(TimeUnit.NANOSECONDS));
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class GridFSTest 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 pinpoint by naver.
the class MongoDBITBase method createComplexDocument.
private Document createComplexDocument() {
// insert Data
BsonValue a = new BsonString("stest");
BsonValue b = new BsonDouble(111);
BsonValue c = new BsonBoolean(true);
Document document = new Document().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)).append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())).append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")).append("objectId", new BsonObjectId(new ObjectId())).append("code", new BsonJavaScript("int i = 10;")).append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))).append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")).append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)).append("undefined", new BsonUndefined()).append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })).append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })).append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))).append("document", new BsonDocument("a", new BsonInt32(77))).append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull());
return document;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class IdHoldingBsonWriter method writeInt64.
@Override
public void writeInt64(final long value) {
addBsonValue(() -> new BsonInt64(value), () -> getIdBsonWriter().writeInt64(value));
super.writeInt64(value);
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CommandMessage method getExtraElements.
private List<BsonElement> getExtraElements(final SessionContext sessionContext) {
List<BsonElement> extraElements = new ArrayList<BsonElement>();
extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName())));
if (sessionContext.getClusterTime() != null) {
extraElements.add(new BsonElement("$clusterTime", sessionContext.getClusterTime()));
}
if (sessionContext.hasSession() && responseExpected) {
extraElements.add(new BsonElement("lsid", sessionContext.getSessionId()));
}
boolean firstMessageInTransaction = sessionContext.notifyMessageSent();
assertFalse(sessionContext.hasActiveTransaction() && sessionContext.isSnapshot());
if (sessionContext.hasActiveTransaction()) {
checkServerVersionForTransactionSupport();
extraElements.add(new BsonElement("txnNumber", new BsonInt64(sessionContext.getTransactionNumber())));
if (firstMessageInTransaction) {
extraElements.add(new BsonElement("startTransaction", BsonBoolean.TRUE));
addReadConcernDocument(extraElements, sessionContext);
}
extraElements.add(new BsonElement("autocommit", BsonBoolean.FALSE));
} else if (sessionContext.isSnapshot()) {
addReadConcernDocument(extraElements, sessionContext);
}
if (serverApi != null) {
addServerApiElements(extraElements);
}
if (readPreference != null) {
if (!readPreference.equals(primary())) {
extraElements.add(new BsonElement("$readPreference", readPreference.toDocument()));
} else if (isDirectConnectionToReplicaSetMember()) {
extraElements.add(new BsonElement("$readPreference", primaryPreferred().toDocument()));
}
}
return extraElements;
}
Aggregations