Package com.mongodb

Examples of com.mongodb.DBCursor


    DBCollection collection = m_mongoDBService.getDB().getCollection(m_logname);

    BasicDBObject filter = new BasicDBObject().append("targetId", targetID)
        .append("logId", logID);

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

    long high = 1;
    if (cursor.hasNext()) {
      DBObject row = cursor.next();
      high = (Long) row.get("id");
      return new LogDescriptor(targetID, logID, new SortedRangeSet(
          new Range(1, high).toRepresentation()));
    } else {
      return new LogDescriptor(targetID, logID, SortedRangeSet.FULL_SET);
View Full Code Here


        return this.find(filter, null, null, null);
    }

    public List<DBObject> find() {
        if (null != _coll) {
            final DBCursor cursor = _coll.find();
            return null != cursor ? cursor.toArray() : new ArrayList<DBObject>();
        }
        return null;
    }
View Full Code Here

    }

    public List<DBObject> find(final DBObject filter, final String[] fieldNames,
            final String[] sortAscBy, final String[] sortDescBy) {
        if (null != _coll) {
            final DBCursor cursor = this.cursor(
                    filter, fieldNames, 0, 0, sortAscBy, sortDescBy);
            return null != cursor
                    ? cursor.toArray()
                    : new ArrayList<DBObject>();
        }
        return null;
    }
View Full Code Here

     */
    public List<DBObject> find(final DBObject filter, final String[] fieldNames,
            final int skip, final int limit,
            final String[] sortAscBy, final String[] sortDescBy) {
        if (null != _coll) {
            final DBCursor cursor = this.cursor(
                    filter, fieldNames, skip, limit, sortAscBy, sortDescBy);
            return null != cursor
                    ? cursor.toArray()
                    : new ArrayList<DBObject>();
        }
        return null;
    }
View Full Code Here

        return new ArrayList<String>();
    }
    // </editor-fold>

    public int count(final DBObject filter) {
        DBCursor cursor;
        if (null != filter) {
            cursor = null != _coll ? _coll.find(filter) : null;
        } else {
            cursor = null != _coll ? _coll.find() : null;
        }
        return null != cursor ? cursor.count() : 0;
    }
View Full Code Here

    private DBCursor cursor(final DBObject filter, final String[] fieldNames,
            final int skip, final int limit,
            final String[] sortAscBy, final String[] sortDescBy) {
        if (null != _coll) {
            DBCursor cursor;
            final DBObject fields = this.getFields(fieldNames, true);
            final DBObject sort = BeeMongoUtils.getSortFields(sortAscBy, sortDescBy);
            if (null != filter) {
                cursor = null != fields
                        ? _coll.find(filter, fields)
                        : _coll.find(filter);
            } else {
                cursor = null != fields
                        ? _coll.find(new BasicDBObject(), fields)
                        : _coll.find();
            }

            // limit data
            if (skip > 0 || limit > 0) {
                if (skip > 0) {
                    cursor = cursor.skip(skip);
                }
                if (limit > 0) {
                    cursor = cursor.limit(limit);
                }
            }

            // sort
            if (null != cursor && null != sort) {
                cursor = cursor.sort(sort);
            }

            return cursor;
        }
        return null;
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(fromKey);
        queryBuilder.lessThan(toKey);
        DBObject query = queryBuilder.get();
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query);
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < limit && cursor.hasNext(); i++) {
                DBObject o = cursor.next();
                Map<String, Object> map = convertFromDBObject(o);
                if (collection == Collection.NODES) {
                    String key = (String) map.get(UpdateOp.ID);
                    nodesCache.put(key, new CachedDocument(map));
                }
View Full Code Here

            if (this.lastHeadRevId < syncMongo.getHeadRevisionId()) {
                DBCollection commitCollection = ((MongoNodeStore)microKernel.getNodeStore()).getCommitCollection();
                DBObject query = QueryBuilder.start(MongoCommit.KEY_REVISION_ID).greaterThan(this.lastRevId)
                        .and(MongoCommit.KEY_REVISION_ID).lessThanEquals(syncMongo.getHeadRevisionId()).get();
                DBObject sort = QueryBuilder.start(MongoCommit.KEY_REVISION_ID).is(1).get();
                DBCursor dbCursor = commitCollection.find(query).sort(sort);
                while (dbCursor.hasNext()) {
                    commitMongos.add((MongoCommit) dbCursor.next());
                }

                if (commitMongos.size() > 0) {
                    LOG.debug(String.format("Found %d new commits", commitMongos.size()));
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;
            try {
                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);
                        CacheValue cacheKey = new StringValue(id);
                        try {
                            // do not overwrite document in cache if the
                            // existing one in the cache is newer
                            NodeDocument cached = nodesCache.getIfPresent(cacheKey);
                            if (cached != null && cached != NodeDocument.NULL) {
                                // check mod count
                                Number cachedModCount = cached.getModCount();
                                Number modCount = doc.getModCount();
                                if (cachedModCount == null || modCount == null) {
                                    throw new IllegalStateException(
                                            "Missing " + Document.MOD_COUNT);
                                }
                                if (modCount.longValue() > cachedModCount.longValue()) {
                                    nodesCache.put(cacheKey, (NodeDocument) doc);
                                }
                            } else {
                                nodesCache.put(cacheKey, (NodeDocument) doc);
                            }
                        } finally {
                            lock.unlock();
                        }
                    }
                    list.add(doc);
                }
            } finally {
                cursor.close();
            }
            return list;
        } finally {
            end("query", start);
        }
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.