Skip to content

Commit 9dce117

Browse files
committed
DATAMONGO-1238 - Upgraded to Querydsl 4.
1 parent e66e1e0 commit 9dce117

File tree

12 files changed

+85
-104
lines changed

12 files changed

+85
-104
lines changed

spring-data-mongodb/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
</dependency>
6060

6161
<dependency>
62-
<groupId>com.mysema.querydsl</groupId>
62+
<groupId>com.querydsl</groupId>
6363
<artifactId>querydsl-mongodb</artifactId>
6464
<version>${querydsl}</version>
6565
<optional>true</optional>
6666
</dependency>
6767

6868
<dependency>
69-
<groupId>com.mysema.querydsl</groupId>
69+
<groupId>com.querydsl</groupId>
7070
<artifactId>querydsl-apt</artifactId>
7171
<version>${querydsl}</version>
7272
<scope>provided</scope>
@@ -183,7 +183,7 @@
183183
<version>${apt}</version>
184184
<dependencies>
185185
<dependency>
186-
<groupId>com.mysema.querydsl</groupId>
186+
<groupId>com.querydsl</groupId>
187187
<artifactId>querydsl-apt</artifactId>
188188
<version>${querydsl}</version>
189189
</dependency>

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/MongoAnnotationProcessor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,14 +25,14 @@
2525

2626
import org.springframework.data.mongodb.core.mapping.Document;
2727

28-
import com.mysema.query.annotations.QueryEmbeddable;
29-
import com.mysema.query.annotations.QueryEmbedded;
30-
import com.mysema.query.annotations.QueryEntities;
31-
import com.mysema.query.annotations.QuerySupertype;
32-
import com.mysema.query.annotations.QueryTransient;
33-
import com.mysema.query.apt.AbstractQuerydslProcessor;
34-
import com.mysema.query.apt.Configuration;
35-
import com.mysema.query.apt.DefaultConfiguration;
28+
import com.querydsl.apt.AbstractQuerydslProcessor;
29+
import com.querydsl.apt.Configuration;
30+
import com.querydsl.apt.DefaultConfiguration;
31+
import com.querydsl.core.annotations.QueryEmbeddable;
32+
import com.querydsl.core.annotations.QueryEmbedded;
33+
import com.querydsl.core.annotations.QueryEntities;
34+
import com.querydsl.core.annotations.QuerySupertype;
35+
import com.querydsl.core.annotations.QueryTransient;
3636

3737
/**
3838
* Annotation processor to create Querydsl query types for QueryDsl annotated classes.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QueryDslMongoRepository.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@
3434
import org.springframework.data.repository.core.EntityMetadata;
3535
import org.springframework.util.Assert;
3636

37-
import com.mysema.query.mongodb.MongodbQuery;
38-
import com.mysema.query.types.EntityPath;
39-
import com.mysema.query.types.Expression;
40-
import com.mysema.query.types.OrderSpecifier;
41-
import com.mysema.query.types.Predicate;
42-
import com.mysema.query.types.path.PathBuilder;
37+
import com.querydsl.core.types.EntityPath;
38+
import com.querydsl.core.types.Expression;
39+
import com.querydsl.core.types.OrderSpecifier;
40+
import com.querydsl.core.types.Predicate;
41+
import com.querydsl.core.types.dsl.PathBuilder;
42+
import com.querydsl.mongodb.AbstractMongodbQuery;
4343

4444
/**
4545
* Special QueryDsl based repository implementation that allows execution {@link Predicate}s in various forms.
4646
*
4747
* @author Oliver Gierke
4848
* @author Thomas Darimont
4949
*/
50-
public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID> implements
51-
QueryDslPredicateExecutor<T> {
50+
public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID>
51+
implements QueryDslPredicateExecutor<T> {
5252

5353
private final PathBuilder<T> builder;
5454
private final EntityInformation<T, ID> entityInformation;
@@ -92,7 +92,7 @@ public QueryDslMongoRepository(MongoEntityInformation<T, ID> entityInformation,
9292
*/
9393
@Override
9494
public T findOne(Predicate predicate) {
95-
return createQueryFor(predicate).uniqueResult();
95+
return createQueryFor(predicate).fetchOne();
9696
}
9797

9898
/*
@@ -101,7 +101,7 @@ public T findOne(Predicate predicate) {
101101
*/
102102
@Override
103103
public List<T> findAll(Predicate predicate) {
104-
return createQueryFor(predicate).list();
104+
return createQueryFor(predicate).fetchResults().getResults();
105105
}
106106

107107
/*
@@ -110,7 +110,7 @@ public List<T> findAll(Predicate predicate) {
110110
*/
111111
@Override
112112
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
113-
return createQueryFor(predicate).orderBy(orders).list();
113+
return createQueryFor(predicate).orderBy(orders).fetchResults().getResults();
114114
}
115115

116116
/*
@@ -119,7 +119,7 @@ public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
119119
*/
120120
@Override
121121
public List<T> findAll(Predicate predicate, Sort sort) {
122-
return applySorting(createQueryFor(predicate), sort).list();
122+
return applySorting(createQueryFor(predicate), sort).fetchResults().getResults();
123123
}
124124

125125
/*
@@ -128,7 +128,7 @@ public List<T> findAll(Predicate predicate, Sort sort) {
128128
*/
129129
@Override
130130
public Iterable<T> findAll(OrderSpecifier<?>... orders) {
131-
return createQuery().orderBy(orders).list();
131+
return createQuery().orderBy(orders).fetchResults().getResults();
132132
}
133133

134134
/*
@@ -138,10 +138,11 @@ public Iterable<T> findAll(OrderSpecifier<?>... orders) {
138138
@Override
139139
public Page<T> findAll(Predicate predicate, Pageable pageable) {
140140

141-
MongodbQuery<T> countQuery = createQueryFor(predicate);
142-
MongodbQuery<T> query = createQueryFor(predicate);
141+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> countQuery = createQueryFor(predicate);
142+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQueryFor(predicate);
143143

144-
return new PageImpl<T>(applyPagination(query, pageable).list(), pageable, countQuery.count());
144+
return new PageImpl<T>(applyPagination(query, pageable).fetchResults().getResults(), pageable,
145+
countQuery.fetchCount());
145146
}
146147

147148
/*
@@ -151,10 +152,11 @@ public Page<T> findAll(Predicate predicate, Pageable pageable) {
151152
@Override
152153
public Page<T> findAll(Pageable pageable) {
153154

154-
MongodbQuery<T> countQuery = createQuery();
155-
MongodbQuery<T> query = createQuery();
155+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> countQuery = createQuery();
156+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQuery();
156157

157-
return new PageImpl<T>(applyPagination(query, pageable).list(), pageable, countQuery.count());
158+
return new PageImpl<T>(applyPagination(query, pageable).fetchResults().getResults(), pageable,
159+
countQuery.fetchCount());
158160
}
159161

160162
/*
@@ -163,7 +165,7 @@ public Page<T> findAll(Pageable pageable) {
163165
*/
164166
@Override
165167
public List<T> findAll(Sort sort) {
166-
return applySorting(createQuery(), sort).list();
168+
return applySorting(createQuery(), sort).fetchResults().getResults();
167169
}
168170

169171
/*
@@ -172,7 +174,7 @@ public List<T> findAll(Sort sort) {
172174
*/
173175
@Override
174176
public long count(Predicate predicate) {
175-
return createQueryFor(predicate).count();
177+
return createQueryFor(predicate).fetchCount();
176178
}
177179

178180
/*
@@ -181,7 +183,7 @@ public long count(Predicate predicate) {
181183
*/
182184
@Override
183185
public boolean exists(Predicate predicate) {
184-
return createQueryFor(predicate).exists();
186+
return createQueryFor(predicate).fetchCount() > 0;
185187
}
186188

187189
/**
@@ -190,7 +192,7 @@ public boolean exists(Predicate predicate) {
190192
* @param predicate
191193
* @return
192194
*/
193-
private MongodbQuery<T> createQueryFor(Predicate predicate) {
195+
private AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> createQueryFor(Predicate predicate) {
194196
return createQuery().where(predicate);
195197
}
196198

@@ -199,7 +201,7 @@ private MongodbQuery<T> createQueryFor(Predicate predicate) {
199201
*
200202
* @return
201203
*/
202-
private MongodbQuery<T> createQuery() {
204+
private AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> createQuery() {
203205
return new SpringDataMongodbQuery<T>(mongoOperations, entityInformation.getJavaType());
204206
}
205207

@@ -210,7 +212,8 @@ private MongodbQuery<T> createQuery() {
210212
* @param pageable
211213
* @return
212214
*/
213-
private MongodbQuery<T> applyPagination(MongodbQuery<T> query, Pageable pageable) {
215+
private AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> applyPagination(
216+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query, Pageable pageable) {
214217

215218
if (pageable == null) {
216219
return query;
@@ -227,7 +230,8 @@ private MongodbQuery<T> applyPagination(MongodbQuery<T> query, Pageable pageable
227230
* @param sort
228231
* @return
229232
*/
230-
private MongodbQuery<T> applySorting(MongodbQuery<T> query, Sort sort) {
233+
private AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> applySorting(
234+
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query, Sort sort) {
231235

232236
if (sort == null) {
233237
return query;
@@ -260,7 +264,7 @@ private OrderSpecifier<?> toOrder(Order order) {
260264

261265
Expression<Object> property = builder.get(order.getProperty());
262266

263-
return new OrderSpecifier(order.isAscending() ? com.mysema.query.types.Order.ASC
264-
: com.mysema.query.types.Order.DESC, property);
267+
return new OrderSpecifier(
268+
order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, property);
265269
}
266270
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2012 the original author or authors.
2+
* Copyright 2011-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,8 @@
2020
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
2121
import org.springframework.util.Assert;
2222

23-
import com.mysema.query.mongodb.MongodbQuery;
24-
import com.mysema.query.types.EntityPath;
23+
import com.querydsl.core.types.EntityPath;
24+
import com.querydsl.mongodb.AbstractMongodbQuery;
2525

2626
/**
2727
* Base class to create repository implementations based on Querydsl.
@@ -36,7 +36,7 @@ public abstract class QuerydslRepositorySupport {
3636
/**
3737
* Creates a new {@link QuerydslRepositorySupport} for the given {@link MongoOperations}.
3838
*
39-
* @param operations must not be {@literal null}
39+
* @param operations must not be {@literal null}.
4040
*/
4141
public QuerydslRepositorySupport(MongoOperations operations) {
4242

@@ -53,7 +53,7 @@ public QuerydslRepositorySupport(MongoOperations operations) {
5353
* @param path
5454
* @return
5555
*/
56-
protected <T> MongodbQuery<T> from(final EntityPath<T> path) {
56+
protected <T> AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> from(final EntityPath<T> path) {
5757
Assert.notNull(path);
5858
MongoPersistentEntity<?> entity = context.getPersistentEntity(path.getType());
5959
return from(path, entity.getCollection());
@@ -66,7 +66,7 @@ protected <T> MongodbQuery<T> from(final EntityPath<T> path) {
6666
* @param collection must not be blank or {@literal null}
6767
* @return
6868
*/
69-
protected <T> MongodbQuery<T> from(final EntityPath<T> path, String collection) {
69+
protected <T> AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> from(final EntityPath<T> path, String collection) {
7070

7171
Assert.notNull(path);
7272
Assert.hasText(collection);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SpringDataMongodbQuery.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,14 +20,14 @@
2020
import com.google.common.base.Function;
2121
import com.mongodb.DBCollection;
2222
import com.mongodb.DBObject;
23-
import com.mysema.query.mongodb.MongodbQuery;
23+
import com.querydsl.mongodb.AbstractMongodbQuery;
2424

2525
/**
26-
* Spring Data specfic {@link MongodbQuery} implementation.
26+
* Spring Data specific {@link MongodbQuery} implementation.
2727
*
2828
* @author Oliver Gierke
2929
*/
30-
class SpringDataMongodbQuery<T> extends MongodbQuery<T> {
30+
class SpringDataMongodbQuery<T> extends AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> {
3131

3232
private final MongoOperations operations;
3333

@@ -48,7 +48,8 @@ public SpringDataMongodbQuery(final MongoOperations operations, final Class<? ex
4848
* @param type must not be {@literal null}.
4949
* @param collectionName must not be {@literal null} or empty.
5050
*/
51-
public SpringDataMongodbQuery(final MongoOperations operations, final Class<? extends T> type, String collectionName) {
51+
public SpringDataMongodbQuery(final MongoOperations operations, final Class<? extends T> type,
52+
String collectionName) {
5253

5354
super(operations.getCollection(collectionName), new Function<DBObject, T>() {
5455
public T apply(DBObject input) {
@@ -61,7 +62,7 @@ public T apply(DBObject input) {
6162

6263
/*
6364
* (non-Javadoc)
64-
* @see com.mysema.query.mongodb.MongodbQuery#getCollection(java.lang.Class)
65+
* @see com.querydsl.mongodb.AbstractMongodbQuery#getCollection(java.lang.Class)
6566
*/
6667
@Override
6768
protected DBCollection getCollection(Class<?> type) {

0 commit comments

Comments
 (0)