830709b733b617b9d6601f87e186b1ae143b0df0
[JavaForFun] /
1 package de.spring.example.services.impl;
2
3 import javax.inject.Inject;
4 import javax.inject.Named;
5
6 import org.resthub.common.service.CrudServiceImpl;
7 import org.springframework.data.domain.Page;
8 import org.springframework.data.domain.Pageable;
9
10 import com.querydsl.core.types.dsl.BooleanExpression;
11
12 import de.spring.example.persistence.domain.AdDescription;
13 import de.spring.example.persistence.domain.QAdDescription;
14 import de.spring.example.persistence.repository.AdDescriptionRepository;
15 import de.spring.example.services.AdDescriptionService;
16
17 @Named("adDescriptionService")
18 public class AdDescriptionServiceImpl
19         extends CrudServiceImpl<AdDescription, Long, AdDescriptionRepository>
20         implements AdDescriptionService {
21
22         @Override
23         @Inject
24     public void setRepository(AdDescriptionRepository repository) {
25         this.repository = repository;
26     }
27
28         // Extending CrudServiceImpl when we need some business logic. Otherwise we would be using
29         // the JPA repositories and nothing else :)
30         
31         // In this case there is any business logic, but this is just an example.
32         
33         
34         /**
35          * Using Querydsl. Giving some business logic to this service :)
36          * 
37          * Querydsl: fluent interface done easy. There is no effort because it is already implemented.
38          * 
39          * Criteria using Specifications requires some effort.
40          * 
41          * See: de.spring.example.services.impl.AdServiceImpl
42          */
43         @Override
44         public Page<AdDescription> queryDslExample(Pageable pageRequest) {
45                 final QAdDescription adDescription = QAdDescription.adDescription1;
46                 final BooleanExpression adDescriptionHasAdLink = adDescription.adLink.contains("gumartinm");
47                 final BooleanExpression adDescriptionHasDescription = adDescription.adDescription.contains("babucha");
48                 /**
49                  * https://github.com/spring-projects/spring-data-envers/pull/45
50                  * return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);
51                  */
52                 return null;
53         }
54 }