DATAJPA-765 - Upgraded to Querydsl 4.
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -26,7 +26,6 @@
|
||||
<hsqldb1>1.8.0.10</hsqldb1>
|
||||
<jpa>2.0.0</jpa>
|
||||
<openjpa>2.4.0</openjpa>
|
||||
<querydsl>3.6.3</querydsl>
|
||||
<springdata.commons>1.12.0.BUILD-SNAPSHOT</springdata.commons>
|
||||
|
||||
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
|
||||
@@ -223,14 +222,14 @@
|
||||
|
||||
<!-- QueryDsl -->
|
||||
<dependency>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<groupId>com.querydsl</groupId>
|
||||
<artifactId>querydsl-apt</artifactId>
|
||||
<version>${querydsl}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<groupId>com.querydsl</groupId>
|
||||
<artifactId>querydsl-jpa</artifactId>
|
||||
<version>${querydsl}</version>
|
||||
<optional>true</optional>
|
||||
@@ -424,7 +423,7 @@
|
||||
<configuration>
|
||||
<logOnlyOnError>true</logOnlyOnError>
|
||||
<processors>
|
||||
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
|
||||
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
|
||||
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
|
||||
</processors>
|
||||
</configuration>
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.springframework.data.querydsl.QSort;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
import com.querydsl.jpa.impl.AbstractJPAQuery;
|
||||
|
||||
/**
|
||||
* QueryDsl specific extension of {@link SimpleJpaRepository} which adds implementation for
|
||||
@@ -46,8 +46,8 @@ import com.mysema.query.types.path.PathBuilder;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements
|
||||
QueryDslPredicateExecutor<T> {
|
||||
public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
|
||||
implements QueryDslPredicateExecutor<T> {
|
||||
|
||||
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;
|
||||
|
||||
@@ -78,6 +78,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
EntityPathResolver resolver) {
|
||||
|
||||
super(entityInformation, entityManager);
|
||||
|
||||
this.path = resolver.createPath(entityInformation.getJavaType());
|
||||
this.builder = new PathBuilder<T>(path.getType(), path.getMetadata());
|
||||
this.querydsl = new Querydsl(entityManager, builder);
|
||||
@@ -89,7 +90,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public T findOne(Predicate predicate) {
|
||||
return createQuery(predicate).uniqueResult(path);
|
||||
return createQuery(predicate).select(path).fetchOne();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -98,7 +99,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate) {
|
||||
return createQuery(predicate).list(path);
|
||||
return createQuery(predicate).select(path).fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -107,7 +108,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
|
||||
return executeSorted(createQuery(predicate), orders);
|
||||
return executeSorted(createQuery(predicate).select(path), orders);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -116,7 +117,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate, Sort sort) {
|
||||
return executeSorted(createQuery(predicate), sort);
|
||||
return executeSorted(createQuery(predicate).select(path), sort);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -125,7 +126,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll(OrderSpecifier<?>... orders) {
|
||||
return executeSorted(createQuery(new Predicate[0]), orders);
|
||||
return executeSorted(createQuery(new Predicate[0]).select(path), orders);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -135,11 +136,11 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
@Override
|
||||
public Page<T> findAll(Predicate predicate, Pageable pageable) {
|
||||
|
||||
JPQLQuery countQuery = createQuery(predicate);
|
||||
JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate));
|
||||
JPQLQuery<?> countQuery = createQuery(predicate);
|
||||
JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path));
|
||||
|
||||
Long total = countQuery.count();
|
||||
List<T> content = pageable == null || total > pageable.getOffset() ? query.list(path) : Collections.<T> emptyList();
|
||||
long total = countQuery.fetchCount();
|
||||
List<T> content = pageable == null || total > pageable.getOffset() ? query.fetch() : Collections.<T> emptyList();
|
||||
|
||||
return new PageImpl<T>(content, pageable, total);
|
||||
}
|
||||
@@ -150,7 +151,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public long count(Predicate predicate) {
|
||||
return createQuery(predicate).count();
|
||||
return createQuery(predicate).fetchCount();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -159,7 +160,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
*/
|
||||
@Override
|
||||
public boolean exists(Predicate predicate) {
|
||||
return createQuery(predicate).exists();
|
||||
return createQuery(predicate).fetchCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,9 +169,9 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
* @param predicate
|
||||
* @return the Querydsl {@link JPQLQuery}.
|
||||
*/
|
||||
protected JPQLQuery createQuery(Predicate... predicate) {
|
||||
protected JPQLQuery<?> createQuery(Predicate... predicate) {
|
||||
|
||||
JPAQuery query = querydsl.createQuery(path).where(predicate);
|
||||
AbstractJPAQuery<?, ?> query = querydsl.createQuery(path).where(predicate);
|
||||
CrudMethodMetadata metadata = getRepositoryMethodMetadata();
|
||||
|
||||
if (metadata == null) {
|
||||
@@ -194,7 +195,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
* @param orders must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private List<T> executeSorted(JPQLQuery query, OrderSpecifier<?>... orders) {
|
||||
private List<T> executeSorted(JPQLQuery<T> query, OrderSpecifier<?>... orders) {
|
||||
return executeSorted(query, new QSort(orders));
|
||||
}
|
||||
|
||||
@@ -205,7 +206,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
* @param sort must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private List<T> executeSorted(JPQLQuery query, Sort sort) {
|
||||
return querydsl.applySorting(sort, query).list(path);
|
||||
private List<T> executeSorted(JPQLQuery<T> query, Sort sort) {
|
||||
return querydsl.applySorting(sort, query).fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ import javax.persistence.PersistenceContext;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mysema.query.dml.DeleteClause;
|
||||
import com.mysema.query.dml.UpdateClause;
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.jpa.impl.JPADeleteClause;
|
||||
import com.mysema.query.jpa.impl.JPAUpdateClause;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.mysema.query.types.path.PathBuilderFactory;
|
||||
import com.querydsl.core.dml.DeleteClause;
|
||||
import com.querydsl.core.dml.UpdateClause;
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.core.types.dsl.PathBuilderFactory;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
import com.querydsl.jpa.impl.JPADeleteClause;
|
||||
import com.querydsl.jpa.impl.JPAUpdateClause;
|
||||
|
||||
/**
|
||||
* Base class for implementing repositories using QueryDsl library.
|
||||
@@ -88,12 +88,23 @@ public abstract class QueryDslRepositorySupport {
|
||||
/**
|
||||
* Returns a fresh {@link JPQLQuery}.
|
||||
*
|
||||
* @param path must not be {@literal null}.
|
||||
* @return the Querydsl {@link JPQLQuery}.
|
||||
*/
|
||||
protected JPQLQuery from(EntityPath<?>... paths) {
|
||||
protected JPQLQuery<Object> from(EntityPath<?>... paths) {
|
||||
return querydsl.createQuery(paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link JPQLQuery} for the given {@link EntityPath}.
|
||||
*
|
||||
* @param path must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected <T> JPQLQuery<T> from(EntityPath<T> path) {
|
||||
return querydsl.createQuery(path).select(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a fresh {@link DeleteClause}.
|
||||
*
|
||||
|
||||
@@ -27,19 +27,19 @@ import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.querydsl.QSort;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mysema.query.jpa.EclipseLinkTemplates;
|
||||
import com.mysema.query.jpa.HQLTemplates;
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.jpa.OpenJPATemplates;
|
||||
import com.mysema.query.jpa.impl.AbstractJPAQuery;
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
import com.mysema.query.support.Expressions;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.OrderSpecifier.NullHandling;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.OrderSpecifier.NullHandling;
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.jpa.EclipseLinkTemplates;
|
||||
import com.querydsl.jpa.HQLTemplates;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
import com.querydsl.jpa.OpenJPATemplates;
|
||||
import com.querydsl.jpa.impl.AbstractJPAQuery;
|
||||
import com.querydsl.jpa.impl.JPAQuery;
|
||||
|
||||
/**
|
||||
* Helper instance to ease access to Querydsl JPA query API.
|
||||
@@ -74,18 +74,18 @@ public class Querydsl {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AbstractJPAQuery<JPAQuery> createQuery() {
|
||||
public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
|
||||
|
||||
switch (provider) {
|
||||
case ECLIPSELINK:
|
||||
return new JPAQuery(em, EclipseLinkTemplates.DEFAULT);
|
||||
return new JPAQuery<T>(em, EclipseLinkTemplates.DEFAULT);
|
||||
case HIBERNATE:
|
||||
return new JPAQuery(em, HQLTemplates.DEFAULT);
|
||||
return new JPAQuery<T>(em, HQLTemplates.DEFAULT);
|
||||
case OPEN_JPA:
|
||||
return new JPAQuery(em, OpenJPATemplates.DEFAULT);
|
||||
return new JPAQuery<T>(em, OpenJPATemplates.DEFAULT);
|
||||
case GENERIC_JPA:
|
||||
default:
|
||||
return new JPAQuery(em);
|
||||
return new JPAQuery<T>(em);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Querydsl {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public AbstractJPAQuery<JPAQuery> createQuery(EntityPath<?>... paths) {
|
||||
public AbstractJPAQuery<Object, JPAQuery<Object>> createQuery(EntityPath<?>... paths) {
|
||||
return createQuery().from(paths);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class Querydsl {
|
||||
* @param query must not be {@literal null}.
|
||||
* @return the Querydsl {@link JPQLQuery}.
|
||||
*/
|
||||
public JPQLQuery applyPagination(Pageable pageable, JPQLQuery query) {
|
||||
public <T> JPQLQuery<T> applyPagination(Pageable pageable, JPQLQuery<T> query) {
|
||||
|
||||
if (pageable == null) {
|
||||
return query;
|
||||
@@ -124,7 +124,7 @@ public class Querydsl {
|
||||
* @param query must not be {@literal null}.
|
||||
* @return the Querydsl {@link JPQLQuery}
|
||||
*/
|
||||
public JPQLQuery applySorting(Sort sort, JPQLQuery query) {
|
||||
public <T> JPQLQuery<T> applySorting(Sort sort, JPQLQuery<T> query) {
|
||||
|
||||
if (sort == null) {
|
||||
return query;
|
||||
@@ -144,8 +144,7 @@ public class Querydsl {
|
||||
* @param qsort must not be {@literal null}.
|
||||
* @param query must not be {@literal null}.
|
||||
*/
|
||||
|
||||
private JPQLQuery addOrderByFrom(QSort qsort, JPQLQuery query) {
|
||||
private <T> JPQLQuery<T> addOrderByFrom(QSort qsort, JPQLQuery<T> query) {
|
||||
|
||||
List<OrderSpecifier<?>> orderSpecifiers = qsort.getOrderSpecifiers();
|
||||
return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
|
||||
@@ -159,7 +158,7 @@ public class Querydsl {
|
||||
* @param query must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private JPQLQuery addOrderByFrom(Sort sort, JPQLQuery query) {
|
||||
private <T> JPQLQuery<T> addOrderByFrom(Sort sort, JPQLQuery<T> query) {
|
||||
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
Assert.notNull(query, "Query must not be null!");
|
||||
@@ -180,9 +179,9 @@ public class Querydsl {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private OrderSpecifier<?> toOrderSpecifier(Order order) {
|
||||
|
||||
return new OrderSpecifier(order.isAscending() ? com.mysema.query.types.Order.ASC
|
||||
: com.mysema.query.types.Order.DESC, buildOrderPropertyPathFrom(order),
|
||||
toQueryDslNullHandling(order.getNullHandling()));
|
||||
return new OrderSpecifier(
|
||||
order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC,
|
||||
buildOrderPropertyPathFrom(order), toQueryDslNullHandling(order.getNullHandling()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,7 @@ import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
|
||||
/**
|
||||
* Integratio test for lock support.
|
||||
* Integration test for lock support.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,8 @@ import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
* Demonstrates the support for composite primary keys with {@code @EmbeddedId}.
|
||||
@@ -32,10 +32,9 @@ import com.mysema.query.types.Predicate;
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface EmployeeRepositoryWithEmbeddedId extends
|
||||
JpaRepository<EmbeddedIdExampleEmployee, EmbeddedIdExampleEmployeePK>,
|
||||
public interface EmployeeRepositoryWithEmbeddedId
|
||||
extends JpaRepository<EmbeddedIdExampleEmployee, EmbeddedIdExampleEmployeePK>,
|
||||
QueryDslPredicateExecutor<EmbeddedIdExampleEmployee> {
|
||||
|
||||
List<EmbeddedIdExampleEmployee> findAll(Predicate predicate, OrderSpecifier<?>... orders);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,8 @@ import org.springframework.data.jpa.domain.sample.IdClassExampleEmployeePK;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
* Demonstrates the support for composite primary keys with {@code @IdClass}.
|
||||
@@ -36,5 +36,4 @@ public interface EmployeeRepositoryWithIdClass extends JpaRepository<IdClassExam
|
||||
QueryDslPredicateExecutor<IdClassExampleEmployee> {
|
||||
|
||||
List<IdClassExampleEmployee> findAll(Predicate predicate, OrderSpecifier<?>... orders);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,13 +21,14 @@ import org.springframework.data.jpa.domain.sample.MailMessage;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public interface MailMessageRepository extends JpaRepository<MailMessage, Long>, QueryDslPredicateExecutor<MailMessage> {
|
||||
public interface MailMessageRepository
|
||||
extends JpaRepository<MailMessage, Long>, QueryDslPredicateExecutor<MailMessage> {
|
||||
|
||||
List<MailMessage> findAll(Predicate predicate, OrderSpecifier<?>... orders);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2014 the original author or authors.
|
||||
* Copyright 2008-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.jpa.repository.QueryHints;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
* Typing interface for {@code Role}.
|
||||
|
||||
@@ -43,10 +43,10 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.expr.BooleanExpression;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.mysema.query.types.path.PathBuilderFactory;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.core.types.dsl.PathBuilderFactory;
|
||||
|
||||
/**
|
||||
* Integration test for {@link QueryDslJpaRepository}.
|
||||
@@ -151,8 +151,8 @@ public class QueryDslJpaRepositoryTests {
|
||||
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(
|
||||
Sort.Direction.ASC, "colleagues.firstname")));
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(),
|
||||
new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "colleagues.firstname")));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent(), hasItems(oliver, dave, carter));
|
||||
@@ -169,8 +169,8 @@ public class QueryDslJpaRepositoryTests {
|
||||
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(
|
||||
Sort.Direction.ASC, "manager.firstname")));
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(),
|
||||
new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "manager.firstname")));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent(), hasItems(dave, oliver, carter));
|
||||
@@ -184,8 +184,8 @@ public class QueryDslJpaRepositoryTests {
|
||||
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(
|
||||
Sort.Direction.ASC, "firstname")));
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(),
|
||||
new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "firstname")));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent(), hasItems(carter, dave, oliver));
|
||||
@@ -199,8 +199,8 @@ public class QueryDslJpaRepositoryTests {
|
||||
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(new Order(
|
||||
Sort.Direction.ASC, "firstname").ignoreCase())));
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(),
|
||||
new PageRequest(0, 10, new Sort(new Order(Sort.Direction.ASC, "firstname").ignoreCase())));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent(), hasItems(carter, dave, oliver));
|
||||
@@ -216,8 +216,8 @@ public class QueryDslJpaRepositoryTests {
|
||||
|
||||
QUser user = QUser.user;
|
||||
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(
|
||||
Sort.Direction.ASC, "address.streetName")));
|
||||
Page<User> page = repository.findAll(user.firstname.isNotNull(),
|
||||
new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "address.streetName")));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent(), hasItems(dave, carter, oliver));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -138,17 +138,14 @@ public class QueryDslRepositorySupportTests {
|
||||
}
|
||||
|
||||
public List<User> findUsersByLastname(String lastname) {
|
||||
|
||||
return from(user).where(user.lastname.eq(lastname)).list(user);
|
||||
return from(user).where(user.lastname.eq(lastname)).fetch();
|
||||
}
|
||||
|
||||
public long updateLastnamesTo(String lastname) {
|
||||
|
||||
return update(user).set(user.lastname, lastname).execute();
|
||||
}
|
||||
|
||||
public long deleteAllWithLastname(String lastname) {
|
||||
|
||||
return delete(user).where(user.lastname.eq(lastname)).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.mysema.query.jpa.JPQLQuery;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link Querydsl}.
|
||||
@@ -47,14 +47,14 @@ public class QuerydslIntegrationTests {
|
||||
|
||||
Querydsl querydsl;
|
||||
PathBuilder<User> userPath;
|
||||
JPQLQuery userQuery;
|
||||
JPQLQuery<User> userQuery;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
userPath = new PathBuilder<User>(User.class, "user");
|
||||
querydsl = new Querydsl(em, userPath);
|
||||
userQuery = querydsl.createQuery().from(userPath);
|
||||
userQuery = querydsl.createQuery().select(userPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class QuerydslIntegrationTests {
|
||||
@Test
|
||||
public void defaultOrderingShouldNotGenerateAnNullOrderingHint() {
|
||||
|
||||
JPQLQuery result = querydsl.applySorting(new Sort(new Sort.Order("firstname")), userQuery);
|
||||
JPQLQuery<User> result = querydsl.applySorting(new Sort(new Sort.Order("firstname")), userQuery);
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.toString(), is(not(anyOf(containsString("nulls first"), containsString("nulls last")))));
|
||||
|
||||
@@ -7,7 +7,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Export-Template:
|
||||
org.springframework.data.jpa.*;version="${project.version}"
|
||||
Import-Template:
|
||||
com.mysema.query.*;version="${querydsl:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
com.querydsl.*;version="${querydsl:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
javax.persistence.*;version="${jpa:[=.=.=,+1.0.0)}",
|
||||
javax.annotation.*;version="0.0.0",
|
||||
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
|
||||
Reference in New Issue
Block a user