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();
}
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();
}
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();
}
Aggregations