Search in sources :

Example 11 with BsonDocumentBuilder

use of com.eightkdata.mongowp.utils.BsonDocumentBuilder in project torodb by torodb.

the class IndexOptions method marshall.

public BsonDocument marshall() {
    BsonDocumentBuilder keysDoc = new BsonDocumentBuilder();
    for (Key key : keys) {
        String path = PATH_JOINER.join(key.getKeys());
        BsonValue<?> value = key.getType().toBsonValue();
        keysDoc.appendUnsafe(path, value);
    }
    BsonDocumentBuilder builder = new BsonDocumentBuilder().appendNumber(VERSION_FIELD, version.toInt()).append(NAME_FIELD, name).append(KEYS_FIELD, keysDoc).append(BACKGROUND_FIELD, background).append(UNIQUE_FIELD, unique).append(SPARSE_FIELD, sparse).append(EXPIRE_AFTER_SECONDS_FIELD, expireAfterSeconds);
    if (!storageEngine.isEmpty()) {
        builder.append(STORAGE_ENGINE_FIELD, storageEngine);
    }
    if (database != null && collection != null) {
        builder.append(NAMESPACE_FIELD, database + '.' + collection);
    }
    for (Entry<?> otherProp : otherProps) {
        builder.appendUnsafe(otherProp.getKey(), otherProp.getValue());
    }
    return builder.build();
}
Also used : BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Example 12 with BsonDocumentBuilder

use of com.eightkdata.mongowp.utils.BsonDocumentBuilder in project torodb by torodb.

the class CursorResult method marshall.

public BsonDocument marshall(Function<E, ? extends BsonValue<?>> transformation) {
    BsonArrayBuilder array = new BsonArrayBuilder();
    Iterator<E> firstBatch = getFirstBatch();
    while (firstBatch.hasNext()) {
        array.add(transformation.apply(firstBatch.next()));
    }
    return new BsonDocumentBuilder().append(ID_FIELD, getCursorId()).append(NAMESPACE_FIELD, getDatabase() + '.' + getCollection()).append(FIRST_BATCH_FIELD, array.build()).build();
}
Also used : BsonArrayBuilder(com.eightkdata.mongowp.utils.BsonArrayBuilder) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Example 13 with BsonDocumentBuilder

use of com.eightkdata.mongowp.utils.BsonDocumentBuilder in project torodb by torodb.

the class MemberConfig method toBson.

public BsonDocument toBson() {
    BsonDocumentBuilder object = new BsonDocumentBuilder();
    object.append(ID_FIELD, id);
    object.append(HOST_FIELD, host);
    object.append(ARBITER_ONLY_FIELD, arbiterOnly);
    object.append(BUILD_INDEXES_FIELD, buildIndexes);
    object.append(HIDDEN_FIELD, hidden);
    object.append(PRIORITY_FIELD, priority);
    BsonDocumentBuilder tagsDoc = new BsonDocumentBuilder();
    for (java.util.Map.Entry<String, String> entry : tags.entrySet()) {
        tagsDoc.appendUnsafe(entry.getKey(), DefaultBsonValues.newString(entry.getValue()));
    }
    object.append(TAGS_FIELD, tagsDoc.build());
    object.append(SLAVE_DELAY_FIELD, slaveDelay);
    object.append(VOTES_FIELD, votes);
    return object.build();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Aggregations

BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)13 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)3 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 BsonArrayBuilder (com.eightkdata.mongowp.utils.BsonArrayBuilder)2 WriteMongodTransaction (com.torodb.mongodb.core.WriteMongodTransaction)2 Map (java.util.Map)2 BsonInt32 (com.eightkdata.mongowp.bson.BsonInt32)1 BsonValue (com.eightkdata.mongowp.bson.BsonValue)1 MongoBsonTranslator (com.eightkdata.mongowp.bson.org.bson.utils.MongoBsonTranslator)1 DefaultBsonValues (com.eightkdata.mongowp.bson.utils.DefaultBsonValues)1 DefaultBsonValues.newLong (com.eightkdata.mongowp.bson.utils.DefaultBsonValues.newLong)1 BadValueException (com.eightkdata.mongowp.exceptions.BadValueException)1 NoSuchKeyException (com.eightkdata.mongowp.exceptions.NoSuchKeyException)1 Request (com.eightkdata.mongowp.server.api.Request)1 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)1 Charsets (com.google.common.base.Charsets)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Truth (com.google.common.truth.Truth)1 UserException (com.torodb.core.exceptions.user.UserException)1 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)1