当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilder.get方法代码示例

本文整理汇总了Java中com.mongodb.QueryBuilder.get方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.get方法的具体用法?Java QueryBuilder.get怎么用?Java QueryBuilder.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transformFieldFilter

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
protected DBObject transformFieldFilter(
    final SingleFieldValueFilter<K, T> fieldFilter,
    final MongoStore<K, T> store) {
  MongoMapping mapping = store.getMapping();
  String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName());

  FilterOp filterOp = fieldFilter.getFilterOp();
  List<Object> operands = fieldFilter.getOperands();

  QueryBuilder builder = QueryBuilder.start(dbFieldName);
  builder = appendToBuilder(builder, filterOp, operands);
  if (!fieldFilter.isFilterIfMissing()) {
    // If false, the find query will pass if the column is not found.
    DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
    builder = QueryBuilder.start().or(notExist, builder.get());
  }
  return builder.get();
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:19,代码来源:DefaultFactory.java

示例2: transformMapFilter

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
protected DBObject transformMapFilter(
    final MapFieldValueFilter<K, T> mapFilter, final MongoStore<K, T> store) {
  MongoMapping mapping = store.getMapping();
  String dbFieldName = mapping.getDocumentField(mapFilter.getFieldName())
      + "." + store.encodeFieldKey(mapFilter.getMapKey().toString());

  FilterOp filterOp = mapFilter.getFilterOp();
  List<Object> operands = mapFilter.getOperands();

  QueryBuilder builder = QueryBuilder.start(dbFieldName);
  builder = appendToBuilder(builder, filterOp, operands);
  if (!mapFilter.isFilterIfMissing()) {
    // If false, the find query will pass if the column is not found.
    DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
    builder = QueryBuilder.start().or(notExist, builder.get());
  }
  return builder.get();
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:19,代码来源:DefaultFactory.java

示例3: getQuery

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
public DBObject getQuery(final StatementConstraints contraints) {
    final QueryBuilder queryBuilder = QueryBuilder.start();
    if (contraints.hasSubject()){
        queryBuilder.and(new BasicDBObject(SUBJECT, contraints.getSubject().toString()));
    }

    if (contraints.hasPredicates()){
        final Set<URI> predicates = contraints.getPredicates();
        if (predicates.size() > 1){
            for (final URI pred : predicates){
                final DBObject currentPred = new BasicDBObject(PREDICATE, pred.toString());
                queryBuilder.or(currentPred);
            }
        }
        else if (!predicates.isEmpty()){
            queryBuilder.and(new BasicDBObject(PREDICATE, predicates.iterator().next().toString()));
        }
    }
    if (contraints.hasContext()){
        queryBuilder.and(new BasicDBObject(CONTEXT, contraints.getContext().toString()));
    }
    return queryBuilder.get();
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:IndexingMongoDBStorageStrategy.java

示例4: createQueryPartition

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
 * Create query partition.
 *
 * @param partition the partition
 * @return the dB object
 */
private DBObject createQueryPartition(MongoPartition partition) {

    QueryBuilder queryBuilderMin = QueryBuilder.start(partition.getKey());
    DBObject bsonObjectMin = queryBuilderMin.greaterThanEquals(partition.splitWrapper().getStartToken()).get();

    QueryBuilder queryBuilderMax = QueryBuilder.start(partition.getKey());
    DBObject bsonObjectMax = queryBuilderMax.lessThan(partition.splitWrapper().getEndToken()).get();

    QueryBuilder queryBuilder = QueryBuilder.start();
    if (partition.splitWrapper().getStartToken() != null) {
        queryBuilder.and(bsonObjectMin);
    }

    if (partition.splitWrapper().getEndToken() != null) {
        queryBuilder.and(bsonObjectMax);
    }

    LOG.debug("mongodb query "+queryBuilder.get());

    return queryBuilder.get();
}
 
开发者ID:Stratio,项目名称:deep-spark,代码行数:28,代码来源:MongoReader.java

示例5: getBlobQuery

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
private static DBObject getBlobQuery(String id, long lastMod) {
    QueryBuilder queryBuilder = new QueryBuilder();
    if (id != null) {
        queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).is(id);
    }
    if (lastMod > 0) {
        queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD).lessThan(lastMod);
    }
    return queryBuilder.get();
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:11,代码来源:MongoBlobStore.java

示例6: process

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public Pagination<Message> process(MessageSearcher searcher) {
	QueryBuilder builder = QueryBuilder.start();
	if (StringUtils.isNotBlank(searcher.getExample().getGroupId())) {
		builder.and(Message.GROUP_ID).is(searcher.getExample().getGroupId());
	}

	if (StringUtils.isNotBlank(searcher.getExample().getTitle())) {
		builder.and(Message.TITLE).regex(Pattern.compile(searcher.getExample().getTitle()));
	}
	DBObject query = builder.get();

	Page page = searcher.getPage();
	page.count = (int) messages.getDBCollection().count(query);
	if (page.count == 0) {
		return Pagination.empty();
	}

	@SuppressWarnings("rawtypes") Iterable<Map> iterable = messages.find(query.toString())
		.sort(CREATE_TIME_ORDER_DESC)
		.skip(page.start)
		.limit(page.limit)
		.as(Map.class);

	Pagination<Message> pagination = new Pagination<>(new ArrayList<Message>(page.limit), page);
	for (Map<String, Object> _in : iterable) {
		Message message = new Message();
		message.fromMap(_in);
		pagination.items.add(message);
	}

	return pagination;
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:34,代码来源:MongoMessageSearcherProcessor.java

示例7: getDrivers

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
 * Get registered test drivers
 * 
 * @param release
 *        the release name of the test or <tt>null</tt> for all releases
 * @param schema
 *        the schema number of the driver or <tt>null</tt> for all schemas
 * @param liveOnly
 *        <tt>true</tt> to retrieve only live instances
 */
public DBCursor getDrivers(String release, Integer schema, boolean active)
{
    QueryBuilder queryBuilder = QueryBuilder.start();
    if (release != null)
    {
        queryBuilder.and(FIELD_RELEASE).is(release);
    }
    if (schema != null)
    {
        queryBuilder.and(FIELD_SCHEMA).is(schema);
    }
    if (active)
    {
        queryBuilder.and(FIELD_PING + "." + FIELD_EXPIRES).greaterThan(new Date());
    }
    DBObject queryObj = queryBuilder.get();
    DBObject sortObj = BasicDBObjectBuilder
            .start()
            .add(FIELD_RELEASE, 1)
            .add(FIELD_SCHEMA, 1)
            .get();

    DBCursor cursor = testDrivers.find(queryObj).sort(sortObj);

    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug(
                "Retrieved test driver: \n" +
                        "   Release: " + release + "\n" +
                        "   Schema:  " + schema + "\n" +
                        "   active:  " + active + "\n" +
                        "   Results: " + cursor.count());
    }
    return cursor;
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:47,代码来源:MongoTestDAO.java

示例8: countDrivers

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
 * Count registered drivers
 * 
 * @param release
 *        the release name of the test or <tt>null</tt> for all releases
 * @param schema
 *        the schema number of the driver or <tt>null</tt> for all schemas
 * @param liveOnly
 *        <tt>true</tt> to retrieve only live instances
 * @return a count of the number of drivers matching the criteria
 */
public long countDrivers(String release, Integer schema, boolean active)
{
    QueryBuilder queryBuilder = QueryBuilder.start();
    if (release != null)
    {
        queryBuilder.and(FIELD_RELEASE).is(release);
    }
    if (schema != null)
    {
        queryBuilder.and(FIELD_SCHEMA).is(schema);
    }
    if (active)
    {
        queryBuilder.and(FIELD_PING + "." + FIELD_EXPIRES).greaterThan(new Date());
    }
    DBObject queryObj = queryBuilder.get();

    long count = testDrivers.count(queryObj);

    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug(
                "Retrieved test driver: \n" +
                        "   Release: " + release + "\n" +
                        "   Schema:  " + schema + "\n" +
                        "   active:  " + active + "\n" +
                        "   Results: " + count);
    }
    return count;
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:43,代码来源:MongoTestDAO.java

示例9: manyChildNodes

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void manyChildNodes() {
    DB db = MongoUtils.getConnection().getDB();
    MongoUtils.dropCollections(db);
    DBCollection nodes = db.getCollection(Collection.NODES.toString());
    DBObject index = new BasicDBObject();
    // modification time (descending)
    index.put("_mod", -1L);
    // and then id (ascending)
    index.put("_id", 1L);
    DBObject options = new BasicDBObject();
    // options.put("unique", Boolean.TRUE);
    nodes.ensureIndex(index, options);

    // index on (_id, _mod):
    // Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" ,
    // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
    // "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 ,
    // "nscannedAllPlans" : 2859727 , "scanAndOrder" : false ,
    // "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 ,
    // "millis" : 5112 ,...
    // Time: 2229 ms
    // Count: 2000

    // index on (_mod, _id)
    // Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" ,
    // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
    // "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 ,
    // "nscannedAllPlans" : 2203 , "scanAndOrder" : false ,
    // "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 ,
    // "millis" : 3 ,...
    // Time: 43 ms
    // Count: 2000

    int children = 1000000;
    int perInsert = 1000;
    int group = 0;
    String parent = "/parent/node/abc";
    for (int i = 0; i < children;) {
        DBObject[] inserts = new DBObject[perInsert];
        group++;
        for (int j = 0; j < perInsert; j++, i++) {
            BasicDBObject doc = new BasicDBObject();
            inserts[j] = doc;
            doc.put("_id", parent + "/node" + i);
            doc.put("_mod", group);
        }
        nodes.insert(inserts, WriteConcern.SAFE);
        log("inserted " + i + "/" + children);
    }
    QueryBuilder queryBuilder = QueryBuilder.start("_mod");
    queryBuilder.greaterThanEquals(group - 1);
    queryBuilder.and("_id").greaterThan(parent + "/");
    queryBuilder.and("_id").lessThanEquals(parent + "0");
    DBObject query = queryBuilder.get();
    BasicDBObject keys = new BasicDBObject();
    keys.put("_id", 1);
    DBCursor cursor = nodes.find(query, keys);
    int count = 0;
    log("Query plan: " + cursor.explain());
    long time = System.currentTimeMillis();
    while (cursor.hasNext()) {
        DBObject obj = cursor.next();
        // dummy read operation (to ensure we did get the data)
        obj.get("_id");
        count++;
        // log(" read " + obj);
    }
    time = System.currentTimeMillis() - time;
    log("Time: " + time + " ms");
    log("Count: " + count);
    db.getMongo().close();
}
 
开发者ID:denismo,项目名称:jackrabbit-dynamodb-store,代码行数:75,代码来源:MongoDbTest.java

示例10: generateFilterQuery

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
 * Generate filter query.
 *
 * @param partition the partition
 * @return the dB object
 */
private DBObject generateFilterQuery(MongoPartition partition) {

    if (mongoDeepJobConfig.getQuery() != null) {
        QueryBuilder queryBuilder = QueryBuilder.start();

        queryBuilder.and(createQueryPartition(partition), mongoDeepJobConfig.getQuery());

        LOG.debug("mongodb query "+queryBuilder.get());

        return queryBuilder.get();
    }

    return createQueryPartition(partition);

}
 
开发者ID:Stratio,项目名称:deep-spark,代码行数:22,代码来源:MongoReader.java

示例11: filterQuery

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public MongoDeepJobConfig<T> filterQuery(QueryBuilder query) {
    this.query = query.get();
    return this;
}
 
开发者ID:Stratio,项目名称:deep-spark,代码行数:9,代码来源:MongoDeepJobConfig.java

示例12: build

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
public static JsonObject build(QueryBuilder queryBuilder) {
	DBObject dbo = queryBuilder.get();
	return new JsonObject(JSON.serialize(dbo));
}
 
开发者ID:web-education,项目名称:mongodb-helper,代码行数:5,代码来源:MongoQueryBuilder.java

示例13: getResults

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public List<EventRecord> getResults(
        long startTime,
        long endTime,
        boolean chartOnly,
        int skip, int limit)
{
    QueryBuilder queryBuilder = QueryBuilder
            .start()
            .and(EventRecord.FIELD_START_TIME).greaterThanEquals(new Date(startTime))
            .and(EventRecord.FIELD_START_TIME).lessThan(new Date(endTime));
    if (chartOnly)
    {
        queryBuilder.and(EventRecord.FIELD_CHART).is(true);
    }
    DBObject queryObj = queryBuilder.get();
    DBObject sortObj = BasicDBObjectBuilder
            .start()
            .add(EventRecord.FIELD_START_TIME, Integer.valueOf(1))
            .get();
    
    DBCursor cursor = collection.find(queryObj);
    cursor.sort(sortObj);
    cursor.skip(skip);
    cursor.limit(limit);
    
    // Get all the results and convert them
    int size = cursor.size();
    List<EventRecord> results = new ArrayList<EventRecord>(size);
    try
    {
        while (cursor.hasNext())
        {
            DBObject obj = cursor.next();
            EventRecord eventRecord = convertToEventRecord(obj);
            results.add(eventRecord);
        }
    }
    finally
    {
        cursor.close();
    }
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug("\n" +
                "Found results: \n" +
                "   Query:          " + queryObj + "\n" +
                "   Skip:           " + skip + "\n" +
                "   Limit:          " + limit + "\n" +
                "   Results:        " + size);
    }
    return results;
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:55,代码来源:MongoResultService.java

示例14: getEventDetails

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public List<EventDetails> getEventDetails(EventResultFilter filter, String filterEventName, int skip, int limit)
{
    QueryBuilder queryBuilder = QueryBuilder.start();
    
    // apply filter
    switch (filter)
    {
        case Failed:
            queryBuilder.and(EventRecord.FIELD_SUCCESS).is(false);
            break;
        
        case Success:
            queryBuilder.and(EventRecord.FIELD_SUCCESS).is(true);
            break;
        default:
            break;
    }
    
    //apply event name filter
    if (null != filterEventName && !filterEventName.isEmpty())
    {
        queryBuilder.and(EventRecord.FIELD_EVENT_NAME).is(filterEventName);
    }
    
    DBObject queryObj = queryBuilder.get();
    // sort descending to get the newest values first
    DBObject sortObj = BasicDBObjectBuilder
            .start()
            .add(EventRecord.FIELD_START_TIME, Integer.valueOf(-1))
            .get();
    DBCursor cursor = collection.find(queryObj);
    cursor.sort(sortObj);
    cursor.skip(skip);
    cursor.limit(limit);
    
    // Get all the results and convert them
    int size = cursor.size();
    List<EventDetails> results = new ArrayList<EventDetails>(size);
    try
    {
        while (cursor.hasNext())
        {
            DBObject obj = cursor.next();
            EventDetails eventDetails = convertToEventDetails(obj);
            results.add(eventDetails);
        }
    }
    finally
    {
        cursor.close();
    }
    
    return results;
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:56,代码来源:MongoResultService.java

示例15: randomSiteMember

import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Override
public SiteMemberData randomSiteMember(String siteId,
        DataCreationState state, String username, String... roles)
{
    QueryBuilder queryObjBuilder = QueryBuilder
            .start(SiteMemberData.FIELD_SITE_ID).exists(Boolean.TRUE);
    if (siteId != null)
    {
        queryObjBuilder.and(SiteMemberData.FIELD_SITE_ID).is(siteId);
    }
    if (state != null)
    {
        queryObjBuilder.and(SiteMemberData.FIELD_CREATION_STATE)
                .is(state.toString());
    }
    if (username != null)
    {
        queryObjBuilder.and(SiteMemberData.FIELD_USERNAME).is(username);
    }
    if (roles != null && roles.length > 0)
    {
        queryObjBuilder.and(SiteMemberData.FIELD_ROLE).in(roles);
    }
    BasicDBObject query = (BasicDBObject) queryObjBuilder.get();    // Need
                                                                    // to
                                                                    // cast
                                                                    // for
                                                                    // later
                                                                    // puts
    int random = (int) (Math.random() * (double) 1e6);
    query.put(SiteData.FIELD_RANDOMIZER,
            new BasicDBObject("$gte", Integer.valueOf(random)));

    DBObject result = siteMembersCollection.findOne(query);
    if (result == null)
    {
        result = siteMembersCollection.findOne();
        query.put(SiteData.FIELD_RANDOMIZER,
                new BasicDBObject("$lt", random));
        result = siteMembersCollection.findOne(query);
    }
    return convertSiteMemberDBObject(result);
}
 
开发者ID:AlfrescoBenchmark,项目名称:alfresco-benchmark,代码行数:44,代码来源:SiteDataServiceImpl.java


注:本文中的com.mongodb.QueryBuilder.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。