001d3a75ae23768d20001c08b71c9cbcf816efce
[JavaForFun] /
1 package de.spring.webservices.rest.business.service.impl;
2
3 import java.util.concurrent.CompletableFuture;
4
5 import javax.inject.Inject;
6
7 import org.springframework.data.domain.Page;
8 import org.springframework.data.domain.Pageable;
9 import org.springframework.stereotype.Service;
10
11 import de.spring.webservices.domain.Car;
12 import de.spring.webservices.rest.business.service.AwesomeBusinessLogic;
13 import de.spring.webservices.rest.business.service.CompletableFutureBusinessLogic;
14
15 /**
16  * 
17  * 
18  * TODO: WHAT ABOUT EXCEPTIONS FROM awesomeBusinessLogic? RuntimeExceptions for example
19  * I guess they will be caught by my adapter in controller layer but I must try it.
20  *
21  */
22
23
24 @Service("completableFutureBusinessLogic")
25 public class CompletablefutureBusinessLogicImpl implements CompletableFutureBusinessLogic {
26     private final AwesomeBusinessLogic awesomeBusinessLogic;
27     
28     @Inject
29         public CompletablefutureBusinessLogicImpl(AwesomeBusinessLogic awesomeBusinessLogic) {
30                 this.awesomeBusinessLogic = awesomeBusinessLogic;
31         }
32
33         @Override
34         public CompletableFuture<Page<Car>> findAll(Pageable pageRequest) {
35         return CompletableFuture.supplyAsync(() -> awesomeBusinessLogic.findAll(pageRequest));
36         }
37
38         @Override
39         public CompletableFuture<Car> findById(long id) {
40         return CompletableFuture.supplyAsync(() -> awesomeBusinessLogic.findById(id));
41         }
42
43         @Override
44         public CompletableFuture<Car> create(Car car) {
45                 return CompletableFuture.supplyAsync(() -> awesomeBusinessLogic.create(car));
46         }
47 }