BAEL-1325 (#4272)
* NatsClient refactor * add: mongodb reactive repositories * fix: test names * fix: test names * fix: test running on maven * fix: test name * fix: test class names * Rename tests
This commit is contained in:
committed by
Predrag Maric
parent
73935e65f2
commit
fb04fc4588
+13
-1
@@ -1,13 +1,25 @@
|
||||
package com.baeldung.reactive;
|
||||
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Spring5ReactiveApplication {
|
||||
public class Spring5ReactiveApplication{
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Spring5ReactiveApplication.class, args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
MongoClient mongoClient;
|
||||
|
||||
@Bean
|
||||
public ReactiveMongoTemplate reactiveMongoTemplate() {
|
||||
return new ReactiveMongoTemplate(mongoClient, "test");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.reactive.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@Data
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Account {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String owner;
|
||||
private Double value;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.reactive.repository;
|
||||
|
||||
import com.baeldung.reactive.model.Account;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Repository
|
||||
public interface AccountCrudRepository extends ReactiveCrudRepository<Account, String> {
|
||||
|
||||
public Flux<Account> findAllByValue(Double value);
|
||||
|
||||
public Mono<Account> findFirstByOwner(Mono<String> owner);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.reactive.repository;
|
||||
|
||||
import com.baeldung.reactive.model.Account;
|
||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
|
||||
|
||||
public interface AccountMongoRepository extends ReactiveMongoRepository<Account, String> {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.reactive.repository;
|
||||
|
||||
import com.baeldung.reactive.model.Account;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import org.springframework.data.repository.reactive.RxJava2CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AccountRxJavaRepository extends RxJava2CrudRepository<Account, String>{
|
||||
|
||||
public Observable<Account> findAllByValue(Double value);
|
||||
|
||||
public Single<Account> findFirstByOwner(Single<String> owner);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.reactive.template;
|
||||
|
||||
import com.baeldung.reactive.model.Account;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.ReactiveRemoveOperation;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Service
|
||||
public class AccountTemplateOperations {
|
||||
|
||||
@Autowired
|
||||
ReactiveMongoTemplate template;
|
||||
|
||||
public Mono<Account> findById(String id) {
|
||||
return template.findById(id, Account.class);
|
||||
}
|
||||
|
||||
public Flux<Account> findAll() {
|
||||
return template.findAll(Account.class);
|
||||
}
|
||||
|
||||
public Mono<Account> save(Mono<Account> account) {
|
||||
return template.save(account);
|
||||
}
|
||||
|
||||
public ReactiveRemoveOperation.ReactiveRemove<Account> deleteAll() {
|
||||
return template.remove(Account.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user