34
34
import java .util .function .UnaryOperator ;
35
35
import java .util .regex .Pattern ;
36
36
37
+ import javax .lang .model .SourceVersion ;
38
+
37
39
import org .apiguardian .api .API ;
38
40
import org .neo4j .cypherdsl .core .Condition ;
39
41
import org .neo4j .cypherdsl .core .Conditions ;
40
42
import org .neo4j .cypherdsl .core .Cypher ;
41
43
import org .neo4j .cypherdsl .core .Expression ;
42
44
import org .neo4j .cypherdsl .core .FunctionInvocation ;
43
45
import org .neo4j .cypherdsl .core .Functions ;
46
+ import org .neo4j .cypherdsl .core .IdentifiableElement ;
44
47
import org .neo4j .cypherdsl .core .MapProjection ;
45
48
import org .neo4j .cypherdsl .core .Node ;
46
49
import org .neo4j .cypherdsl .core .Parameter ;
55
58
import org .neo4j .cypherdsl .core .SymbolicName ;
56
59
import org .neo4j .cypherdsl .core .renderer .Configuration ;
57
60
import org .neo4j .cypherdsl .core .renderer .Renderer ;
61
+ import org .neo4j .cypherdsl .core .utils .Assertions ;
58
62
import org .springframework .data .domain .Sort ;
59
63
import org .springframework .data .mapping .MappingException ;
60
64
import org .springframework .data .mapping .PersistentProperty ;
@@ -111,12 +115,12 @@ public StatementBuilder.OrderableOngoingReadingAndWith prepareMatchOf(NodeDescri
111
115
112
116
Node rootNode = createRootNode (nodeDescription );
113
117
114
- List <Expression > expressions = new ArrayList <>();
118
+ List <IdentifiableElement > expressions = new ArrayList <>();
115
119
expressions .add (rootNode .getRequiredSymbolicName ());
116
120
expressions .add (Functions .id (rootNode ).as (Constants .NAME_OF_INTERNAL_ID ));
117
121
expressions .add (Functions .elementId (rootNode ).as (Constants .NAME_OF_ELEMENT_ID ));
118
122
119
- return match (rootNode ).where (conditionOrNoCondition (condition )).with (expressions .toArray (new Expression [] {} ));
123
+ return match (rootNode ).where (conditionOrNoCondition (condition )).with (expressions .toArray (IdentifiableElement []:: new ));
120
124
}
121
125
122
126
public StatementBuilder .OngoingReading prepareMatchOf (NodeDescription <?> nodeDescription ,
@@ -126,12 +130,12 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
126
130
127
131
StatementBuilder .OngoingReadingWithoutWhere match = prepareMatchOfRootNode (rootNode , initialMatchOn );
128
132
129
- List <Expression > expressions = new ArrayList <>();
133
+ List <IdentifiableElement > expressions = new ArrayList <>();
130
134
expressions .add (Functions .collect (Functions .id (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
131
135
132
136
return match
133
137
.where (conditionOrNoCondition (condition ))
134
- .with (expressions .toArray (new Expression []{} ));
138
+ .with (expressions .toArray (IdentifiableElement []:: new ));
135
139
}
136
140
137
141
public StatementBuilder .OngoingReading prepareMatchOf (NodeDescription <?> nodeDescription ,
@@ -163,15 +167,15 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
163
167
};
164
168
165
169
relationship = relationship .named (Constants .NAME_OF_SYNTHESIZED_RELATIONS );
166
- List <Expression > expressions = new ArrayList <>();
170
+ List <IdentifiableElement > expressions = new ArrayList <>();
167
171
expressions .add (Functions .collect (Functions .id (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
168
172
expressions .add (Functions .collect (Functions .id (targetNode )).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ));
169
173
expressions .add (Functions .collect (Functions .id (relationship )).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ));
170
174
171
175
return match
172
176
.where (conditionOrNoCondition (condition ))
173
177
.optionalMatch (relationship )
174
- .with (expressions .toArray (new Expression []{} ));
178
+ .with (expressions .toArray (IdentifiableElement []:: new ));
175
179
}
176
180
177
181
@ NonNull
@@ -619,6 +623,7 @@ public Collection<Expression> createReturnStatementForMatch(Neo4jPersistentEntit
619
623
expression = Cypher .property (property .substring (0 , firstDot ), tail );
620
624
} else {
621
625
try {
626
+ Assertions .isTrue (SourceVersion .isIdentifier (property ), "Name must be a valid identifier." );
622
627
expression = Cypher .name (property );
623
628
} catch (IllegalArgumentException e ) {
624
629
if (e .getMessage ().endsWith ("." )) {
0 commit comments