Search in sources :

Example 1 with BsonArrayBuilder

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

the class AbstractMongoOplogReader method between.

@Override
public MongoCursor<OplogOperation> between(OpTime from, boolean includeFrom, OpTime to, boolean includeTo) throws MongoException {
    BsonArrayBuilder conditions = new BsonArrayBuilder();
    conditions.add(DefaultBsonValues.newDocument("ts", DefaultBsonValues.newDocument(includeFrom ? "$gte" : "$gt", from.getTimestamp())));
    conditions.add(DefaultBsonValues.newDocument("ts", DefaultBsonValues.newDocument(includeTo ? "$lte" : "$lt", to.getTimestamp())));
    EnumSet<QueryOption> flags = EnumSet.noneOf(QueryOption.class);
    return query(DefaultBsonValues.newDocument("$and", conditions.build()), flags, NATURAL_ORDER_SORT);
}
Also used : BsonArrayBuilder(com.eightkdata.mongowp.utils.BsonArrayBuilder) QueryOption(com.eightkdata.mongowp.messages.request.QueryMessage.QueryOption)

Example 2 with BsonArrayBuilder

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

the class ReplicaSetConfig method toBson.

public BsonDocument toBson() {
    BsonDocumentBuilder result = new BsonDocumentBuilder();
    result.append(ID_FIELD, setName);
    result.append(VERSION_FIELD, version);
    BsonArrayBuilder membersList = new BsonArrayBuilder();
    for (MemberConfig member : members) {
        membersList.add(member.toBson());
    }
    result.append(MEMBERS_FIELD, membersList.build());
    BsonDocumentBuilder settingsBuilder = new BsonDocumentBuilder();
    settingsBuilder.append(CHAINING_ALLOWED_FIELD, chainingAllowed);
    settingsBuilder.append(HEARTHBEAT_TIMEOUT_FIELD, heartbeatTimeoutPeriod);
    BsonDocumentBuilder customWrites = new BsonDocumentBuilder();
    for (Map.Entry<String, ReplicaSetTagPattern> entry : customWriteConcern.entrySet()) {
        String customWriteName = entry.getKey();
        if (customWriteName.startsWith("$")) {
            //MongoDB uses $ as an internal mode
            continue;
        }
        BsonDocument tagMap = entry.getValue().toBson();
        customWrites.appendUnsafe(customWriteName, tagMap);
    }
    settingsBuilder.append(GET_LAST_ERROR_MODES_FIELD, customWrites);
    settingsBuilder.append(GET_LAST_ERROR_DEFAULTS_FIELD, defaultWriteConcern.toDocument());
    settingsBuilder.append(PROTOCOL_VERSION_FIELD, protocolVersion);
    result.append(SETTINGS_FIELD, settingsBuilder);
    return result.build();
}
Also used : BsonArrayBuilder(com.eightkdata.mongowp.utils.BsonArrayBuilder) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) HashMap(java.util.HashMap) Map(java.util.Map) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Example 3 with BsonArrayBuilder

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

the class CollectionOptions method marshall.

public void marshall(BsonDocumentBuilder builder) {
    if (isCapped()) {
        builder.append(CAPPED_FIELD, true);
        long cappedSize = getCappedSize();
        if (cappedSize != 0) {
            builder.append(CAPPED_SIZE_FIELD, cappedSize);
        }
        long cappedMaxDocs = getCappedMaxDocs();
        if (cappedMaxDocs != 0) {
            builder.append(CAPPED_MAX_DOCS_FIELD, cappedMaxDocs);
        }
    }
    Long initialNumExtents = getInitialNumExtents();
    if (initialNumExtents != null && initialNumExtents != 0) {
        builder.append(INITIAL_NUM_EXTENDS_FIELD, initialNumExtents);
    }
    List<Long> initialExtentSizes = getInitialExtentSizes();
    if (initialExtentSizes != null && !initialExtentSizes.isEmpty()) {
        BsonArrayBuilder arrBuilder = new BsonArrayBuilder(initialExtentSizes.size());
        for (Long initialExtentSize : initialExtentSizes) {
            arrBuilder.add(initialExtentSize);
        }
        builder.append(INITIAL_EXTENT_SIZES_FIELD, arrBuilder.build());
    }
    AutoIndexMode autoIndexMode = getAutoIndexMode();
    if (!autoIndexMode.equals(AutoIndexMode.DEFAULT)) {
        boolean value = autoIndexMode.equals(AutoIndexMode.YES);
        builder.append(AUTO_INDEX_MODE_FIELD, value);
    }
    Set<Flag> flags = getFlags();
    if (!flags.isEmpty()) {
        int value = 0;
        for (Flag flag : flags) {
            value |= flag.getBit();
        }
        builder.append(FLAGS_FIELD, value);
    }
    BsonDocument storageEngine = getStorageEngine();
    if (storageEngine != null && storageEngine.isEmpty()) {
        builder.append(STORAGE_ENGINE_FIELD, storageEngine);
    }
    boolean temp = isTemp();
    if (temp) {
        builder.append(TEMP_FIELD, temp);
    }
}
Also used : BsonArrayBuilder(com.eightkdata.mongowp.utils.BsonArrayBuilder) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument)

Example 4 with BsonArrayBuilder

use of com.eightkdata.mongowp.utils.BsonArrayBuilder 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)

Aggregations

BsonArrayBuilder (com.eightkdata.mongowp.utils.BsonArrayBuilder)4 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)2 BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)2 QueryOption (com.eightkdata.mongowp.messages.request.QueryMessage.QueryOption)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1