@Test public void testSaveMultipleDocumentsOK() throws IOException, DatabaseException { List<Document> documents = new ArrayList<>(); for (int i = 0; i < 100; i++) { XContentBuilder builder = jsonBuilder() .startObject() .field(VitamDocument.ID, GUIDFactory.newGUID().toString()) .field(VitamDocument.TENANT_ID, 0) .field(TITLE, TEST_SAVE + RandomUtils.nextDouble()) .endObject(); documents.add(Document.parse(Strings.toString(builder))); } repository.save(documents); MongoCollection<Document> collection = mongoRule.getMongoCollection(TEST_COLLECTION); long count = collection.countDocuments(); assertThat(count).isEqualTo(100); }
@Override public void save(Document document) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, collection, document); try { collection.insertOne(document); } catch (Exception e) { LOGGER.error("Insert Document Exception: ", e); throw new DatabaseException(e); } }
VitamMongoRepository implements VitamRepository { @Override public void save(Document document) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, collection, document); try { collection.insertOne(document); } catch (Exception e) { LOGGER.error("Insert Document Exception: ", e); throw new DatabaseException(e); } } }
VitamMongoRepository implements VitamRepository { @Override public void save(Document document) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, collection, document); try { collection.insertOne(document); } catch (Exception e) { LOGGER.error("Insert Document Exception: ", e); throw new DatabaseException(e); } } VitamMongoRepository(MongoCollection<Document> collection); }
VitamMongoRepository implements VitamRepository { @Override public void save(Document document) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, collection, document); try { collection.insertOne(document); } catch (Exception e) { LOGGER.error("Insert Document Exception: ", e); throw new DatabaseException(e); } } 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 void save(Document document) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, collection, document); try { collection.insertOne(document); } catch (Exception e) { LOGGER.error("Insert Document Exception: ", e); throw new DatabaseException(e); } } 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; }