Skip to content

DATAMONGO-1712 - Adopt to ReactiveCrudRepository.findById(Publisher) and existsById(Publisher) #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand All @@ -28,7 +28,7 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>2.0.0.BUILD-SNAPSHOT</springdata.commons>
<springdata.commons>2.0.0.DATACMNS-1063-SNAPSHOT</springdata.commons>
<mongo>3.4.2</mongo>
<mongo.reactivestreams>1.4.0</mongo.reactivestreams>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
</dependency>

<!-- reactive -->
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-log4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1712-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public Mono<T> findById(ID id) {

/*
* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(reactor.core.publisher.Mono)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
*/
@Override
public Mono<T> findById(Mono<ID> mono) {
public Mono<T> findById(Publisher<ID> publisher) {

Assert.notNull(mono, "The given id must not be null!");
Assert.notNull(publisher, "The given id must not be null!");

return mono.flatMap(
return Mono.from(publisher).flatMap(
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
}

Expand Down Expand Up @@ -115,14 +115,14 @@ public Mono<Boolean> existsById(ID id) {

/*
* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(reactor.core.publisher.Mono)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
*/
@Override
public Mono<Boolean> existsById(Mono<ID> mono) {
public Mono<Boolean> existsById(Publisher<ID> publisher) {

Assert.notNull(mono, "The given id must not be null!");
Assert.notNull(publisher, "The given id must not be null!");

return mono.flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
entityInformation.getCollectionName()));

}
Expand Down Expand Up @@ -180,6 +180,9 @@ public Flux<T> findAllById(Publisher<ID> ids) {
*/
@Override
public Flux<T> findAll(Sort sort) {

Assert.notNull(sort, "Sort must not be null!");

return findAll(new Query().with(sort));
}

Expand All @@ -204,6 +207,9 @@ public <S extends T> Flux<S> findAll(Example<S> example, Sort sort) {
*/
@Override
public <S extends T> Flux<S> findAll(Example<S> example) {

Assert.notNull(example, "Example must not be null!");

return findAll(example, Sort.unsorted());
}

Expand Down Expand Up @@ -327,6 +333,19 @@ public Mono<Void> deleteById(ID id) {
.remove(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName()).then();
}

/*
* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(org.reactivestreams.Publisher)
*/
@Override
public Mono<Void> deleteById(Publisher<ID> publisher) {

Assert.notNull(publisher, "Id must not be null!");

return Mono.from(publisher).flatMap(id -> mongoOperations.remove(getIdQuery(id), entityInformation.getJavaType(),
entityInformation.getCollectionName())).then();
}

/*
* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#delete(java.lang.Object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,38 @@ public void existsByMonoOfIdShouldReturnTrueForExistingObject() {
StepVerifier.create(repository.existsById(Mono.just(dave.id))).expectNext(true).verifyComplete();
}

@Test // DATAMONGO-1712
public void existsByFluxOfIdShouldReturnTrueForExistingObject() {
StepVerifier.create(repository.existsById(Flux.just(dave.id, oliver.id))).expectNext(true).verifyComplete();
}

@Test // DATAMONGO-1444
public void existsByEmptyMonoOfIdShouldReturnEmptyMono() {
StepVerifier.create(repository.existsById(Mono.empty())).verifyComplete();
}

@Test // DATAMONGO-1444
public void findOneShouldReturnObject() {
public void findByIdShouldReturnObject() {
StepVerifier.create(repository.findById(dave.id)).expectNext(dave).verifyComplete();
}

@Test // DATAMONGO-1444
public void findOneShouldCompleteWithoutValueForAbsentObject() {
public void findByIdShouldCompleteWithoutValueForAbsentObject() {
StepVerifier.create(repository.findById("unknown")).verifyComplete();
}

@Test // DATAMONGO-1444
public void findOneByMonoOfIdShouldReturnTrueForExistingObject() {
public void findByIdByMonoOfIdShouldReturnTrueForExistingObject() {
StepVerifier.create(repository.findById(Mono.just(dave.id))).expectNext(dave).verifyComplete();
}

@Test // DATAMONGO-1712
public void findByIdByFluxOfIdShouldReturnTrueForExistingObject() {
StepVerifier.create(repository.findById(Flux.just(dave.id, oliver.id))).expectNext(dave).verifyComplete();
}

@Test // DATAMONGO-1444
public void findOneByEmptyMonoOfIdShouldReturnEmptyMono() {
public void findByIdByEmptyMonoOfIdShouldReturnEmptyMono() {
StepVerifier.create(repository.findById(Mono.empty())).verifyComplete();
}

Expand Down Expand Up @@ -328,6 +338,23 @@ public void deleteByIdShouldRemoveEntity() {
StepVerifier.create(repository.findById(dave.id)).verifyComplete();
}

@Test // DATAMONGO-1712
public void deleteByIdUsingMonoShouldRemoveEntity() {

StepVerifier.create(repository.deleteById(Mono.just(dave.id))).verifyComplete();

StepVerifier.create(repository.existsById(dave.id)).expectNext(false).verifyComplete();
}

@Test // DATAMONGO-1712
public void deleteByIdUsingFluxShouldRemoveEntity() {

StepVerifier.create(repository.deleteById(Flux.just(dave.id, oliver.id))).verifyComplete();

StepVerifier.create(repository.existsById(dave.id)).expectNext(false).verifyComplete();
StepVerifier.create(repository.existsById(oliver.id)).expectNext(true).verifyComplete();
}

@Test // DATAMONGO-1444
public void deleteShouldRemoveEntity() {

Expand Down