@Override public <S extends T> S insert(S entity) { Assert.notNull(entity, "Entity must not be null!"); return mongoOperations.insert(entity, entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<S> insert(S entity) { Assert.notNull(entity, "Entity must not be null!"); return mongoOperations.insert(entity, entityInformation.getCollectionName()); }
@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()); }
private List<T> findAll(@Nullable Query query) { if (query == null) { return Collections.emptyList(); } return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName()); } }
@Override public Optional<T> findById(ID id) { Assert.notNull(id, "The given id must not be null!"); return Optional.ofNullable( mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName())); }
@Override public Mono<T> findById(ID id) { Assert.notNull(id, "The given id must not be null!"); return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()); }
@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 void deleteById(ID id) { Assert.notNull(id, "The given id must not be null!"); mongoOperations.remove(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName()); }
@Override public <S extends T> Flux<S> insert(Publisher<S> entities) { Assert.notNull(entities, "The given Publisher of entities must not be null!"); return Flux.from(entities).flatMap(entity -> mongoOperations.insert(entity, entityInformation.getCollectionName())); }
@Override public boolean existsById(ID id) { Assert.notNull(id, "The given id must not be null!"); return mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName()); }
@Override public Mono<Boolean> existsById(Publisher<ID> publisher) { Assert.notNull(publisher, "The given id must not be null!"); return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName())); }
@Override public <S extends T> Flux<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); Streamable<S> source = Streamable.of(entities); return source.stream().allMatch(entityInformation::isNew) ? // mongoOperations.insert(source.stream().collect(Collectors.toList()), entityInformation.getCollectionName()) : // Flux.fromIterable(entities).flatMap(this::save); }
@Override public Mono<Void> deleteById(ID id) { Assert.notNull(id, "The given id must not be null!"); return mongoOperations .remove(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName()).then(); }
@Override public <S extends T> Optional<S> findOne(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); return Optional .ofNullable(mongoOperations.findOne(q, example.getProbeType(), entityInformation.getCollectionName())); }
@Override public <S extends T> List<S> findAll(Example<S> example, Sort sort) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(sort, "Sort must not be null!"); Query q = new Query(new Criteria().alike(example)).with(sort); return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<Long> count(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); return mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public <S extends T> long count(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); return mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public <S extends T> boolean exists(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); return mongoOperations.exists(q, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<Boolean> exists(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); return mongoOperations.exists(q, example.getProbeType(), entityInformation.getCollectionName()); }