1616package org .springframework .data .neo4j .core .mapping ;
1717
1818import static org .neo4j .cypherdsl .core .Cypher .anyNode ;
19+ import static org .neo4j .cypherdsl .core .Cypher .coalesce ;
20+ import static org .neo4j .cypherdsl .core .Cypher .collect ;
1921import static org .neo4j .cypherdsl .core .Cypher .listBasedOn ;
2022import static org .neo4j .cypherdsl .core .Cypher .literalOf ;
2123import static org .neo4j .cypherdsl .core .Cypher .match ;
2224import static org .neo4j .cypherdsl .core .Cypher .node ;
2325import static org .neo4j .cypherdsl .core .Cypher .optionalMatch ;
2426import static org .neo4j .cypherdsl .core .Cypher .parameter ;
25- import static org .neo4j .cypherdsl .core .Functions .coalesce ;
2627
2728import java .util .ArrayList ;
2829import java .util .Arrays ;
3940
4041import org .apiguardian .api .API ;
4142import org .neo4j .cypherdsl .core .Condition ;
42- import org .neo4j .cypherdsl .core .Conditions ;
4343import org .neo4j .cypherdsl .core .Cypher ;
4444import org .neo4j .cypherdsl .core .Expression ;
4545import org .neo4j .cypherdsl .core .FunctionInvocation ;
46- import org .neo4j .cypherdsl .core .Functions ;
4746import org .neo4j .cypherdsl .core .IdentifiableElement ;
4847import org .neo4j .cypherdsl .core .MapProjection ;
4948import org .neo4j .cypherdsl .core .Named ;
@@ -87,9 +86,9 @@ public enum CypherGenerator {
8786 // default elementId function
8887 private Function <Named , FunctionInvocation > elementIdOrIdFunction = named -> {
8988 if (named instanceof Node node ) {
90- return Functions .elementId (node );
89+ return Cypher .elementId (node );
9190 } else if (named instanceof Relationship relationship ) {
92- return Functions .elementId (relationship );
91+ return Cypher .elementId (relationship );
9392 } else {
9493 throw new IllegalArgumentException ("Unsupported CypherDSL type: " + named .getClass ());
9594 }
@@ -140,7 +139,8 @@ public StatementBuilder.OrderableOngoingReadingAndWith prepareMatchOf(NodeDescri
140139 List <IdentifiableElement > expressions = new ArrayList <>();
141140 expressions .add (rootNode .getRequiredSymbolicName ());
142141 if (nodeDescription instanceof Neo4jPersistentEntity <?> entity && entity .isUsingDeprecatedInternalId ()) {
143- expressions .add (Functions .id (rootNode ).as (Constants .NAME_OF_INTERNAL_ID ));
142+ //noinspection deprecation
143+ expressions .add (rootNode .internalId ().as (Constants .NAME_OF_INTERNAL_ID ));
144144 }
145145 expressions .add (elementIdOrIdFunction .apply (rootNode ).as (Constants .NAME_OF_ELEMENT_ID ));
146146
@@ -155,7 +155,7 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
155155 StatementBuilder .OngoingReadingWithoutWhere match = prepareMatchOfRootNode (rootNode , initialMatchOn );
156156
157157 List <IdentifiableElement > expressions = new ArrayList <>();
158- expressions .add (Functions .collect (elementIdOrIdFunction .apply (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
158+ expressions .add (Cypher .collect (elementIdOrIdFunction .apply (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
159159
160160 return match
161161 .where (conditionOrNoCondition (condition ))
@@ -192,9 +192,9 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
192192
193193 relationship = relationship .named (Constants .NAME_OF_SYNTHESIZED_RELATIONS );
194194 List <IdentifiableElement > expressions = new ArrayList <>();
195- expressions .add (Functions .collect (elementIdOrIdFunction .apply (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
196- expressions .add (Functions .collect (elementIdOrIdFunction .apply (targetNode )).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ));
197- expressions .add (Functions .collect (elementIdOrIdFunction .apply (relationship )).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ));
195+ expressions .add (Cypher .collect (elementIdOrIdFunction .apply (rootNode )).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ));
196+ expressions .add (Cypher .collect (elementIdOrIdFunction .apply (targetNode )).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ));
197+ expressions .add (Cypher .collect (elementIdOrIdFunction .apply (relationship )).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ));
198198
199199 return match
200200 .where (conditionOrNoCondition (condition ))
@@ -251,14 +251,14 @@ public Statement createStatementReturningDynamicLabels(NodeDescription<?> nodeDe
251251 versionCondition = rootNode .property (versionProperty .getName ())
252252 .isEqualTo (coalesce (parameter (Constants .NAME_OF_VERSION_PARAM ), literalOf (0 )));
253253 } else {
254- versionCondition = Conditions .noCondition ();
254+ versionCondition = Cypher .noCondition ();
255255 }
256256
257257 return match (rootNode )
258258 .where (idDescription .asIdExpression ().isEqualTo (parameter (Constants .NAME_OF_ID )))
259259 .and (versionCondition ).unwind (rootNode .labels ()).as ("label" ).with (Cypher .name ("label" ))
260260 .where (Cypher .name ("label" ).in (parameter (Constants .NAME_OF_STATIC_LABELS_PARAM )).not ())
261- .returning (Functions . collect (Cypher .name ("label" )).as (Constants .NAME_OF_LABELS )).build ();
261+ .returning (collect (Cypher .name ("label" )).as (Constants .NAME_OF_LABELS )).build ();
262262 }
263263
264264 public Statement prepareDeleteOf (NodeDescription <?> nodeDescription ) {
@@ -276,7 +276,7 @@ public Statement prepareDeleteOf(NodeDescription<?> nodeDescription, @Nullable C
276276 .named (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription ));
277277 OngoingUpdate ongoingUpdate = match (rootNode ).where (conditionOrNoCondition (condition )).detachDelete (rootNode );
278278 if (count ) {
279- return ongoingUpdate .returning (Functions .count (rootNode )).build ();
279+ return ongoingUpdate .returning (Cypher .count (rootNode )).build ();
280280 }
281281 return ongoingUpdate .build ();
282282 }
@@ -289,7 +289,7 @@ public Condition createCompositePropertyCondition(GraphPropertyDescription idPro
289289
290290 Neo4jPersistentProperty property = (Neo4jPersistentProperty ) idProperty ;
291291
292- Condition result = Conditions .noCondition ();
292+ Condition result = Cypher .noCondition ();
293293 for (String key : property .getOptionalConverter ().write (null ).keys ()) {
294294 Property expression = Cypher .property (containerName , key );
295295 result = result .and (expression .isEqualTo (actualParameter .property (key )));
@@ -420,7 +420,7 @@ public Statement prepareSaveOfMultipleInstancesOf(NodeDescription<?> nodeDescrip
420420
421421 List <Expression > expressions = new ArrayList <>();
422422 if (nodeDescription instanceof Neo4jPersistentEntity <?> entity && entity .isUsingDeprecatedInternalId ()) {
423- Functions . id ( rootNode ).as (Constants .NAME_OF_INTERNAL_ID );
423+ rootNode . internalId ( ).as (Constants .NAME_OF_INTERNAL_ID );
424424 }
425425 expressions .add (elementIdOrIdFunction .apply (rootNode ).as (Constants .NAME_OF_ELEMENT_ID ));
426426 expressions .add (rootNode .property (nameOfIdProperty ).as (Constants .NAME_OF_ID ));
@@ -465,9 +465,9 @@ private static Function<Node, Expression> getNodeIdFunction(@Nullable Neo4jPersi
465465 var idProperty = entity .getRequiredIdProperty ();
466466 if (entity .isUsingInternalIds ()) {
467467 if (entity .isUsingDeprecatedInternalId () || !canUseElementId ) {
468- startNodeIdFunction = Functions :: id ;
468+ startNodeIdFunction = Node :: internalId ;
469469 } else {
470- startNodeIdFunction = Functions ::elementId ;
470+ startNodeIdFunction = Cypher ::elementId ;
471471 }
472472 } else {
473473 startNodeIdFunction = node -> node .property (idProperty .getPropertyName ());
@@ -479,25 +479,29 @@ private static Function<Node, Expression> getEndNodeIdFunction(@Nullable Neo4jPe
479479
480480 Function <Node , Expression > startNodeIdFunction ;
481481 if (entity == null ) {
482- return Functions ::elementId ;
482+ return Cypher ::elementId ;
483483 }
484484 if (!entity .isUsingDeprecatedInternalId () && canUseElementId ) {
485- startNodeIdFunction = Functions ::elementId ;
485+ startNodeIdFunction = Cypher ::elementId ;
486486 } else {
487- startNodeIdFunction = Functions :: id ;
487+ startNodeIdFunction = Node :: internalId ;
488488 }
489489 return startNodeIdFunction ;
490490 }
491491
492+ static Expression relId (Relationship r ) {
493+ return FunctionInvocation .create (() -> "id" , r .getRequiredSymbolicName ());
494+ }
495+
492496 private static Function <Relationship , Expression > getRelationshipIdFunction (RelationshipDescription relationshipDescription , boolean canUseElementId ) {
493497
494- Function <Relationship , Expression > result = canUseElementId ? Functions ::elementId : Functions :: id ;
498+ Function <Relationship , Expression > result = canUseElementId ? Cypher ::elementId : CypherGenerator :: relId ;
495499 if (relationshipDescription .hasRelationshipProperties ()) {
496500 Neo4jPersistentEntity <?> entity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
497501 if ((entity != null && entity .isUsingDeprecatedInternalId ()) || !canUseElementId ) {
498- result = Functions :: id ;
502+ result = CypherGenerator :: relId ;
499503 } else {
500- result = Functions ::elementId ;
504+ result = Cypher ::elementId ;
501505 }
502506 }
503507 return result ;
@@ -623,7 +627,7 @@ public Statement prepareUpdateOfRelationshipsWithProperties(Neo4jPersistentEntit
623627 private List <Expression > getReturnedIdExpressionsForRelationship (RelationshipDescription relationship , Relationship relationshipFragment ) {
624628 List <Expression > result = new ArrayList <>();
625629 if (relationship .hasRelationshipProperties () && relationship .getRelationshipPropertiesEntity () instanceof Neo4jPersistentEntity <?> entity && entity .isUsingDeprecatedInternalId ()) {
626- result .add (Functions . id (relationshipFragment ).as (Constants .NAME_OF_INTERNAL_ID ));
630+ result .add (relId (relationshipFragment ).as (Constants .NAME_OF_INTERNAL_ID ));
627631 }
628632 result .add (elementIdOrIdFunction .apply (relationshipFragment ).as (Constants .NAME_OF_ELEMENT_ID ));
629633 return result ;
@@ -661,7 +665,7 @@ public Statement prepareDeleteOf(
661665
662666 public Collection <Expression > createReturnStatementForExists (Neo4jPersistentEntity <?> nodeDescription ) {
663667
664- return Collections .singleton (Functions .count (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription )));
668+ return Collections .singleton (Cypher .count (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription )));
665669 }
666670
667671 public Collection <Expression > createReturnStatementForMatch (Neo4jPersistentEntity <?> nodeDescription ) {
@@ -711,7 +715,7 @@ public Collection<Expression> createReturnStatementForMatch(Neo4jPersistentEntit
711715 }
712716 }
713717 if (order .isIgnoreCase ()) {
714- expression = Functions .toLower (expression );
718+ expression = Cypher .toLower (expression );
715719 }
716720 return order .isAscending () ? expression .ascending () : expression .descending ();
717721 }).toArray (SortItem []::new ))
@@ -804,10 +808,11 @@ private List<Object> projectNodeProperties(PropertyFilter.RelaxedPropertyPath pa
804808 }
805809
806810 nodePropertiesProjection .add (Constants .NAME_OF_LABELS );
807- nodePropertiesProjection .add (Functions .labels (node ));
811+ nodePropertiesProjection .add (Cypher .labels (node ));
808812 if (nodeDescription instanceof Neo4jPersistentEntity <?> entity && entity .isUsingDeprecatedInternalId ()) {
809813 nodePropertiesProjection .add (Constants .NAME_OF_INTERNAL_ID );
810- nodePropertiesProjection .add (Functions .id (node ));
814+ //noinspection deprecation
815+ nodePropertiesProjection .add (node .internalId ());
811816 }
812817 nodePropertiesProjection .add (Constants .NAME_OF_ELEMENT_ID );
813818 nodePropertiesProjection .add (elementIdOrIdFunction .apply (node ));
@@ -876,7 +881,7 @@ private void generateListFor(PropertyFilter.RelaxedPropertyPath parentPath, Neo4
876881
877882 addMapProjection (relationshipTargetName ,
878883 listBasedOn (relationship ).returning (mapProjection
879- .and (RelationshipDescription .NAME_OF_RELATIONSHIP_TYPE , Functions .type (relationship ))),
884+ .and (RelationshipDescription .NAME_OF_RELATIONSHIP_TYPE , Cypher .type (relationship ))),
880885 mapProjectionLists );
881886
882887 } else {
@@ -902,6 +907,6 @@ private void addMapProjection(String name, Object projection, List<Object> proje
902907 }
903908
904909 private static Condition conditionOrNoCondition (@ Nullable Condition condition ) {
905- return condition == null ? Conditions .noCondition () : condition ;
910+ return condition == null ? Cypher .noCondition () : condition ;
906911 }
907912}
0 commit comments