@Test public void testFindDocuments() throws Exception { List<Document> documents = new ArrayList<>(); for (int i = 0; i < 10; i++) { XContentBuilder builder = jsonBuilder() .startObject() .field(VitamDocument.ID, GUIDFactory.newGUID().toString()) .field(VitamDocument.TENANT_ID, 0) .field(TITLE, TEST_SAVE + i + " " + RandomUtils.nextDouble()) .endObject(); documents.add(Document.parse(Strings.toString(builder))); } repository.save(documents); FindIterable<Document> iterable = repository.findDocuments(2, 0); MongoCursor<Document> cursor; cursor = iterable.iterator(); List<Document> docs = getDocuments(cursor, 2); assertThat(docs.size()).isEqualTo(2); while (!docs.isEmpty()) { docs = getDocuments(cursor, 2); } assertThat(docs.size()).isEqualTo(0); }
@Override public FindIterable<Document> findDocuments(Collection<String> ids, Bson projection) { ParametersChecker.checkParameter("Id list is required ", ids); if (null == projection) { return collection.find(in(ID, ids)); } else { return collection.find(in(ID, ids)).projection(projection); } }
VitamMongoRepository implements VitamRepository { @Override public FindIterable<Document> findDocuments(Collection<String> ids, Bson projection) { ParametersChecker.checkParameter("Id list is required ", ids); if (null == projection) { return collection.find(in(ID, ids)); } else { return collection.find(in(ID, ids)).projection(projection); } } }
VitamMongoRepository implements VitamRepository { @Override public FindIterable<Document> findDocuments(Collection<String> ids, Bson projection) { ParametersChecker.checkParameter("Id list is required ", ids); if (null == projection) { return collection.find(in(ID, ids)); } else { return collection.find(in(ID, ids)).projection(projection); } } VitamMongoRepository(MongoCollection<Document> collection); }
VitamMongoRepository implements VitamRepository { @Override public FindIterable<Document> findDocuments(Collection<String> ids, Bson projection) { ParametersChecker.checkParameter("Id list is required ", ids); if (null == projection) { return collection.find(in(ID, ids)); } else { return collection.find(in(ID, ids)).projection(projection); } } VitamMongoRepository(MongoCollection<Document> collection); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> queries); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override FindIterable<Document> findDocuments(int mongoBatchSize, Integer tenant); @Override FindIterable<Document> findDocuments(int mongoBatchSize); @Override FindIterable<Document> findDocuments(Bson query, int mongoBatchSize); @Override void delete(List<String> ids, int tenant); }
VitamMongoRepository implements VitamRepository { @Override public FindIterable<Document> findDocuments(Collection<String> ids, Bson projection) { ParametersChecker.checkParameter("Id list is required ", ids); if (null == projection) { return collection.find(in(ID, ids)); } else { return collection.find(in(ID, ids)).projection(projection); } } VitamMongoRepository(MongoCollection<Document> collection); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> queries); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override FindIterable<Document> findDocuments(int mongoBatchSize, Integer tenant); @Override FindIterable<Document> findDocuments(int mongoBatchSize); @Override FindIterable<Document> findDocuments(Bson query, int mongoBatchSize); @Override void delete(List<String> ids, int tenant); static final String NAME; }