Browse Source

DATAMONGO-1907 - Polishing.

Rename test method to reflect test subject.

Switch from flatMap(…) to map(…) to avoid overhead of Mono creation.

Original pull request: #541.
pull/542/merge
Mark Paluch 8 years ago
parent
commit
1ad975de0a
  1. 13
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java
  2. 2
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java

13
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java

@ -92,12 +92,12 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement @@ -92,12 +92,12 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
q.limit(2);
return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
.flatMap(vals -> {
.map(vals -> {
if (vals.size() > 1) {
return Mono.error(new IncorrectResultSizeDataAccessException(1));
throw new IncorrectResultSizeDataAccessException(1);
}
return Mono.just(vals.iterator().next());
return vals.iterator().next();
}).next();
}
@ -315,10 +315,9 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement @@ -315,10 +315,9 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
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)));
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)));
}
/*

2
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java

@ -443,7 +443,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware, @@ -443,7 +443,7 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
}
@Test // DATAMONGO-1907
public void existsByExampleShouldReturnNonExistingWithoutThrowException() {
public void findOneByExampleWithoutResultShouldCompleteEmpty() {
Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1));

Loading…
Cancel
Save