Package com.mongodb

Examples of com.mongodb.DBCursor


                if (input.containsKey("$select")) {
                    select = buildDBObject((MongoRecord)input.get("$select"));
                    input.remove("$select");
                }
                DBObject object = buildDBObject(input);
                DBCursor cursor = collection.find(object, select);
                if (sort != null) {
                    cursor.sort(sort);
                }
                try {
                    if (mongoSpec.getSkip() > 0) {
                        cursor.skip(mongoSpec.getSkip());
                    }
                    if (mongoSpec.getLimit() != 0) {
                        cursor.limit(mongoSpec.getLimit());
                    }
                    if (mongoSpec.getBatchSize() != 0) {
                        cursor.batchSize(mongoSpec.getBatchSize());
                    }
                    if (!cursor.hasNext()) {
                        return null;
                    }
                    MongoListRecord results = new MongoListRecord();
                    while (cursor.hasNext()) {
                        DBObject result = cursor.next();
                        results.add(buildRecordFromDBObject(result));
                    }
                    return results;
                } finally {
                    cursor.close();
                }

            } else {
                throw new ResourceException("Invalid operation: " + operation);               
            }
View Full Code Here


    }
  }

  private ClosableIterator<Tuple> doFind(MongoDBQueryDescriptor query, QueryParameters queryParameters, DBCollection collection,
      EntityKeyMetadata entityKeyMetadata) {
    DBCursor cursor = collection.find( query.getCriteria(), query.getProjection() );

    if ( query.getOrderBy() != null ) {
      cursor.sort( query.getOrderBy() );
    }

    // apply firstRow/maxRows if present
    if ( queryParameters.getRowSelection().getFirstRow() != null ) {
      cursor.skip( queryParameters.getRowSelection().getFirstRow() );
    }

    if ( queryParameters.getRowSelection().getMaxRows() != null ) {
      cursor.limit( queryParameters.getRowSelection().getMaxRows() );
    }

    return new MongoDBResultsCursor( cursor, entityKeyMetadata );
  }
View Full Code Here

        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);
        }
View Full Code Here

            queryBuilder.greaterThanEquals(startValue);
        }
        DBObject query = queryBuilder.get();
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query).sort(BY_ID_ASC);
            List<T> list = new ArrayList<T>();
            for (int i = 0; i < limit && cursor.hasNext(); i++) {
                DBObject o = cursor.next();
                T doc = convertFromDBObject(collection, o);
                if (collection == Collection.NODES && doc != null) {
                    doc.seal();
                    String id = doc.getId();
                    Lock lock = getAndLock(id);
View Full Code Here

            // Fetch only the lastRev map and id
            final BasicDBObject keys = new BasicDBObject(Document.ID, 1);
            keys.put(Document.MOD_COUNT, 1);

            // Fetch lastRev for each such node
            DBCursor cursor = nodes.find(query.get(), keys);
            result.queryCount++;

            for (DBObject obj : cursor) {
                result.cacheEntriesProcessedCount++;
                String id = (String) obj.get(Document.ID);
View Full Code Here

                    QueryBuilder query = QueryBuilder.start(Document.ID)
                            .in(sameLevelNodes.keySet());

                    // Fetch lastRev and modCount for each such nodes
                    DBCursor cursor = nodes.find(query.get(), keys);
                    LOG.debug(
                            "Checking for changed nodes at level {} with {} paths",
                            tn.level(), sameLevelNodes.size());
                    result.queryCount++;
                    for (DBObject obj : cursor) {
View Full Code Here

        QueryBuilder builder = new QueryBuilder();
        if (maxLastModifiedTime != 0 && maxLastModifiedTime != -1) {
            builder.and(MongoBlob.KEY_LAST_MOD).lessThanEquals(maxLastModifiedTime);
        }

        final DBCursor cur =
                collection.find(builder.get(), fields).hint(fields)
                        .addOption(Bytes.QUERYOPTION_SLAVEOK);

        return new AbstractIterator<String>() {
            protected String computeNext() {
                if (cur.hasNext()) {
                    MongoBlob blob = (MongoBlob) cur.next();
                    if (blob != null) {
                        return blob.getId();
                    }
                }
                return endOfData();
View Full Code Here

     *            the name of the collection
     * @return a table definition for mongo db.
     */
    public static SimpleTableDef detectTable(DB db, String collectionName) {
        final DBCollection collection = db.getCollection(collectionName);
        final DBCursor cursor = collection.find().limit(1000);

        final SortedMap<String, Set<Class<?>>> columnsAndTypes = new TreeMap<String, Set<Class<?>>>();
        while (cursor.hasNext()) {
            DBObject object = cursor.next();
            Set<String> keysInObject = object.keySet();
            for (String key : keysInObject) {
                Set<Class<?>> types = columnsAndTypes.get(key);
                if (types == null) {
                    types = new HashSet<Class<?>>();
                    columnsAndTypes.put(key, types);
                }
                Object value = object.get(key);
                if (value != null) {
                    types.add(value.getClass());
                }
            }
        }
        cursor.close();

        final String[] columnNames = new String[columnsAndTypes.size()];
        final ColumnType[] columnTypes = new ColumnType[columnsAndTypes.size()];

        int i = 0;
View Full Code Here

        final DBCollection collection = _mongoDb.getCollection(table.getName());

        final DBObject query = createMongoDbQuery(table, whereItems);

        logger.info("Executing MongoDB 'find' query: {}", query);
        DBCursor cursor = collection.find(query);

        if (maxRows > 0) {
            cursor = cursor.limit(maxRows);
        }
        if (firstRow > 1) {
            final int skip = firstRow - 1;
            cursor = cursor.skip(skip);
        }

        return new MongoDbDataSet(cursor, columns, queryPostProcessed);
    }
View Full Code Here

        range.getTargetID()).append("logId", range.getLogID());
    if (high > 0) {
      filter.append("id", new BasicDBObject("$lte", high));
    }

    DBCursor cursor = collection.find(filter);
    cursor.sort(new BasicDBObject("id", 1));

    List<LogEvent> logevents = new ArrayList<LogEvent>();
    while (cursor.hasNext()) {
      DBObject event = cursor.next();
      String targetId = (String) event.get("targetId");
      long logId = (Long) event.get("logId");
      long id = (Long) event.get("id");
      long time = (Long) event.get("time");
      int type = (Integer) event.get("type");
View Full Code Here

TOP

Related Classes of com.mongodb.DBCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.