@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package example.springdata.mongodb.people;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
@@ -26,13 +24,14 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@Document
|
||||
public class Person {
|
||||
public record Person(@Id String id, String firstname, String lastname, int age) {
|
||||
|
||||
private @Id String id;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final int age;
|
||||
@PersistenceConstructor
|
||||
public Person {
|
||||
}
|
||||
|
||||
public Person(String firstname, String lastname, int age) {
|
||||
this(null, firstname, lastname, age);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ReactiveMongoTemplateIntegrationTest {
|
||||
|
||||
StepVerifier.create(template.dropCollection(Person.class)).verifyComplete();
|
||||
|
||||
Flux<Person> insertAll = template
|
||||
var insertAll = template
|
||||
.insertAll(Flux.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
@@ -66,7 +66,7 @@ public class ReactiveMongoTemplateIntegrationTest {
|
||||
@Test
|
||||
public void shouldInsertAndCountData() {
|
||||
|
||||
Mono<Long> count = template.count(new Query(), Person.class) //
|
||||
var count = template.count(new Query(), Person.class) //
|
||||
.doOnNext(System.out::println) //
|
||||
.thenMany(template.insertAll(Arrays.asList(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))) //
|
||||
@@ -83,7 +83,7 @@ public class ReactiveMongoTemplateIntegrationTest {
|
||||
@Test
|
||||
public void convertReactorTypesToRxJava2() {
|
||||
|
||||
Flux<Person> flux = template.find(Query.query(Criteria.where("lastname").is("White")), Person.class);
|
||||
var flux = template.find(Query.query(Criteria.where("lastname").is("White")), Person.class);
|
||||
|
||||
long count = RxReactiveStreams.toObservable(flux).count().toSingle().toBlocking().value();
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ReactivePersonRepositoryIntegrationTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
Mono<MongoCollection<Document>> recreateCollection = operations.collectionExists(Person.class) //
|
||||
var recreateCollection = operations.collectionExists(Person.class) //
|
||||
.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
|
||||
.then(operations.createCollection(Person.class, CollectionOptions.empty() //
|
||||
.size(1024 * 1024) //
|
||||
@@ -61,7 +61,7 @@ public class ReactivePersonRepositoryIntegrationTest {
|
||||
|
||||
StepVerifier.create(recreateCollection).expectNextCount(1).verifyComplete();
|
||||
|
||||
Flux<Person> insertAll = operations.insertAll(Flux.just(new Person("Walter", "White", 50), //
|
||||
var insertAll = operations.insertAll(Flux.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
new Person("Jesse", "Pinkman", 27)).collectList());
|
||||
@@ -76,7 +76,7 @@ public class ReactivePersonRepositoryIntegrationTest {
|
||||
@Test
|
||||
public void shouldInsertAndCountData() {
|
||||
|
||||
Mono<Long> saveAndCount = repository.count() //
|
||||
var saveAndCount = repository.count() //
|
||||
.doOnNext(System.out::println) //
|
||||
.thenMany(repository.saveAll(Flux.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))) //
|
||||
@@ -106,7 +106,7 @@ public class ReactivePersonRepositoryIntegrationTest {
|
||||
|
||||
Queue<Person> people = new ConcurrentLinkedQueue<>();
|
||||
|
||||
Disposable disposable = repository.findWithTailableCursorBy() //
|
||||
var disposable = repository.findWithTailableCursorBy() //
|
||||
.doOnNext(System.out::println) //
|
||||
.doOnNext(people::add) //
|
||||
.doOnComplete(() -> System.out.println("Complete")) //
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
Mono<MongoCollection<Document>> recreateCollection = operations.collectionExists(Person.class) //
|
||||
var recreateCollection = operations.collectionExists(Person.class) //
|
||||
.flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
|
||||
.then(operations.createCollection(Person.class, CollectionOptions.empty() //
|
||||
.size(1024 * 1024) //
|
||||
@@ -83,7 +83,7 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
@Test
|
||||
public void shouldInsertAndCountData() {
|
||||
|
||||
Flowable<Person> people = Flowable.just(new Person("Hank", "Schrader", 43), //
|
||||
var people = Flowable.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62));
|
||||
|
||||
repository.count() //
|
||||
@@ -124,7 +124,7 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
|
||||
Queue<Person> people = new ConcurrentLinkedQueue<>();
|
||||
|
||||
Disposable subscription = repository.findWithTailableCursorBy() //
|
||||
var subscription = repository.findWithTailableCursorBy() //
|
||||
.doOnNext(System.out::println) //
|
||||
.doOnNext(people::add) //
|
||||
.doOnComplete(() -> System.out.println("Complete")) //
|
||||
|
||||
Reference in New Issue
Block a user