Example usage for com.mongodb BasicDBObjectBuilder add

List of usage examples for com.mongodb BasicDBObjectBuilder add

Introduction

In this page you can find the example usage for com.mongodb BasicDBObjectBuilder add.

Prototype

public BasicDBObjectBuilder add(final String key, final Object val) 

Source Link

Document

Same as append

Usage

From source file:org.sglover.checksum.dao.mongo.MongoChecksumDAO.java

License:Open Source License

private DBObject toDBObject(NodeChecksums documentChecksums) {
    BasicDBObjectBuilder checksumsObjectBuilder = BasicDBObjectBuilder.start();
    for (Map.Entry<Integer, List<Checksum>> checksums : documentChecksums.getChecksums().entrySet()) {
        List<DBObject> checksumDBObjects = new LinkedList<>();
        for (Checksum checksum : checksums.getValue()) {
            DBObject checksumDBObject = toDBObject(checksum);
            checksumDBObjects.add(checksumDBObject);
        }/*w ww.j ava2 s .  c  om*/
        checksumsObjectBuilder.add(String.valueOf(checksums.getKey()), checksumDBObjects);
    }
    DBObject dbObject = BasicDBObjectBuilder.start("n", documentChecksums.getNodeId())
            .add("ni", documentChecksums.getNodeInternalId()).add("v", documentChecksums.getNodeVersion())
            .add("l", documentChecksums.getVersionLabel()).add("b", documentChecksums.getBlockSize())
            .add("nb", documentChecksums.getNumBlocks()).add("c", checksumsObjectBuilder.get()).get();
    return dbObject;
}

From source file:org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.java

License:Apache License

private DBObject resolveCompoundIndexKeyFromStringDefinition(String dotPath, String keyDefinitionString) {

    if (!StringUtils.hasText(dotPath) && !StringUtils.hasText(keyDefinitionString)) {
        throw new InvalidDataAccessApiUsageException("Cannot create index on root level for empty keys.");
    }/*  w  w  w .ja v a 2 s .  c o m*/

    if (!StringUtils.hasText(keyDefinitionString)) {
        return new BasicDBObject(dotPath, 1);
    }

    DBObject dbo = (DBObject) JSON.parse(keyDefinitionString);
    if (!StringUtils.hasText(dotPath)) {
        return dbo;
    }

    BasicDBObjectBuilder dboBuilder = new BasicDBObjectBuilder();

    for (String key : dbo.keySet()) {
        dboBuilder.add(dotPath + "." + key, dbo.get(key));
    }
    return dboBuilder.get();
}

From source file:org.springframework.data.mongodb.core.query.TextCriteria.java

License:Apache License

@Override
public DBObject getCriteriaObject() {

    BasicDBObjectBuilder builder = new BasicDBObjectBuilder();

    if (StringUtils.hasText(language)) {
        builder.add("$language", language);
    }//  w w  w .  j a  v  a 2  s  . co  m

    if (!terms.isEmpty()) {
        builder.add("$search", join(terms));
    }

    if (caseSensitive != null) {
        builder.add("$caseSensitive", caseSensitive);
    }

    if (diacriticSensitive != null) {
        builder.add("$diacriticSensitive", diacriticSensitive);
    }

    return new BasicDBObject("$text", builder.get());
}

From source file:org.teiid.translator.mongodb.MongoDBSelectVisitor.java

License:Open Source License

private DBObject buildGeoNearFunction(Function function) {
    List<Expression> args = function.getParameters();

    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());/* w  w  w  . j av  a  2  s .  c o  m*/
    builder.push("$geometry");//$NON-NLS-1$
    builder.add("type", SpatialType.Point.name());//$NON-NLS-1$

    // walk the co-ordinates
    append(args.get(paramIndex++));
    BasicDBList coordinates = new BasicDBList();
    coordinates.add(this.onGoingExpression.pop());
    builder.add("coordinates", coordinates); //$NON-NLS-1$

    // maxdistance
    append(args.get(paramIndex++));
    builder.pop().add("$maxDistance", this.onGoingExpression.pop()); //$NON-NLS-1$

    return builder.get();
}

From source file:org.teiid.translator.mongodb.MongoDBSelectVisitor.java

License:Open Source License

private DBObject buildGeoFunction(Function function) {
    List<Expression> args = function.getParameters();

    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));

    // Type: Point, LineString, Polygon..
    append(args.get(paramIndex++));//from   w w w. ja  va2s  .c om
    SpatialType type = SpatialType.valueOf((String) this.onGoingExpression.pop());

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    builder.push("$geometry");//$NON-NLS-1$
    builder.add("type", type.name());//$NON-NLS-1$

    // walk the co-ordinates
    append(args.get(paramIndex++));
    BasicDBList coordinates = new BasicDBList();
    coordinates.add(this.onGoingExpression.pop());
    builder.add("coordinates", coordinates); //$NON-NLS-1$
    return builder.get();
}

From source file:uk.ac.ebi.eva.pipeline.io.readers.MongoDbCursorItemReader.java

License:Apache License

private DBObject createDbObjectKeys() {
    if (fields == null) {
        return new BasicDBObject();
    } else {//from w ww.  jav a  2  s . c o  m
        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        for (String field : fields) {
            builder.add(field, 1);
        }
        return builder.get();
    }
}

From source file:uk.ac.ebi.eva.pipeline.io.readers.NonAnnotatedVariantsMongoReader.java

License:Apache License

/**
 * @param studyId Can be the empty string, meaning to bring all non-annotated variants in the collection.
 *  If the studyId string is not empty, bring only non-annotated variants from that study. This parameter should
 *  not be null in any case.// w ww . jav  a  2 s . c  o m
 */
public NonAnnotatedVariantsMongoReader(MongoOperations template, String collectionsVariantsName,
        String studyId) {
    if (studyId == null) {
        throw new IllegalArgumentException("NonAnnotatedVariantsMongoReader needs a non-null studyId "
                + "(it can take a studyId or an empty string for reading every study)");
    }

    setTemplate(template);
    setCollection(collectionsVariantsName);

    BasicDBObjectBuilder queryBuilder = BasicDBObjectBuilder.start();
    if (!studyId.isEmpty()) {
        queryBuilder.add(STUDY_KEY, studyId);
    }
    DBObject query = queryBuilder.add("annot.ct.so", new BasicDBObject("$exists", false)).get();
    setQuery(query);

    String[] fields = { "chr", "start", "end", "ref", "alt" };
    setFields(fields);
}