/** * Static factory method to create a {@link Criteria} matching an example object. * * @param example must not be {@literal null}. * @return * @see Criteria#alike(Example) * @since 1.8 */ public static Criteria byExample(Example<?> example) { return new Criteria().alike(example); }
@Override public <S extends T> Mono<S> findOne(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); q.limit(2); return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2) .map(vals -> { if (vals.size() > 1) { throw new IncorrectResultSizeDataAccessException(1); } return vals.iterator().next(); }).next(); }
@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> 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> Flux<S> findAll(Example<S> example, Sort sort) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(sort, "Sort must not be null!"); Query query = new Query(new Criteria().alike(example)).with(sort); return mongoOperations.find(query, 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> 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()); }
@Override public <S extends T> Page<S> findAll(final Example<S> example, Pageable pageable) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); Query q = new Query(new Criteria().alike(example)).with(pageable); List<S> list = mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); return PageableExecutionUtils.getPage(list, pageable, () -> mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName())); }
/** * Static factory method to create a {@link Criteria} matching an example object. * * @param example must not be {@literal null}. * @return * @see Criteria#alike(Example) * @since 1.8 */ public static Criteria byExample(Example<?> example) { return new Criteria().alike(example); }
@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> Flux<S> findAll(Example<S> example, Sort sort) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(sort, "Sort must not be null!"); Query query = new Query(new Criteria().alike(example)).with(sort); return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName()); }
@Override public <S extends T> Mono<S> findOne(Example<S> example) { Assert.notNull(example, "Sample must not be null!"); Query q = new Query(new Criteria().alike(example)); q.limit(2); return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2) .map(vals -> { if (vals.size() > 1) { throw new IncorrectResultSizeDataAccessException(1); } return vals.iterator().next(); }).next(); }
@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> 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()); }
@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> Page<S> findAll(final Example<S> example, Pageable pageable) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); Query q = new Query(new Criteria().alike(example)).with(pageable); List<S> list = mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); return PageableExecutionUtils.getPage(list, pageable, () -> mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName())); }