Search in sources :

Example 16 with BsonInt32

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

the class AbstractServerDiscoveryAndMonitoringTest method applyResponse.

protected void applyResponse(final BsonArray response) {
    ServerAddress serverAddress = new ServerAddress(response.get(0).asString().getValue());
    BsonDocument isMasterResult = response.get(1).asDocument();
    ServerDescription serverDescription;
    if (isMasterResult.isEmpty()) {
        serverDescription = ServerDescription.builder().type(ServerType.UNKNOWN).state(CONNECTING).address(serverAddress).build();
    } else {
        serverDescription = createServerDescription(serverAddress, isMasterResult, getVersion(new BsonDocument("versionArray", new BsonArray(asList(new BsonInt32(2), new BsonInt32(6), new BsonInt32(0))))), 5000000);
    }
    factory.sendNotification(serverAddress, serverDescription);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) DescriptionHelper.createServerDescription(com.mongodb.connection.DescriptionHelper.createServerDescription) BsonArray(org.bson.BsonArray) ServerAddress(com.mongodb.ServerAddress)

Example 17 with BsonInt32

use of org.bson.BsonInt32 in project morphia by mongodb.

the class IndexHelperTest method calculateKeys.

@Test
public void calculateKeys() {
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
    BsonDocument keys = indexHelper.calculateKeys(mappedClass, new IndexBuilder().fields(new FieldBuilder().value("text").type(IndexType.TEXT).weight(1), new FieldBuilder().value("nest").type(IndexType.DESC)));
    assertEquals(new BsonDocument().append("text", new BsonString("text")).append("nest", new BsonInt32(-1)), keys);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 18 with BsonInt32

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

the class X509Authenticator method getAuthCommand.

private BsonDocument getAuthCommand(final String userName) {
    BsonDocument cmd = new BsonDocument();
    cmd.put("authenticate", new BsonInt32(1));
    if (userName != null) {
        cmd.put("user", new BsonString(userName));
    }
    cmd.put("mechanism", new BsonString(AuthenticationMechanism.MONGODB_X509.getMechanismName()));
    return cmd;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 19 with BsonInt32

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

the class NativeAuthenticationHelper method getAuthCommand.

public static BsonDocument getAuthCommand(final String userName, final String authHash, final String nonce) {
    String key = nonce + userName + authHash;
    BsonDocument cmd = new BsonDocument();
    cmd.put("authenticate", new BsonInt32(1));
    cmd.put("user", new BsonString(userName));
    cmd.put("nonce", new BsonString(nonce));
    cmd.put("key", new BsonString(hexMD5(key.getBytes(UTF_8_CHARSET))));
    return cmd;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonString(org.bson.BsonString)

Example 20 with BsonInt32

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

the class QueryProtocol method asFindCommandDocument.

private BsonDocument asFindCommandDocument(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) {
    BsonDocument command = new BsonDocument(FIND_COMMAND_NAME, new BsonString(namespace.getCollectionName()));
    boolean isExplain = false;
    List<ByteBufBsonDocument> documents = ByteBufBsonDocument.create(bsonOutput, firstDocumentPosition);
    ByteBufBsonDocument rawQueryDocument = documents.get(0);
    for (Map.Entry<String, BsonValue> cur : rawQueryDocument.entrySet()) {
        String commandFieldName = META_OPERATOR_TO_COMMAND_FIELD_MAP.get(cur.getKey());
        if (commandFieldName != null) {
            command.append(commandFieldName, cur.getValue());
        } else if (cur.getKey().equals("$explain")) {
            isExplain = true;
        }
    }
    if (command.size() == 1) {
        command.append("filter", rawQueryDocument);
    }
    if (documents.size() == 2) {
        command.append("projection", documents.get(1));
    }
    if (skip != 0) {
        command.append("skip", new BsonInt32(skip));
    }
    if (withLimitAndBatchSize) {
        if (limit != 0) {
            command.append("limit", new BsonInt32(limit));
        }
        if (batchSize != 0) {
            command.append("batchSize", new BsonInt32(batchSize));
        }
    }
    if (tailableCursor) {
        command.append("tailable", BsonBoolean.valueOf(tailableCursor));
    }
    if (noCursorTimeout) {
        command.append("noCursorTimeout", BsonBoolean.valueOf(noCursorTimeout));
    }
    if (oplogReplay) {
        command.append("oplogReplay", BsonBoolean.valueOf(oplogReplay));
    }
    if (awaitData) {
        command.append("awaitData", BsonBoolean.valueOf(awaitData));
    }
    if (partial) {
        command.append("allowPartialResults", BsonBoolean.valueOf(partial));
    }
    if (isExplain) {
        command = new BsonDocument(EXPLAIN_COMMAND_NAME, command);
    }
    return command;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonString(org.bson.BsonString) HashMap(java.util.HashMap) Map(java.util.Map) BsonValue(org.bson.BsonValue)

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