17
17
18
18
import static org .neo4j .cypherdsl .core .Cypher .parameter ;
19
19
20
+ import java .util .ArrayList ;
20
21
import java .util .Collection ;
21
22
import java .util .Collections ;
23
+ import java .util .List ;
22
24
import java .util .Map ;
23
25
24
26
import org .apiguardian .api .API ;
25
27
import org .neo4j .cypherdsl .core .Condition ;
26
28
import org .neo4j .cypherdsl .core .Conditions ;
29
+ import org .neo4j .cypherdsl .core .Cypher ;
30
+ import org .neo4j .cypherdsl .core .Node ;
27
31
import org .neo4j .cypherdsl .core .SortItem ;
28
32
import org .springframework .data .domain .Example ;
29
33
import org .springframework .data .domain .Pageable ;
@@ -94,9 +98,16 @@ public void setParameters(Map<String, Object> newParameters) {
94
98
public static QueryFragmentsAndParameters forFindById (Neo4jPersistentEntity <?> entityMetaData , Object idValues ) {
95
99
Map <String , Object > parameters = Collections .singletonMap (Constants .NAME_OF_ID , idValues );
96
100
97
- Condition condition = entityMetaData .getIdExpression ().isEqualTo (parameter (Constants .NAME_OF_ID ));
101
+ Node container = cypherGenerator .createRootNode (entityMetaData );
102
+ Condition condition ;
103
+ if (entityMetaData .getIdProperty ().isComposite ()) {
104
+ condition = CypherGenerator .INSTANCE .createCompositePropertyCondition (entityMetaData .getIdProperty (), container .getRequiredSymbolicName (), parameter (Constants .NAME_OF_ID ));
105
+ } else {
106
+ condition = entityMetaData .getIdExpression ().isEqualTo (parameter (Constants .NAME_OF_ID ));
107
+ }
108
+
98
109
QueryFragments queryFragments = new QueryFragments ();
99
- queryFragments .addMatchOn (cypherGenerator . createRootNode ( entityMetaData ) );
110
+ queryFragments .addMatchOn (container );
100
111
queryFragments .setCondition (condition );
101
112
queryFragments .setReturnExpressions (cypherGenerator .createReturnStatementForMatch (entityMetaData ));
102
113
return new QueryFragmentsAndParameters (entityMetaData , queryFragments , parameters );
@@ -105,9 +116,21 @@ public static QueryFragmentsAndParameters forFindById(Neo4jPersistentEntity<?> e
105
116
public static QueryFragmentsAndParameters forFindByAllId (Neo4jPersistentEntity <?> entityMetaData , Object idValues ) {
106
117
Map <String , Object > parameters = Collections .singletonMap (Constants .NAME_OF_IDS , idValues );
107
118
108
- Condition condition = entityMetaData .getIdExpression ().in ((parameter (Constants .NAME_OF_IDS )));
119
+ Node container = cypherGenerator .createRootNode (entityMetaData );
120
+ Condition condition ;
121
+ if (entityMetaData .getIdProperty ().isComposite ()) {
122
+ List <Object > args = new ArrayList <>();
123
+ for (String key : entityMetaData .getIdProperty ().getOptionalConverter ().write (null ).keys ()) {
124
+ args .add (key );
125
+ args .add (container .property (key ));
126
+ }
127
+ condition = Cypher .mapOf (args .toArray ()).in (parameter (Constants .NAME_OF_IDS ));
128
+ } else {
129
+ condition = entityMetaData .getIdExpression ().in (parameter (Constants .NAME_OF_IDS ));
130
+ }
131
+
109
132
QueryFragments queryFragments = new QueryFragments ();
110
- queryFragments .addMatchOn (cypherGenerator . createRootNode ( entityMetaData ) );
133
+ queryFragments .addMatchOn (container );
111
134
queryFragments .setCondition (condition );
112
135
queryFragments .setReturnExpressions (cypherGenerator .createReturnStatementForMatch (entityMetaData ));
113
136
return new QueryFragmentsAndParameters (entityMetaData , queryFragments , parameters );
@@ -124,9 +147,16 @@ public static QueryFragmentsAndParameters forFindAll(Neo4jPersistentEntity<?> en
124
147
public static QueryFragmentsAndParameters forExistsById (Neo4jPersistentEntity <?> entityMetaData , Object idValues ) {
125
148
Map <String , Object > parameters = Collections .singletonMap (Constants .NAME_OF_ID , idValues );
126
149
127
- Condition condition = entityMetaData .getIdExpression ().isEqualTo (parameter (Constants .NAME_OF_ID ));
150
+ Node container = cypherGenerator .createRootNode (entityMetaData );
151
+ Condition condition ;
152
+ if (entityMetaData .getIdProperty ().isComposite ()) {
153
+ condition = CypherGenerator .INSTANCE .createCompositePropertyCondition (entityMetaData .getIdProperty (), container .getRequiredSymbolicName (), parameter (Constants .NAME_OF_ID ));
154
+ } else {
155
+ condition = entityMetaData .getIdExpression ().isEqualTo (parameter (Constants .NAME_OF_ID ));
156
+ }
157
+
128
158
QueryFragments queryFragments = new QueryFragments ();
129
- queryFragments .addMatchOn (cypherGenerator . createRootNode ( entityMetaData ) );
159
+ queryFragments .addMatchOn (container );
130
160
queryFragments .setCondition (condition );
131
161
queryFragments .setReturnExpressions (cypherGenerator .createReturnStatementForExists (entityMetaData ));
132
162
return new QueryFragmentsAndParameters (entityMetaData , queryFragments , parameters );
0 commit comments