Example usage for com.mongodb QueryBuilder get

List of usage examples for com.mongodb QueryBuilder get

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder get.

Prototype

public DBObject get() 

Source Link

Document

Creates a DBObject query to be used for the driver's find operations

Usage

From source file:kina.config.GenericMongoKinaConfig.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w .jav a 2s  .c  o  m*/
 */
@Override
public MongoKinaConfig<T> filterQuery(QueryBuilder query) {
    this.query = query.get().toString();
    return this;
}

From source file:net.atos.entng.calendar.event.CalendarSearchingEvents.java

License:Open Source License

private void searchEvent(int page, int limit, List<String> searchWords, final Map<String, String> mapIdTitle,
        Handler<Either<String, JsonArray>> handler) {
    final int skip = (0 == page) ? -1 : page * limit;

    final List<String> returnFields = new ArrayList<String>();
    returnFields.add("title");
    returnFields.add("calendar");
    returnFields.add("description");
    returnFields.add("location");
    returnFields.add("modified");
    returnFields.add("startMoment");
    returnFields.add("endMoment");
    returnFields.add("owner.userId");
    returnFields.add("owner.displayName");

    final QueryBuilder worldsQuery = new QueryBuilder();
    worldsQuery.text(MongoDbSearchService.textSearchedComposition(searchWords));

    final QueryBuilder calendarQuery = new QueryBuilder().start("calendar").in(mapIdTitle.keySet());
    final QueryBuilder query = new QueryBuilder().and(worldsQuery.get(), calendarQuery.get());

    JsonObject sort = new JsonObject().putNumber("modified", -1);
    final JsonObject projection = new JsonObject();
    for (String field : returnFields) {
        projection.putNumber(field, 1);//from   w ww  .  j av a2  s  .c om
    }

    mongo.find(Calendar.CALENDAR_EVENT_COLLECTION, MongoQueryBuilder.build(query), sort, projection, skip,
            limit, Integer.MAX_VALUE, validResultsHandler(handler));
}

From source file:net.atos.entng.forum.events.ForumSearchingEvents.java

License:Open Source License

private void searchSubject(int page, int limit, List<String> searchWords, final Map<String, String> mapIdName,
        Handler<Either<String, JsonArray>> handler) {
    final int skip = (0 == page) ? -1 : page * limit;

    final QueryBuilder worldsQuery = new QueryBuilder();
    worldsQuery.text(MongoDbSearchService.textSearchedComposition(searchWords));

    final QueryBuilder categoryQuery = new QueryBuilder().start("category").in(mapIdName.keySet());

    final QueryBuilder query = new QueryBuilder().and(worldsQuery.get(), categoryQuery.get());

    JsonObject sort = new JsonObject().putNumber("modified", -1);
    final JsonObject projection = new JsonObject();
    projection.putNumber("title", 1);
    projection.putNumber("messages", 1);
    projection.putNumber("category", 1);
    projection.putNumber("modified", 1);
    projection.putNumber("owner.userId", 1);
    projection.putNumber("owner.displayName", 1);

    mongo.find(Forum.SUBJECT_COLLECTION, MongoQueryBuilder.build(query), sort, projection, skip, limit,
            Integer.MAX_VALUE, validResultsHandler(handler));
}

From source file:net.jimj.automaton.commands.NoteCommand.java

License:Open Source License

protected void findNotes(User to) {
    QueryBuilder builder = new QueryBuilder();
    builder.or(new BasicDBObject(NOTE_TO, to.getNick().toLowerCase()),
            new BasicDBObject(NOTE_TO, to.getRealName()));
    builder.and(new BasicDBObject(NOTE_DELIVERED, false));
    DBCursor noteCursor = notes.find(builder.get());
    if (noteCursor == null) {
        return;/*from   ww w .  java2s.  c  o  m*/
    }

    while (noteCursor.hasNext()) {
        DBObject noteObj = noteCursor.next();
        String from = (String) noteObj.get(NOTE_FROM);
        String note = (String) noteObj.get(NOTE_NOTE);
        long when = (long) noteObj.get(NOTE_WHEN);

        StringBuilder noteMessage = new StringBuilder(to.getNick()).append(" you have a note from ");
        noteMessage.append(from).append(" at ").append(WHEN_FMT.format(new Date(when)));
        addEvent(new ReplyEvent(to, noteMessage.toString()));
        addEvent(new ReplyEvent(to, note));

        notes.update(new BasicDBObject("_id", noteObj.get("_id")),
                new BasicDBObject("$set", new BasicDBObject(NOTE_DELIVERED, true)));
    }
}

From source file:org.alfresco.bm.event.mongo.MongoResultService.java

License:Open Source License

@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);
    }//from www  .jav a  2  s.c om
    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;
}

From source file:org.alfresco.bm.event.mongo.MongoResultService.java

License:Open Source License

@Override
public List<EventDetails> getEventDetails(EventResultFilter filter, String filterEventName, int skip,
        int limit) {
    QueryBuilder queryBuilder = QueryBuilder.start();

    // apply filter
    switch (filter) {
    case Failed://from   www .j av a  2 s  .c  om
        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;
}

From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java

License:Open Source License

/**
 * Get registered test drivers/*from   w  ww.j  av  a 2  s .c  o m*/
 * 
 * @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;
}

From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java

License:Open Source License

/**
 * Count registered drivers//  w  w  w  .j av a  2s. c  o  m
 * 
 * @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;
}

From source file:org.alfresco.cacheserver.dao.mongo.MongoWebSocketDAO.java

License:Open Source License

@Override
public Registration getByUsername(String username) {
    QueryBuilder queryBuilder = QueryBuilder.start("u").is(username);
    DBObject query = queryBuilder.get();

    DBObject dbObject = registrationData.findOne(query);
    Registration registration = toRegistration(dbObject);
    return registration;
}

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public NodeInfo getByNodeId(String nodeId, String nodeVersion, boolean isPrimary) {
    QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("n").is(nodeId).and("v")
            .is(nodeVersion).and("pri").is(isPrimary);
    DBObject query = queryBuilder.get();

    DBObject dbObject = contentData.findOne(query);
    NodeInfo nodeInfo = toNodeInfo(dbObject);
    return nodeInfo;
}