Package com.mongodb

Examples of com.mongodb.DBCursor


                    final DBCollection col = this.getCollection(info[0]);
                    final String pattern = "^" + Pattern.quote(info[1]) + "/";

                    final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
                    final DBCursor cur = col.find(query);
                    while ( cur.hasNext() ) {
                        final DBObject dbObj = cur.next();
                        final String childPath = info[0] + '/' + dbObj.get(getPROP_PATH());
                        this.deletedResources.add(childPath);
                        this.changedResources.remove(childPath);
                    }
                    deletedResource = true;
View Full Code Here


                } else {
                    pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
                }

                final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
                final DBCursor cur = col.find(query).
                        sort(BasicDBObjectBuilder.start(getPROP_PATH(), 1).get());
                return new Iterator<Resource>() {

                    public boolean hasNext() {
                        return cur.hasNext();
                    }

                    public Resource next() {
                        final DBObject obj = cur.next();
                        final String objPath = obj.get(getPROP_PATH()).toString();
                        final int lastSlash = objPath.lastIndexOf('/');
                        final String name;
                        if (lastSlash == -1) {
                            name = objPath;
View Full Code Here

        DBCollection col = this.getCollection( collectionName );
        if ( col != null )
        {
            String criteria = query.trim().substring( query.indexOf( ".find(" ) + 6, query.length() - 1 );
            DBObject dbObject = (DBObject) JSON.parse( criteria );
            final DBCursor cur = col.find( dbObject );
            final String rootPath = context.getRootWithSlash();
           
            return new Iterator<Resource>() {

                public boolean hasNext() {
                    return cur.hasNext();
                }

                public Resource next() {
                    final DBObject obj = cur.next();
                    final String objPath = obj.get(getPROP_PATH()).toString();
                    final int lastSlash = objPath.lastIndexOf('/');
                    final String name;
                    if (lastSlash == -1) {
                        name = objPath;
View Full Code Here

    if (exchange.isInIoThread()) {
      exchange.dispatch(this);
      return;
    }
    List<Fortune> fortunes = new ArrayList<>();
    DBCursor cursor = database.getCollection("Fortune").find();
    while (cursor.hasNext()) {
      DBObject object = cursor.next();
      fortunes.add(new Fortune(
          ((Number) object.get("_id")).intValue(),
          (String) object.get("message")));
    }
    fortunes.add(new Fortune(0, "Additional fortune added at request time."));
View Full Code Here

  public long getNumberOfEmbeddedAssociations(SessionFactory sessionFactory) {
    DB db = getProvider( sessionFactory ).getDatabase();
    long associationCount = 0;

    for ( String entityCollection : getEntityCollections( sessionFactory ) ) {
      DBCursor entities = db.getCollection( entityCollection ).find();

      while ( entities.hasNext() ) {
        DBObject entity = entities.next();
        associationCount += getNumberOfEmbeddedAssociations( entity );
      }
    }

    return associationCount;
View Full Code Here

    return parseResult.resultValue.build();
  }

  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

        if (after != -1) {
            obj.add(new BasicDBObject("$gt"new BasicDBObject("$gt", new Date(after))));
        }
        andQuery.put("$and", obj);

        final DBCursor cursor = mongoConnection.getDatabase().getCollection("graylog2_metrics")
                .find(andQuery).sort(new BasicDBObject("timestamp", 1));
        Map<String, Object> metricsData = Maps.newHashMap();
        metricsData.put("name", metricName);
        List<Object> values = Lists.newArrayList();
        metricsData.put("values", values);

        while (cursor.hasNext()) {
            final DBObject value = cursor.next();
            metricsData.put("node", value.get("node"));

            final MetricType metricType = MetricType.valueOf(((String) value.get("type")).toUpperCase());
            Map<String, Object> dataPoint = Maps.newHashMap();
            values.add(dataPoint);
View Full Code Here

            filter = FrameworkUtil.createFilter(filterValue);
        }

        DBCollection coll = getCollection();

        DBCursor cursor = coll.find();
        try {
            while (cursor.hasNext()) {
                // Hmm, there might be a more clever way of doing this...
                Role role = m_helper.deserialize(cursor.next());
                if ((filter == null) || filter.match(role.getProperties())) {
                    roles.add(role);
                }
            }
        } finally {
            cursor.close();
        }

        return roles.toArray(new Role[roles.size()]);
    }
View Full Code Here

    @Override
    public Role getRole(String name) {
        DBCollection coll = getCollection();

        DBCursor cursor = coll.find(getTemplateObject(name));
        try {
            if (cursor.hasNext()) {
                return m_helper.deserialize(cursor.next());
            }
        } finally {
            cursor.close();
        }

        return null;
    }
View Full Code Here

        // get the batch size and number to skip
        Integer batchSize = exchange.getIn().getHeader(MongoDbConstants.BATCH_SIZE, Integer.class);
        Integer numToSkip = exchange.getIn().getHeader(MongoDbConstants.NUM_TO_SKIP, Integer.class);
        Integer limit = exchange.getIn().getHeader(MongoDbConstants.LIMIT, Integer.class);
        DBObject sortBy = exchange.getIn().getHeader(MongoDbConstants.SORT_BY, DBObject.class);
        DBCursor ret = null;
        try {
            if (query == null && fieldFilter == null) {
                ret = dbCol.find(new BasicDBObject());
            } else if (fieldFilter == null) {
                ret = dbCol.find(query);
            } else {
                ret = dbCol.find(query, fieldFilter);
            }

            if (sortBy != null) {
                ret.sort(sortBy);
            }

            if (batchSize != null) {
                ret.batchSize(batchSize.intValue());
            }

            if (numToSkip != null) {
                ret.skip(numToSkip.intValue());
            }

            if (limit != null) {
                ret.limit(limit.intValue());
            }

            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.findAll);
            resultMessage.setBody(ret.toArray());
            resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.count());
            resultMessage.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ret.size());
        } finally {
            // make sure the cursor is closed
            if (ret != null) {
                ret.close();
            }
        }

    }
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.