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.apache.rya.indexing.mongodb.temporal.TemporalMongoDBStorageStrategy.java

License:Apache License

public DBObject getTimeValue(final String timeData) {
    final Matcher match = TemporalInstantRfc3339.PATTERN.matcher(timeData);
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    if (match.find()) {
        final TemporalInterval date = TemporalInstantRfc3339.parseInterval(timeData);
        builder.add(INTERVAL_START, date.getHasBeginning().getAsDateTime().toDate());
        builder.add(INTERVAL_END, date.getHasEnd().getAsDateTime().toDate());
    } else {// w w w.java 2  s.  com
        builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate());
    }
    return builder.get();
}

From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java

License:Apache License

/**
 * Checks if the field intersects the set.
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param field the field to check./*  w ww  .  jav a  2s .co m*/
 * @param set the set to check.
 * @return the $setIntersection expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder setIntersection(final BasicDBObjectBuilder builder, final String field,
        final Object[] set) {
    checkNotNull(builder);
    builder.add("$setIntersection", Arrays.asList(field, set));
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java

License:Apache License

/**
 * Checks if the expression is a subset of the set.
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param expression the expression to see if it's in the set.
 * @param set the set to check against.//from  ww  w .  ja v  a2s.co m
 * @return the $setIsSubset expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder setIsSubset(final BasicDBObjectBuilder builder, final DBObject expression,
        final Object[] set) {
    checkNotNull(builder);
    builder.add("$setIsSubset", Arrays.asList(expression, set).toArray(new Object[0]));
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.aggregation.SetOperators.java

License:Apache License

/**
 * Checks if any elements from the expression are {@code true}.
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param expression the expression to see if any elements are {@code true}.
 * @return the $anyElementTrue expression {@link BasicDBObjectBuilder}.
 *///from  ww w  . jav a 2  s.com
public static BasicDBObjectBuilder anyElementTrue(final BasicDBObjectBuilder builder,
        final DBObject expression) {
    checkNotNull(builder);
    builder.add("$anyElementTrue", expression);
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.query.ArrayOperators.java

License:Apache License

/**
 * Creates an $size MongoDB expression./*  w w  w .  java 2  s  . c  o m*/
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param expression the expression to get the size of.
 * @return the $size expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder size(final BasicDBObjectBuilder builder, final Object expression) {
    checkNotNull(builder);
    builder.add("$size", expression);
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.query.ComparisonOperators.java

License:Apache License

/**
 * Creates a $gt MongoDB expression.//  ww w  . j  a  v  a2  s . c om
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param expression the expression.
 * @param value the value to test if the expression is greater than
 * @return the $gt expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder gt(final BasicDBObjectBuilder builder, final BasicDBObject expression,
        final Number value) {
    checkNotNull(builder);
    builder.add("$gt", Arrays.asList(expression, value));
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.query.ComparisonOperators.java

License:Apache License

/**
 * Creates an $eq MongoDB expression.//  w  w w. ja  v  a  2s  .  c  o m
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param expression1 the first expression.
 * @param expression2 the second expression.
 * @return the $eq expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder eq(final BasicDBObjectBuilder builder, final BasicDBObject expression1,
        final Object expression2) {
    checkNotNull(builder);
    builder.add("$eq", Arrays.asList(expression1, expression2));
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.query.LogicalOperators.java

License:Apache License

/**
 * Creates an $and MongoDB expression./*from w  w w .  ja va 2  s.  c  o m*/
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param lhs the left-hand side operand.
 * @param rhs the right-hand side operand.
 * @param extras any additional operands.
 * @return the $and expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder and(final BasicDBObjectBuilder builder, final BasicDBObject lhs,
        final BasicDBObject rhs, final BasicDBObject... extras) {
    checkNotNull(builder);
    final List<BasicDBObject> operands = Lists.newArrayList(lhs, rhs);

    if (extras != null && extras.length > 0) {
        operands.addAll(Lists.newArrayList(extras));
    }

    builder.add("$and", operands);
    return builder;
}

From source file:org.apache.rya.mongodb.document.operators.query.LogicalOperators.java

License:Apache License

/**
 * Creates an $or MongoDB expression.//from w w  w  . ja  va  2  s  . co m
 * @param builder the {@link BasicDBObjectBuilder}. (not {@code null})
 * @param lhs the left-hand side operand.
 * @param rhs the right-hand side operand.
 * @param extras any additional operands.
 * @return the $or expression {@link BasicDBObjectBuilder}.
 */
public static BasicDBObjectBuilder or(final BasicDBObjectBuilder builder, final BasicDBObject lhs,
        final BasicDBObject rhs, final BasicDBObject... extras) {
    checkNotNull(builder);
    final List<BasicDBObject> operands = Lists.newArrayList(lhs, rhs);

    if (extras != null && extras.length > 0) {
        operands.addAll(Lists.newArrayList(extras));
    }

    builder.add("$or", operands);
    return builder;
}

From source file:org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.java

License:Apache License

/**
 * Serializes a {@link DocumentVisibility} to a MongoDB {@link DBObject}.
 * @param documentVisibility the {@link DocumentVisibility} to be
 * serialized./*from   ww w  .  j a  v  a 2 s  .  co m*/
 * @return The MongoDB {@link DBObject}.
 */
public static BasicDBObject toDBObject(final DocumentVisibility documentVisibility) {
    DocumentVisibility dv;
    if (documentVisibility == null) {
        dv = MongoDbRdfConstants.EMPTY_DV;
    } else {
        dv = documentVisibility;
    }
    Object[] dvArray = null;
    try {
        dvArray = DocumentVisibilityUtil.toMultidimensionalArray(dv);
    } catch (final DocumentVisibilityConversionException e) {
        log.error("Unable to convert document visibility");
    }

    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.add(DOCUMENT_VISIBILITY_KEY, dvArray);
    return (BasicDBObject) builder.get();
}