22
22
import static org .springframework .data .couchbase .core .query .QueryCriteria .where ;
23
23
24
24
import java .util .Iterator ;
25
+ import java .util .Optional ;
25
26
26
27
import org .springframework .core .convert .converter .Converter ;
27
28
import org .springframework .data .couchbase .core .convert .CouchbaseConverter ;
28
29
import org .springframework .data .couchbase .core .mapping .CouchbasePersistentProperty ;
29
30
import org .springframework .data .couchbase .core .query .N1QLExpression ;
30
31
import org .springframework .data .couchbase .core .query .Query ;
31
32
import org .springframework .data .couchbase .core .query .QueryCriteria ;
33
+ import org .springframework .data .domain .Pageable ;
32
34
import org .springframework .data .domain .Sort ;
33
35
import org .springframework .data .mapping .PersistentPropertyPath ;
34
36
import org .springframework .data .mapping .context .MappingContext ;
37
39
import org .springframework .data .repository .query .parser .AbstractQueryCreator ;
38
40
import org .springframework .data .repository .query .parser .Part ;
39
41
import org .springframework .data .repository .query .parser .PartTree ;
42
+ import org .springframework .util .Assert ;
40
43
41
44
/**
42
45
* @author Michael Nitschinger
@@ -72,12 +75,24 @@ protected QueryCriteria create(final Part part, final Iterator<Object> iterator)
72
75
return from (part , property , where (addMetaIfRequired (bucketName , path , property )), iterator );
73
76
}
74
77
78
+ @ Override
79
+ public Query createQuery () {
80
+ Query q = this .createQuery ((Optional .of (this .accessor ).map (ParameterAccessor ::getSort ).orElse (Sort .unsorted ())));
81
+ Pageable pageable = accessor .getPageable ();
82
+ if (pageable .isPaged ()) {
83
+ q .skip (pageable .getOffset ());
84
+ q .limit (pageable .getPageSize ());
85
+ }
86
+ return q ;
87
+ }
88
+
75
89
static Converter <? super CouchbasePersistentProperty , String > cvtr = new MyConverter ();
76
90
77
91
static class MyConverter implements Converter <CouchbasePersistentProperty , String > {
78
92
@ Override
79
93
public String convert (CouchbasePersistentProperty source ) {
80
- return new StringBuilder (source .getFieldName ().length ()+2 ).append ("`" ).append (source .getFieldName ()).append ("`" ).toString ();
94
+ return new StringBuilder (source .getFieldName ().length () + 2 ).append ("`" ).append (source .getFieldName ()).append ("`" )
95
+ .toString ();
81
96
}
82
97
}
83
98
@@ -90,7 +105,7 @@ protected QueryCriteria and(final Part part, final QueryCriteria base, final Ite
90
105
PersistentPropertyPath <CouchbasePersistentProperty > path = context .getPersistentPropertyPath (part .getProperty ());
91
106
CouchbasePersistentProperty property = path .getLeafProperty ();
92
107
93
- return from (part , property , base .and (addMetaIfRequired (bucketName ,path , property )), iterator );
108
+ return from (part , property , base .and (addMetaIfRequired (bucketName , path , property )), iterator );
94
109
}
95
110
96
111
@ Override
@@ -100,7 +115,8 @@ protected QueryCriteria or(QueryCriteria base, QueryCriteria criteria) {
100
115
101
116
@ Override
102
117
protected Query complete (QueryCriteria criteria , Sort sort ) {
103
- return (criteria == null ? new Query () : new Query ().addCriteria (criteria )).with (sort );
118
+ Query q = (criteria == null ? new Query () : new Query ().addCriteria (criteria )).with (sort );
119
+ return q ;
104
120
}
105
121
106
122
private QueryCriteria from (final Part part , final CouchbasePersistentProperty property , final QueryCriteria criteria ,
@@ -166,8 +182,7 @@ private QueryCriteria from(final Part part, final CouchbasePersistentProperty pr
166
182
}
167
183
}
168
184
169
- public static N1QLExpression addMetaIfRequired (
170
- String bucketName ,
185
+ public static N1QLExpression addMetaIfRequired (String bucketName ,
171
186
final PersistentPropertyPath <CouchbasePersistentProperty > persistentPropertyPath ,
172
187
final CouchbasePersistentProperty property ) {
173
188
if (property .isIdProperty ()) {
0 commit comments