@Override public <S extends T> List<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities not be null!"); Streamable<S> source = Streamable.of(entities); boolean allNew = source.stream().allMatch(it -> entityInformation.isNew(it)); if (allNew) { List<S> result = source.stream().collect(Collectors.toList()); return new ArrayList<>(mongoOperations.insert(result, entityInformation.getCollectionName())); } return source.stream().map(this::save).collect(Collectors.toList()); }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return mongoOperations.insert(entity, entityInformation.getCollectionName()); } return mongoOperations.save(entity, entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<S> save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return mongoOperations.insert(entity, entityInformation.getCollectionName()); } return mongoOperations.save(entity, entityInformation.getCollectionName()); }
@Override public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) { Assert.notNull(entityStream, "The given Publisher of entities must not be null!"); return Flux.from(entityStream).flatMap(entity -> entityInformation.isNew(entity) ? // mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity))); }
@Override public <S extends T> List<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities not be null!"); Streamable<S> source = Streamable.of(entities); boolean allNew = source.stream().allMatch(it -> entityInformation.isNew(it)); if (allNew) { List<S> result = source.stream().collect(Collectors.toList()); return new ArrayList<>(mongoOperations.insert(result, entityInformation.getCollectionName())); } return source.stream().map(this::save).collect(Collectors.toList()); }
@Override public <S extends T> S save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return mongoOperations.insert(entity, entityInformation.getCollectionName()); } return mongoOperations.save(entity, entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<S> save(S entity) { Assert.notNull(entity, "Entity must not be null!"); if (entityInformation.isNew(entity)) { return mongoOperations.insert(entity, entityInformation.getCollectionName()); } return mongoOperations.save(entity, entityInformation.getCollectionName()); }
@Override public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) { Assert.notNull(entityStream, "The given Publisher of entities must not be null!"); return Flux.from(entityStream).flatMap(entity -> entityInformation.isNew(entity) ? // mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity))); }