Browse Source

DATAMONGO-2181 - Consider repository collection name in ReactiveMongoRepository.saveAll(…).

We now consider the collection name that is bound to the repository when inserting entities of which all are new. Previously, the collection name was derived from the entity.

Original Pull Request: #632
pull/633/head
Mark Paluch 7 years ago committed by Christoph Strobl
parent
commit
7d5d0bbdfc
  1. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java
  2. 35
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

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

@ -301,8 +301,8 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement @@ -301,8 +301,8 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
Streamable<S> source = Streamable.of(entities);
return source.stream().allMatch(it -> entityInformation.isNew(it)) ? //
mongoOperations.insertAll(source.stream().collect(Collectors.toList())) : //
return source.stream().allMatch(entityInformation::isNew) ? //
mongoOperations.insert(source.stream().collect(Collectors.toList()), entityInformation.getCollectionName()) : //
Flux.fromIterable(entities).flatMap(this::save);
}

35
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.repository;
import static org.assertj.core.api.Assertions.offset;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.Sort.Direction.*;
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
@ -78,6 +78,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF @@ -78,6 +78,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
ClassLoader classLoader;
BeanFactory beanFactory;
ReactivePersonRepository repository;
ReactiveContactRepository contactRepository;
ReactiveCappedCollectionRepository cappedRepository;
Person dave, oliver, carter, boyd, stefan, leroi, alicia;
@ -102,6 +103,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF @@ -102,6 +103,7 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
factory.setEvaluationContextProvider(QueryMethodEvaluationContextProvider.DEFAULT);
repository = factory.getRepository(ReactivePersonRepository.class);
contactRepository = factory.getRepository(ReactiveContactRepository.class);
cappedRepository = factory.getRepository(ReactiveCappedCollectionRepository.class);
StepVerifier.create(repository.deleteAll()).verifyComplete();
@ -345,6 +347,35 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF @@ -345,6 +347,35 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
}).verifyComplete();
}
@Test // DATAMONGO-2181
public void considersRepositoryCollectionName() {
repository.deleteAll() //
.as(StepVerifier::create) //
.verifyComplete();
contactRepository.deleteAll() //
.as(StepVerifier::create) //
.verifyComplete();
leroi.id = null;
boyd.id = null;
contactRepository.saveAll(Arrays.asList(leroi, boyd)) //
.as(StepVerifier::create) //
.expectNextCount(2) //
.verifyComplete();
repository.count() //
.as(StepVerifier::create) //
.expectNext(0L) //
.verifyComplete();
contactRepository.count() //
.as(StepVerifier::create) //
.expectNext(2L) //
.verifyComplete();
}
interface ReactivePersonRepository extends ReactiveMongoRepository<Person, String> {
Flux<Person> findByLastname(String lastname);
@ -385,6 +416,8 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF @@ -385,6 +416,8 @@ public class ReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanF
Flux<Person> findByAgeGreaterThan(int age, Sort sort);
}
interface ReactiveContactRepository extends ReactiveMongoRepository<Contact, String> {}
interface ReactiveCappedCollectionRepository extends Repository<Capped, String> {
@Tailable

Loading…
Cancel
Save