use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method executeCountDocuments.
public OperationResult executeCountDocuments(final BsonDocument operation) {
MongoCollection<BsonDocument> collection = entities.getCollection(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
BsonDocument filter = arguments.getDocument("filter");
ClientSession session = getSession(arguments);
for (Map.Entry<String, BsonValue> cur : arguments.entrySet()) {
switch(cur.getKey()) {
case "filter":
case "session":
break;
default:
throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey());
}
}
return resultOf(() -> {
if (session == null) {
return new BsonInt64(collection.countDocuments(filter));
} else {
return new BsonInt64(collection.countDocuments(session, filter));
}
});
}
use of org.bson.BsonInt64 in project immutables by immutables.
the class TypeConversionTest method int64.
@Test
public void int64() throws IOException {
BsonInt32 value = new BsonInt32(64);
check(Jsons.readerAt(value).peek()).is(JsonToken.NUMBER);
check(Jsons.readerAt(new BsonInt64(64)).nextInt()).is(64);
check(Jsons.readerAt(new BsonInt64(64)).nextLong()).is(64L);
check(Jsons.readerAt(new BsonInt64(64)).nextDouble()).is(64D);
check(Jsons.readerAt(new BsonInt64(64)).nextString()).is("64");
}
use of org.bson.BsonInt64 in project immutables by immutables.
the class TypeConversionTest method int64.
@Test
void int64() throws IOException {
final BsonInt32 value = new BsonInt32(42);
check(Parsers.parserAt(value).currentToken()).is(JsonToken.VALUE_NUMBER_INT);
check(Parsers.parserAt(new BsonInt64(64)).getNumberType()).is(JsonParser.NumberType.LONG);
check(Parsers.parserAt(new BsonInt64(64)).getIntValue()).is(64);
check(Parsers.parserAt(new BsonInt64(64)).getLongValue()).is(64L);
check(Parsers.parserAt(new BsonInt64(64)).getDoubleValue()).is(64D);
check(Parsers.parserAt(new BsonInt64(64)).getDecimalValue()).is(BigDecimal.valueOf(64));
check(Parsers.parserAt(new BsonInt64(64)).getBigIntegerValue()).is(BigInteger.valueOf(64));
check(Parsers.parserAt(new BsonInt64(64)).getNumberValue()).is(64L);
}
use of org.bson.BsonInt64 in project spring-data-mongodb by spring-projects.
the class BsonUtilsTest method simpleToBsonValue.
// DATAMONGO-625
@Test
void simpleToBsonValue() {
assertThat(BsonUtils.simpleToBsonValue(Long.valueOf(10))).isEqualTo(new BsonInt64(10));
assertThat(BsonUtils.simpleToBsonValue(new Integer(10))).isEqualTo(new BsonInt32(10));
assertThat(BsonUtils.simpleToBsonValue(Double.valueOf(0.1D))).isEqualTo(new BsonDouble(0.1D));
assertThat(BsonUtils.simpleToBsonValue("value")).isEqualTo(new BsonString("value"));
}
Aggregations