#124 - Added Querydsl integration to Starbucks example.

Enabled Querydsl query metadata creation to the Starbucks example and added binding customizations to UserRepository.
This commit is contained in:
Oliver Gierke
2015-08-04 15:46:27 +02:00
parent bbaa53c873
commit 7eab65b53f
3 changed files with 45 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ We have separate folders for the samples of individual modules:
## Spring Data web support
* `web` - Example for Spring Data web integration (binding `Pageable` instances to Spring MVC controller methods, using interfaces to bind Spring MVCrequest payloads).
* `querydsl` - Example for Spring Data Querydsl web integration (creating a `Predicate` from web requests).
## Miscellaneous

View File

@@ -84,6 +84,31 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${apt.version}</version>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
<logOnlyOnError>true</logOnlyOnError>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -19,17 +19,35 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Point;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RestResource;
import com.mysema.query.types.path.StringPath;
/**
* Repository interface for out-of-the-box paginating access to {@link Store}s and a query method to find stores by
* location and distance.
*
* @author Oliver Gierke
*/
public interface StoreRepository extends PagingAndSortingRepository<Store, String> {
public interface StoreRepository extends PagingAndSortingRepository<Store, String>, QueryDslPredicateExecutor<Store>,
QuerydslBinderCustomizer<QStore> {
@RestResource(rel = "by-location")
Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
/**
* Tweak the Querydsl binding if collection resources are filtered.
*
* @see org.springframework.data.web.querydsl.QuerydslBinderCustomizer#customize(org.springframework.data.web.querydsl.QuerydslBindings,
* com.mysema.query.types.EntityPath)
*/
default void customize(QuerydslBindings bindings, QStore store) {
bindings.bind(store.address.city).first((path, value) -> path.endsWith(value));
bindings.bind(String.class).first((StringPath path, String value) -> path.contains(value));
}
}