Package com.mongodb

Examples of com.mongodb.DBCursor


        //_deletedOnce == true && _modified < lastModifiedTime
        DBObject query =
                start(NodeDocument.DELETED_ONCE).is(Boolean.TRUE)
                                .put(NodeDocument.MODIFIED_IN_SECS).lessThan(Commit.getModifiedInSecs(lastModifiedTime))
                        .get();
        DBCursor cursor = getNodeCollection().find(query).setReadPreference(ReadPreference.secondaryPreferred());
        return CloseableIterable.wrap(transform(cursor, new Function<DBObject, NodeDocument>() {
            @Override
            public NodeDocument apply(DBObject input) {
                return store.convertFromDBObject(Collection.NODES, input);
            }
View Full Code Here


    private void logSplitDocIdsTobeDeleted(DBObject query) {
        // Fetch only the id
        final BasicDBObject keys = new BasicDBObject(Document.ID, 1);
        List<String> ids;
        DBCursor cursor = getNodeCollection().find(query, keys)
                .setReadPreference(ReadPreference.secondaryPreferred());
        try {
             ids = ImmutableList.copyOf(Iterables.transform(cursor, new Function<DBObject, String>() {
                 @Override
                 public String apply(@Nullable DBObject input) {
                     return (String) input.get(Document.ID);
                 }
             }));
        } finally {
            cursor.close();
        }
        StringBuilder sb = new StringBuilder("Split documents with following ids were deleted as part of GC \n");
        Joiner.on(StandardSystemProperty.LINE_SEPARATOR.value()).appendTo(sb, ids);
        log.debug(sb.toString());
    }
View Full Code Here

                        .put(NodeDocument.MODIFIED_IN_SECS).greaterThanEquals(
                                Commit.getModifiedInSecs(startTime))
                        .get();
        DBObject sortFields = new BasicDBObject(NodeDocument.MODIFIED_IN_SECS, -1);

        DBCursor cursor =
                getNodeCollection().find(query)
                        .sort(sortFields)
                        .setReadPreference(
                                ReadPreference.secondaryPreferred());
        return CloseableIterable.wrap(transform(cursor, new Function<DBObject, NodeDocument>() {
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(idBatch);

                        // 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++;
                        try {
                            for (DBObject obj : cursor) {

                                result.cacheEntriesProcessedCount++;

                                Number latestModCount = (Number) obj.get(Document.MOD_COUNT);
                                String id = (String) obj.get(Document.ID);

                                final TreeNode tn2 = sameLevelNodes.get(id);
                                CachedNodeDocument cachedDoc = tn2.getDocument();
                                if (cachedDoc != null) {
                                    boolean noChangeInModCount = Objects.equal(latestModCount, cachedDoc.getModCount());
                                    if (noChangeInModCount) {
                                        result.upToDateCount++;
                                        tn2.markUptodate(startTime);
                                    } else {
                                        result.invalidationCount++;
                                        tn2.invalidate();
                                    }
                                }

                                // Remove the processed nodes
                                sameLevelNodes.remove(tn2.getId());
                            }
                        } finally {
                            cursor.close();
                        }
                    }

                    // NodeDocument present in cache but not in database
                    // Remove such nodes from cache
View Full Code Here

  public void testCollectionViaCursor() throws UnknownHostException, MongoException {
    MongoDao dao = MongoDao.Factory.newTestMongoDao();
   
    DBCollection col = dao.getDbCollection();
   
    DBCursor cur = col.find();

        while(cur.hasNext()) {
            System.out.println(cur.next());
        }
  }
View Full Code Here

  }

  @Override
  public Collection<PropertyRecord> find(String propertyName,
      String propertyValue) {
    DBCursor dbCursor = this.dbCollection.find(new BasicDBObject(
        propertyName, propertyValue));
    if (dbCursor == null)
      return null;
    return new PropertyRecordList(dbCursor);
  }
View Full Code Here

      if (property.getValue() instanceof String) {
        queryParts.add(queryPart);
      }
    }
    logger.debug("query: " + query);
    DBCursor dbCursor = this.dbCollection.find(query);
    if (dbCursor == null)
      return null;
    return new PropertyRecordList(dbCursor);
  }
View Full Code Here

  @Override
  public void refresh(Collection<Refreshable> alreadyRefreshed) {
    Date ts = new Date(0);
    BasicDBObject query = new BasicDBObject();
    query.put("deleted_at", new BasicDBObject("$gt", mongoTimestamp));
    DBCursor cursor = collection.find(query);
    while (cursor.hasNext()) {
      Map<String,Object> user = (Map<String,Object>) cursor.next().toMap();
      String userID = getID(user.get(mongoUserID), true);
      Collection<List<String>> items = Lists.newArrayList();
      List<String> item = Lists.newArrayList();
      item.add(getID(user.get(mongoItemID), false));
      item.add(Float.toString(getPreference(user.get(mongoPreference))));
      items.add(item);
      try {
        refreshData(userID, items, false);
      } catch (NoSuchUserException e) {
        log.warn("No such user ID: {}", userID);
      } catch (NoSuchItemException e) {
        log.warn("No such items: {}", items);
      }
      if (ts.compareTo(getDate(user.get("created_at"))) < 0) {
        ts = getDate(user.get("created_at"));
      }
    }
    query = new BasicDBObject();
    query.put("created_at", new BasicDBObject("$gt", mongoTimestamp));
    cursor = collection.find(query);
    while (cursor.hasNext()) {
      Map<String,Object> user = (Map<String,Object>) cursor.next().toMap();
      if (!user.containsKey("deleted_at")) {
        String userID = getID(user.get(mongoUserID), true);
        Collection<List<String>> items = Lists.newArrayList();
        List<String> item = Lists.newArrayList();
        item.add(getID(user.get(mongoItemID), false));
View Full Code Here

      collectionMap.ensureIndex(indexObj);
      indexObj = new BasicDBObject();
      indexObj.put("long_value", 1);
      collectionMap.ensureIndex(indexObj);
      collectionMap.remove(new BasicDBObject());
      DBCursor cursor = collection.find();
      while (cursor.hasNext()) {
        Map<String,Object> user = (Map<String,Object>) cursor.next().toMap();
        if (!user.containsKey("deleted_at")) {
          long userID = Long.parseLong(fromIdToLong(getID(user.get(mongoUserID), true), true));
          long itemID = Long.parseLong(fromIdToLong(getID(user.get(mongoItemID), false), false));
          float ratingValue = getPreference(user.get(mongoPreference));
          Collection<Preference> userPrefs = userIDPrefMap.get(userID);
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.