24
24
import org .springframework .beans .factory .annotation .Autowired ;
25
25
import org .springframework .context .annotation .Bean ;
26
26
import org .springframework .context .annotation .Configuration ;
27
+ import org .springframework .data .domain .Page ;
27
28
import org .springframework .data .domain .PageRequest ;
28
29
import org .springframework .data .domain .Sort ;
29
30
import org .springframework .data .neo4j .config .AbstractNeo4jConfig ;
30
31
import org .springframework .data .neo4j .integration .shared .common .Person ;
31
- // tag::sdn-mixins.dynamic-conditions.add-mixin[]
32
32
import org .springframework .data .neo4j .repository .Neo4jRepository ;
33
- // end::sdn-mixins.dynamic-conditions.add-mixin[]
34
33
import org .springframework .data .neo4j .repository .config .EnableNeo4jRepositories ;
35
34
import org .springframework .data .neo4j .test .Neo4jExtension ;
36
35
import org .springframework .data .neo4j .test .Neo4jIntegrationTest ;
37
- // tag::sdn-mixins.dynamic-conditions.add-mixin[]
38
36
import org .springframework .data .querydsl .QuerydslPredicateExecutor ;
39
-
40
- // end::sdn-mixins.dynamic-conditions.add-mixin[]
41
37
import org .springframework .transaction .annotation .EnableTransactionManagement ;
42
38
43
39
import com .querydsl .core .types .Ops ;
@@ -70,7 +66,8 @@ protected static void setupData() {
70
66
transaction .run ("MATCH (n) detach delete n" );
71
67
transaction .run ("CREATE (p:Person{firstName: 'A', lastName: 'LA'})" );
72
68
transaction .run ("CREATE (p:Person{firstName: 'B', lastName: 'LB'})" );
73
- transaction .run ("CREATE (p:Person{firstName: 'Helge', lastName: 'Schneider'}) -[:LIVES_AT]-> (a:Address {city: 'Mülheim an der Ruhr'})" );
69
+ transaction
70
+ .run ("CREATE (p:Person{firstName: 'Helge', lastName: 'Schneider'}) -[:LIVES_AT]-> (a:Address {city: 'Mülheim an der Ruhr'})" );
74
71
transaction .run ("CREATE (p:Person{firstName: 'Bela', lastName: 'B.'})" );
75
72
transaction .commit ();
76
73
}
@@ -127,13 +124,33 @@ void orderedFindAllWithoutPredicateShouldWork(@Autowired QueryDSLPersonRepositor
127
124
@ Test
128
125
void pagedFindAllShouldWork (@ Autowired QueryDSLPersonRepository repository ) {
129
126
130
- assertThat (
131
- repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
132
- .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
133
- PageRequest .of (1 , 1 , Sort .by ("lastName" ).descending ())
134
- ))
127
+ Page <Person > people = repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
128
+ .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
129
+ PageRequest .of (1 , 1 , Sort .by ("lastName" ).descending ())
130
+ );
131
+
132
+ assertThat (people .hasPrevious ()).isTrue ();
133
+ assertThat (people .hasNext ()).isFalse ();
134
+ assertThat (people .getTotalElements ()).isEqualTo (2 );
135
+ assertThat (people )
135
136
.extracting (Person ::getFirstName )
136
- .containsExactly ("B" );
137
+ .containsExactly ("Bela" );
138
+ }
139
+
140
+ @ Test // GH-2194
141
+ void pagedFindAllShouldWork2 (@ Autowired QueryDSLPersonRepository repository ) {
142
+
143
+ Page <Person > people = repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
144
+ .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
145
+ PageRequest .of (0 , 20 , Sort .by ("lastName" ).descending ())
146
+ );
147
+
148
+ assertThat (people .hasPrevious ()).isFalse ();
149
+ assertThat (people .hasNext ()).isFalse ();
150
+ assertThat (people .getTotalElements ()).isEqualTo (2 );
151
+ assertThat (people )
152
+ .extracting (Person ::getFirstName )
153
+ .containsExactly ("Helge" , "Bela" );
137
154
}
138
155
139
156
@ Test
@@ -160,7 +177,6 @@ interface QueryDSLPersonRepository extends
160
177
}
161
178
// end::sdn-mixins.dynamic-conditions.add-mixin[]
162
179
163
-
164
180
@ Configuration
165
181
@ EnableTransactionManagement
166
182
@ EnableNeo4jRepositories (considerNestedRepositories = true )
0 commit comments