16
16
package org .springframework .data .neo4j .repository .query ;
17
17
18
18
import static org .neo4j .cypherdsl .core .Cypher .property ;
19
- import static org .neo4j .cypherdsl .core .Cypher .raw ;
20
19
21
20
import java .util .Collection ;
22
21
import java .util .HashMap ;
35
34
import org .neo4j .cypherdsl .core .SortItem ;
36
35
import org .neo4j .cypherdsl .core .StatementBuilder ;
37
36
import org .neo4j .cypherdsl .core .SymbolicName ;
38
- import org .neo4j .cypherdsl .core .internal .SchemaNames ;
39
37
import org .neo4j .driver .Value ;
40
38
import org .springframework .data .domain .KeysetScrollPosition ;
41
39
import org .springframework .data .domain .Pageable ;
@@ -66,21 +64,25 @@ public static Function<Sort.Order, SortItem> sortAdapterFor(NodeDescription<?> n
66
64
return order -> {
67
65
68
66
String domainProperty = order .getProperty ();
69
- String rawDomainProperty = order .getProperty ();
70
- boolean propertyIsQualified = domainProperty .contains ("." );
67
+ boolean propertyIsQualifiedOrComposite = domainProperty .contains ("." );
71
68
SymbolicName root ;
72
- if (!propertyIsQualified ) {
69
+ if (!propertyIsQualifiedOrComposite ) {
73
70
root = Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription );
74
71
} else {
75
- int indexOfSeparator = domainProperty .indexOf ("." );
76
- root = Cypher .name (domainProperty .substring (0 , indexOfSeparator ));
77
- domainProperty = domainProperty .substring (indexOfSeparator + 1 );
72
+ // need to check first if this is really a qualified name or the "qualifier" is a composite property
73
+ if (nodeDescription .getGraphProperty (domainProperty .split ("\\ ." )[0 ]).isEmpty ()) {
74
+ int indexOfSeparator = domainProperty .indexOf ("." );
75
+ root = Cypher .name (domainProperty .substring (0 , indexOfSeparator ));
76
+ domainProperty = domainProperty .substring (indexOfSeparator + 1 );
77
+ } else {
78
+ root = Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription );
79
+ }
78
80
}
79
81
80
82
var optionalGraphProperty = nodeDescription .getGraphProperty (domainProperty );
81
83
// try to resolve if this is a composite property
82
84
if (optionalGraphProperty .isEmpty ()) {
83
- var domainPropertyPrefix = rawDomainProperty .split ("\\ ." )[0 ];
85
+ var domainPropertyPrefix = domainProperty .split ("\\ ." )[0 ];
84
86
optionalGraphProperty = nodeDescription .getGraphProperty (domainPropertyPrefix );
85
87
}
86
88
if (optionalGraphProperty .isEmpty ()) {
@@ -91,10 +93,10 @@ public static Function<Sort.Order, SortItem> sortAdapterFor(NodeDescription<?> n
91
93
if (graphProperty .isInternalIdProperty ()) {
92
94
// Not using the id expression here, as the root will be referring to the constructed map being returned.
93
95
expression = property (root , Constants .NAME_OF_INTERNAL_ID );
94
- } else if (graphProperty .isComposite () && !rawDomainProperty .contains ("." )) {
95
- throw new IllegalStateException (String .format ("Cannot order by composite property: '%s'. Only ordering by its nested fields is allowed." , rawDomainProperty ));
96
+ } else if (graphProperty .isComposite () && !domainProperty .contains ("." )) {
97
+ throw new IllegalStateException (String .format ("Cannot order by composite property: '%s'. Only ordering by its nested fields is allowed." , domainProperty ));
96
98
} else if (graphProperty .isComposite ()) {
97
- expression = property (root , rawDomainProperty );
99
+ expression = property (root , domainProperty );
98
100
} else {
99
101
expression = property (root , graphProperty .getPropertyName ());
100
102
if (order .isIgnoreCase ()) {
0 commit comments