Search in sources :

Example 1 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project morphia by mongodb.

the class DatastoreImpl method ensureCaps.

@Override
public void ensureCaps() {
    for (final MappedClass mc : mapper.getMappedClasses()) {
        if (mc.getEntityAnnotation() != null && mc.getEntityAnnotation().cap().value() > 0) {
            final CappedAt cap = mc.getEntityAnnotation().cap();
            final String collName = mapper.getCollectionName(mc.getClazz());
            final BasicDBObjectBuilder dbCapOpts = start("capped", true);
            if (cap.value() > 0) {
                dbCapOpts.add("size", cap.value());
            }
            if (cap.count() > 0) {
                dbCapOpts.add("max", cap.count());
            }
            final DB database = getDB();
            if (database.getCollectionNames().contains(collName)) {
                final DBObject dbResult = database.command(start("collstats", collName).get());
                if (dbResult.containsField("capped")) {
                    LOG.debug("DBCollection already exists and is capped already; doing nothing. " + dbResult);
                } else {
                    LOG.warning("DBCollection already exists with same name(" + collName + ") and is not capped; not creating capped version!");
                }
            } else {
                getDB().createCollection(collName, dbCapOpts.get());
                LOG.debug("Created capped DBCollection (" + collName + ") with opts " + dbCapOpts);
            }
        }
    }
}
Also used : CappedAt(org.mongodb.morphia.annotations.CappedAt) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) MappedClass(org.mongodb.morphia.mapping.MappedClass) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DB(com.mongodb.DB)

Example 2 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project morphia by mongodb.

the class GeoFieldCriteria method addTo.

@Override
public void addTo(final DBObject obj) {
    final BasicDBObjectBuilder query;
    switch(getOperator()) {
        case NEAR:
            query = BasicDBObjectBuilder.start(FilterOperator.NEAR.val(), getValue());
            break;
        case NEAR_SPHERE:
            query = BasicDBObjectBuilder.start(FilterOperator.NEAR_SPHERE.val(), getValue());
            break;
        case WITHIN_BOX:
            query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
            break;
        case WITHIN_CIRCLE:
            query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
            break;
        case WITHIN_CIRCLE_SPHERE:
            query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
            break;
        default:
            throw new UnsupportedOperationException(getOperator() + " not supported for geo-query");
    }
    //add options...
    if (opts != null) {
        for (final Map.Entry<String, Object> e : opts.entrySet()) {
            query.append(e.getKey(), e.getValue());
        }
    }
    obj.put(getField(), query.get());
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Map(java.util.Map)

Example 3 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.

the class MongoDetailsAdapter method toDBObject.

static DBObject toDBObject(final PCJDetails pcjDetails) {
    requireNonNull(pcjDetails);
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    // PCJ ID
    builder.add(PCJ_ID_KEY, pcjDetails.getId());
    // PCJ Update Strategy if present.
    if (pcjDetails.getUpdateStrategy().isPresent()) {
        builder.add(PCJ_UPDATE_STRAT_KEY, pcjDetails.getUpdateStrategy().get().name());
    }
    // Last Update Time if present.
    if (pcjDetails.getLastUpdateTime().isPresent()) {
        builder.add(PCJ_LAST_UPDATE_KEY, pcjDetails.getLastUpdateTime().get());
    }
    return builder.get();
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder)

Example 4 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.

the class MongoDetailsAdapter method toDBObject.

/**
 * Converts a {@link RyaDetails} object into its MongoDB {@link DBObject} equivalent.
 *
 * @param details - The details to convert. (not null)
 * @return The MongoDB {@link DBObject} equivalent.
 */
public static BasicDBObject toDBObject(final RyaDetails details) {
    requireNonNull(details);
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().add(INSTANCE_KEY, details.getRyaInstanceName()).add(VERSION_KEY, details.getRyaVersion()).add(ENTITY_DETAILS_KEY, details.getEntityCentricIndexDetails().isEnabled()).add(PCJ_DETAILS_KEY, toDBObject(details.getPCJIndexDetails())).add(TEMPORAL_DETAILS_KEY, details.getTemporalIndexDetails().isEnabled()).add(FREETEXT_DETAILS_KEY, details.getFreeTextIndexDetails().isEnabled());
    if (details.getProspectorDetails().getLastUpdated().isPresent()) {
        builder.add(PROSPECTOR_DETAILS_KEY, details.getProspectorDetails().getLastUpdated().get());
    }
    if (details.getJoinSelectivityDetails().getLastUpdated().isPresent()) {
        builder.add(JOIN_SELECTIVITY_DETAILS_KEY, details.getJoinSelectivityDetails().getLastUpdated().get());
    }
    // If the Rya Streams Details are present, then add them.
    if (details.getRyaStreamsDetails().isPresent()) {
        final RyaStreamsDetails ryaStreamsDetails = details.getRyaStreamsDetails().get();
        // The embedded object that holds onto the fields.
        final DBObject ryaStreamsFields = BasicDBObjectBuilder.start().add(RYA_STREAMS_HOSTNAME_KEY, ryaStreamsDetails.getHostname()).add(RYA_STREAMS_PORT_KEY, ryaStreamsDetails.getPort()).get();
        // Add them to the main builder.
        builder.add(RYA_STREAMS_DETAILS_KEY, ryaStreamsFields);
    }
    return (BasicDBObject) builder.get();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 5 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.

the class TemporalMongoDBStorageStrategy method getTimeValue.

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 {
        builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate());
    }
    return builder.get();
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Matcher(java.util.regex.Matcher) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Aggregations

BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)44 DBObject (com.mongodb.DBObject)30 Test (org.junit.Test)21 DBCollection (com.mongodb.DBCollection)18 BasicDBObject (com.mongodb.BasicDBObject)12 ArrayList (java.util.ArrayList)7 BasicDBList (com.mongodb.BasicDBList)6 List (java.util.List)4 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)4 HiveTest (com.mongodb.hadoop.hive.HiveTest)3 IOException (java.io.IOException)3 Map (java.util.Map)3 MongoException (com.mongodb.MongoException)2 Configuration (org.apache.hadoop.conf.Configuration)2 JobConf (org.apache.hadoop.mapred.JobConf)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 ResourceSchema (org.apache.pig.ResourceSchema)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 BasicBSONObject (org.bson.BasicBSONObject)2 GeometryType (org.teiid.core.types.GeometryType)2