Examples of DBCursor


Examples of com.mongodb.DBCursor

            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

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

Examples of com.mongodb.DBCursor

    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

Examples of com.mongodb.DBCursor

                        .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

Examples of com.mongodb.DBCursor

            // 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

Examples of com.mongodb.DBCursor

                        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

Examples of com.mongodb.DBCursor

  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

Examples of com.mongodb.DBCursor

  }

  @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

Examples of com.mongodb.DBCursor

      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

Examples of com.sun.sgs.service.store.db.DbCursor

      infoDb.get(dbTxn, firstPlaceholderKey, true));
  if (placeholderOid < 0) {
      logger.log(Level.FINEST, "No allocation placeholders");
      return;
  }
  DbCursor cursor = oidsDb.openCursor(dbTxn);
  try {
      while (cursor.findNext(DataEncoding.encodeLong(placeholderOid))) {
    byte[] key = cursor.getKey();
    if (DataEncoding.decodeLong(key) != placeholderOid) {
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Placeholder oid:{0,number,#} not found",
           placeholderOid);
        }
    } else if (isPlaceholderValue(cursor.getValue())) {
        boolean success = oidsDb.delete(dbTxn, key);
        assert success;
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Removed placeholder at oid:{0,number,#}",
           placeholderOid);
        }
    } else {
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Ignoring oid:{0,number,#} that does not" +
           " refer to a placeholder",
           placeholderOid);
        }
    }
    placeholderOid += ALLOCATION_BLOCK_SIZE;
      }
      infoDb.put(
    dbTxn, firstPlaceholderKey, DataEncoding.encodeLong(-1));
  } finally {
      cursor.close();
  }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.