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. 9
      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

9
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
q.limit(2); q.limit(2);
return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2) return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
.flatMap(vals -> { .map(vals -> {
if (vals.size() > 1) { 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(); }).next();
} }
@ -315,8 +315,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
Assert.notNull(entityStream, "The given Publisher of entities must not be null!"); Assert.notNull(entityStream, "The given Publisher of entities must not be null!");
return Flux.from(entityStream) return Flux.from(entityStream).flatMap(entity -> entityInformation.isNew(entity) ? //
.flatMap(entity -> entityInformation.isNew(entity) ? //
mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : // mongoOperations.insert(entity, entityInformation.getCollectionName()).then(Mono.just(entity)) : //
mongoOperations.save(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,
} }
@Test // DATAMONGO-1907 @Test // DATAMONGO-1907
public void existsByExampleShouldReturnNonExistingWithoutThrowException() { public void findOneByExampleWithoutResultShouldCompleteEmpty() {
Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1)); Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1));

Loading…
Cancel
Save