@Override public <A extends Collection<? super GridFSFile>> A into(final A target) { return underlying.into(target); }
@Override public List<Document> bulkFetch(List<DBRef> refs) { Assert.notNull(mongoDbFactory, "Factory must not be null!"); Assert.notNull(refs, "DBRef to fetch must not be null!"); if (refs.isEmpty()) { return Collections.emptyList(); } String collection = refs.iterator().next().getCollectionName(); List<Object> ids = new ArrayList<>(refs.size()); for (DBRef ref : refs) { if (!collection.equals(ref.getCollectionName())) { throw new InvalidDataAccessApiUsageException( "DBRefs must all target the same collection for bulk fetch operation."); } ids.add(ref.getId()); } List<Document> result = getCollection(refs.iterator().next()) // .find(new Document("_id", new Document("$in", ids))) // .into(new ArrayList<>()); return ids.stream() // .flatMap(id -> documentWithId(id, result)) // .collect(Collectors.toList()); }
@Override public List<Document> bulkFetch(List<DBRef> refs) { Assert.notNull(mongoDbFactory, "Factory must not be null!"); Assert.notNull(refs, "DBRef to fetch must not be null!"); if (refs.isEmpty()) { return Collections.emptyList(); } String collection = refs.iterator().next().getCollectionName(); List<Object> ids = new ArrayList<>(refs.size()); for (DBRef ref : refs) { if (!collection.equals(ref.getCollectionName())) { throw new InvalidDataAccessApiUsageException( "DBRefs must all target the same collection for bulk fetch operation."); } ids.add(ref.getId()); } List<Document> result = getCollection(refs.iterator().next()) // .find(new Document("_id", new Document("$in", ids))) // .into(new ArrayList<>()); return ids.stream() // .flatMap(id -> documentWithId(id, result)) // .collect(Collectors.toList()); }
@Override public <A extends Collection<? super GridFSFile>> A into(final A target) { return underlying.into(target); }
@Override public <A extends Collection<? super GridFSFile>> A into(final A target) { return underlying.into(target); }
@Override public Optional<LotteryTicket> findById(LotteryTicketId id) { Document find = new Document("ticketId", id.getId()); List<Document> results = ticketsCollection.find(find).limit(1).into(new ArrayList<Document>()); if (results.size() > 0) { LotteryTicket lotteryTicket = docToTicket(results.get(0)); return Optional.of(lotteryTicket); } else { return Optional.empty(); } }
@Override public Map<LotteryTicketId, LotteryTicket> findAll() { Map<LotteryTicketId, LotteryTicket> map = new HashMap<>(); List<Document> docs = ticketsCollection.find(new Document()).into(new ArrayList<Document>()); for (Document doc: docs) { LotteryTicket lotteryTicket = docToTicket(doc); map.put(lotteryTicket.getId(), lotteryTicket); } return map; }
@Override public int getFunds(String bankAccount) { Document search = new Document("_id", bankAccount); List<Document> results = accountsCollection.find(search).limit(1).into(new ArrayList<Document>()); if (results.size() > 0) { return results.get(0).getInteger("funds"); } else { return 0; } }
/** * Finds and returns documents from the collection by condition. * * @param collection collection name. * @param condition condition for search documents in collection. * @param resultedClass type of class for deserialization. */ protected <T> List<T> find(String collection, Bson condition, Class<T> resultedClass) { return mongoService.getCollection(collection) .find(condition) .into(new ArrayList<>()) .stream() .map(d -> convertFromDocument(d, resultedClass)) .collect(Collectors.toList()); }
@Override public Set<String> getObjectIdList() { Set<String> objectIdList = new HashSet<String>(); MongoCollection<Document> objectMetaCol = mongoDb .getCollection(objectMetadataCollectionName); List<Document> objectIds = objectMetaCol.find(new Document()) .projection(fields(include("redboxOid"), excludeId())) .into(new ArrayList<Document>()); for (Document doc : objectIds) { objectIdList.add(doc.getString("redboxOid")); } return objectIdList; }
private MongoBlob getBlob(String id, long lastMod) { Bson query = getBlobQuery(id, lastMod); Bson fields = new BasicDBObject(MongoBlob.KEY_DATA, 1); // try with default read preference first, may be from secondary List<MongoBlob> result = new ArrayList<>(1); getBlobCollection().withReadPreference(defaultReadPreference).find(query) .projection(fields).into(result); if (result.isEmpty()) { // not found in the secondary: try the primary getBlobCollection().withReadPreference(primary()).find(query) .projection(fields).into(result); } return result.isEmpty() ? null : result.get(0); }
private MongoBlob getBlob(String id, long lastMod) { Bson query = getBlobQuery(id, lastMod); Bson fields = new BasicDBObject(MongoBlob.KEY_DATA, 1); // try with default read preference first, may be from secondary List<MongoBlob> result = new ArrayList<>(1); getBlobCollection().withReadPreference(defaultReadPreference).find(query) .projection(fields).into(result); if (result.isEmpty()) { // not found in the secondary: try the primary getBlobCollection().withReadPreference(primary()).find(query) .projection(fields).into(result); } return result.isEmpty() ? null : result.get(0); }
private void refreshList() { Document filter = new Document("owner_id", _client.getAuth().getUser().getId()); FindIterable cursor = getItemsCollection().find(filter).limit(100); final ArrayList<Document> documents = new ArrayList<Document>(); cursor.into(documents); _itemAdapter.clear(); _itemAdapter.addAll(convertDocsToTodo(documents)); _itemAdapter.notifyDataSetChanged(); }