<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.version>4.3.0.RELEASE</spring.version>
+ <querydsl.version>4.1.3</querydsl.version>
</properties>
<profiles>
<version>5.2.2.Final</version>
</dependency>
+ <!-- Using Querydsl -->
+ <dependency>
+ <groupId>com.querydsl</groupId>
+ <artifactId>querydsl-apt</artifactId>
+ <version>${querydsl.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.querydsl</groupId>
+ <artifactId>querydsl-jpa</artifactId>
+ <version>${querydsl.version}</version>
+ </dependency>
+
+
<!-- Unitary and integration tests -->
<dependency>
<groupId>junit</groupId>
<version>2.0.11-beta</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <version>2.18.1</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
</archive>
</configuration>
</plugin>
+
+ <!-- Using Querydsl -->
+ <plugin>
+ <groupId>com.mysema.maven</groupId>
+ <artifactId>apt-maven-plugin</artifactId>
+ <version>1.0.4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/generated-sources/querydsl</outputDirectory>
+ <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Required in order to work with m2e plugin for Eclipse -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.11</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.build.directory}/generated-sources/querydsl</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.18.1</version>
<executions>
<execution>
<goals>
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
+import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import de.spring.example.persistence.domain.Ad;
* Be careful with <code>@Transactional</code>. SimpleJpaRepository has annotated methods.
*
*/
-public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long> {
+public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long>, QueryDslPredicateExecutor<AdDescription> {
// Custom Query method (useful when the offered methods by PagingAndSortingRepository are not enough)
Page<AdDescription> findByAd(Ad ad, Pageable pageable);
import javax.inject.Named;
import org.resthub.common.service.CrudServiceImpl;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import com.querydsl.core.types.dsl.BooleanExpression;
import de.spring.example.persistence.domain.AdDescription;
+import de.spring.example.persistence.domain.QAdDescription;
import de.spring.example.persistence.repository.AdDescriptionRepository;
import de.spring.example.services.AdDescriptionService;
// the JPA repositories and nothing else :)
// In this case there is any business logic, but this is just an example.
+
+
+ /**
+ * Using Querydsl. Giving some business logic to this service :)
+ */
+ @Override
+ public Page<AdDescription> queryDslExample(Pageable pageRequest) {
+ final QAdDescription adDescription = QAdDescription.adDescription1;
+ final BooleanExpression adDescriptionHasAdLink = adDescription.adLink.contains("gumartinm");
+ final BooleanExpression adDescriptionHasDescription = adDescription.adDescription.contains("babucha");
+
+ return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);
+ }
}