1 package de.spring.example.services.impl;
3 import javax.inject.Inject;
4 import javax.inject.Named;
6 import org.resthub.common.service.CrudServiceImpl;
7 import org.springframework.data.domain.Page;
8 import org.springframework.data.domain.Pageable;
10 import com.querydsl.core.types.dsl.BooleanExpression;
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;
17 @Named("adDescriptionService")
18 public class AdDescriptionServiceImpl
19 extends CrudServiceImpl<AdDescription, Long, AdDescriptionRepository>
20 implements AdDescriptionService {
24 public void setRepository(AdDescriptionRepository repository) {
25 this.repository = repository;
28 // Extending CrudServiceImpl when we need some business logic. Otherwise we would be using
29 // the JPA repositories and nothing else :)
31 // In this case there is any business logic, but this is just an example.
35 * Using Querydsl. Giving some business logic to this service :)
37 * Querydsl: fluent interface done easy. There is no effort because it is already implemented.
39 * Criteria using Specifications requires some effort.
41 * See: de.spring.example.services.impl.AdServiceImpl
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");
49 return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);