Skip to content

Commit d0013f1

Browse files
GH-2274 - Apply toLower also for SpEL based order.
1 parent 3fe54d1 commit d0013f1

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java

+19-16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
*/
1616
package org.springframework.data.neo4j.core.mapping;
1717

18+
import static org.neo4j.cypherdsl.core.Cypher.anyNode;
19+
import static org.neo4j.cypherdsl.core.Cypher.listBasedOn;
20+
import static org.neo4j.cypherdsl.core.Cypher.literalOf;
21+
import static org.neo4j.cypherdsl.core.Cypher.match;
22+
import static org.neo4j.cypherdsl.core.Cypher.node;
23+
import static org.neo4j.cypherdsl.core.Cypher.optionalMatch;
24+
import static org.neo4j.cypherdsl.core.Cypher.parameter;
25+
import static org.neo4j.cypherdsl.core.Functions.coalesce;
26+
27+
import java.util.ArrayList;
28+
import java.util.Arrays;
29+
import java.util.Collection;
30+
import java.util.List;
31+
import java.util.function.Predicate;
32+
import java.util.function.UnaryOperator;
33+
1834
import org.apiguardian.api.API;
1935
import org.neo4j.cypherdsl.core.Condition;
2036
import org.neo4j.cypherdsl.core.Conditions;
@@ -41,22 +57,6 @@
4157
import org.springframework.lang.Nullable;
4258
import org.springframework.util.Assert;
4359

44-
import java.util.ArrayList;
45-
import java.util.Arrays;
46-
import java.util.Collection;
47-
import java.util.List;
48-
import java.util.function.Predicate;
49-
import java.util.function.UnaryOperator;
50-
51-
import static org.neo4j.cypherdsl.core.Cypher.anyNode;
52-
import static org.neo4j.cypherdsl.core.Cypher.listBasedOn;
53-
import static org.neo4j.cypherdsl.core.Cypher.literalOf;
54-
import static org.neo4j.cypherdsl.core.Cypher.match;
55-
import static org.neo4j.cypherdsl.core.Cypher.node;
56-
import static org.neo4j.cypherdsl.core.Cypher.optionalMatch;
57-
import static org.neo4j.cypherdsl.core.Cypher.parameter;
58-
import static org.neo4j.cypherdsl.core.Functions.coalesce;
59-
6060
/**
6161
* A generator based on the schema defined by node and relationship descriptions. Most methods return renderable Cypher
6262
* statements.
@@ -482,6 +482,9 @@ public Expression[] createReturnStatementForMatch(NodeDescription<?> nodeDescrip
482482
} else {
483483
expression = Cypher.name(property);
484484
}
485+
if (order.isIgnoreCase()) {
486+
expression = Functions.toLower(expression);
487+
}
485488
return order.isAscending() ? expression.ascending() : expression.descending();
486489
}).toArray(SortItem[]::new))
487490
.build();

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

+17
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,23 @@ void findAllWithSortWithCaseIgnored(@Autowired PersonRepository repository) {
374374
.containsExactly("aa", "Ab", "Test", "Test2");
375375
}
376376

377+
@Test // GH-2274
378+
void findAllWithSortWithCaseIgnoredSpelBased(@Autowired PersonRepository repository) {
379+
380+
doWithSession(session ->
381+
session.writeTransaction(tx -> {
382+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'Ab', firstName: 'n/a'})");
383+
tx.run("CREATE (n:PersonWithAllConstructor {name: 'aa', firstName: 'n/a'})");
384+
return null;
385+
}));
386+
387+
List<PersonWithAllConstructor> persons = repository
388+
.orderBySpel(PageRequest.of(0, 10, Sort.by(Sort.Order.asc("n.name").ignoreCase())));
389+
assertThat(persons)
390+
.extracting(PersonWithAllConstructor::getName)
391+
.containsExactly("aa", "Ab", "Test", "Test2");
392+
}
393+
377394
@Test
378395
void findAllWithPageable(@Autowired PersonRepository repository) {
379396

src/test/java/org/springframework/data/neo4j/integration/imperative/repositories/PersonRepository.java

+3
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,7 @@ public DtoPersonProjectionContainingAdditionalFields getBySomeLongValue(long val
310310

311311
@Query("CREATE (n:PersonWithAllConstructor) SET n+= $testNode.__properties__ RETURN n")
312312
PersonWithAllConstructor createWithCustomQuery(@Param("testNode") PersonWithAllConstructor testNode);
313+
314+
@Query(value = "MATCH (n:PersonWithAllConstructor) RETURN n :#{ orderBy (#pageable.sort)} SKIP $skip LIMIT $limit")
315+
List<PersonWithAllConstructor> orderBySpel(Pageable page);
313316
}

0 commit comments

Comments
 (0)