Search in sources :

Example 41 with BsonInt64

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));
        }
    });
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) ClientSession(com.mongodb.client.ClientSession) BsonString(org.bson.BsonString) Map(java.util.Map) BsonValue(org.bson.BsonValue)

Example 42 with BsonInt64

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");
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) Test(org.junit.Test)

Example 43 with BsonInt64

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);
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) Test(org.junit.jupiter.api.Test)

Example 44 with BsonInt64

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"));
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonString(org.bson.BsonString) BsonDouble(org.bson.BsonDouble) Test(org.junit.jupiter.api.Test)

Aggregations

BsonInt64 (org.bson.BsonInt64)44 BsonDocument (org.bson.BsonDocument)36 BsonString (org.bson.BsonString)30 BsonInt32 (org.bson.BsonInt32)20 BsonArray (org.bson.BsonArray)16 BsonDouble (org.bson.BsonDouble)13 BsonValue (org.bson.BsonValue)11 Test (org.junit.Test)7 MongoNamespace (com.mongodb.MongoNamespace)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)3 BsonDocumentReader (org.bson.BsonDocumentReader)3 BsonRegularExpression (org.bson.BsonRegularExpression)3 ObjectId (org.bson.types.ObjectId)3 Test (org.junit.jupiter.api.Test)3 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)2 BsonBoolean (org.bson.BsonBoolean)2 BsonDateTime (org.bson.BsonDateTime)2 BsonNull (org.bson.BsonNull)2