-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Spring Data's Query by Example feature. See #532 and spring-projects/spring-data-relational#929.
- Loading branch information
lub2code
committed
Mar 4, 2021
1 parent
65872fb
commit bcd35a0
Showing
12 changed files
with
507 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/org/springframework/data/r2dbc/documentation/QueryByExampleTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.springframework.data.r2dbc.documentation; | ||
|
||
import static org.springframework.data.domain.ExampleMatcher.*; | ||
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import reactor.core.publisher.Flux; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.domain.Example; | ||
import org.springframework.data.domain.ExampleMatcher; | ||
import org.springframework.data.r2dbc.repository.R2dbcRepository; | ||
|
||
public class QueryByExampleTests { | ||
|
||
private EmployeeRepository repository; | ||
|
||
@Test | ||
void queryByExampleSimple() { | ||
|
||
// tag::example[] | ||
Employee employee = new Employee(); // <1> | ||
employee.setName("Frodo"); | ||
|
||
Example<Employee> example = Example.of(employee); // <2> | ||
|
||
Flux<Employee> employees = repository.findAll(example); // <3> | ||
|
||
// do whatever with the flux | ||
// end::example[] | ||
} | ||
|
||
@Test | ||
void queryByExampleCustomMatcher() { | ||
|
||
// tag::example-2[] | ||
Employee employee = new Employee(); | ||
employee.setName("Baggins"); | ||
employee.setRole("ring bearer"); | ||
|
||
ExampleMatcher matcher = matching() // <1> | ||
.withMatcher("name", endsWith()) // <2> | ||
.withIncludeNullValues() // <3> | ||
.withIgnorePaths("role"); // <4> | ||
Example<Employee> example = Example.of(employee, matcher); // <5> | ||
|
||
Flux<Employee> employees = repository.findAll(example); | ||
|
||
// do whatever with the flux | ||
// end::example-2[] | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class Employee { | ||
|
||
private @Id Integer id; | ||
private String name; | ||
private String role; | ||
} | ||
|
||
public interface EmployeeRepository extends R2dbcRepository<Employee, Integer> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.