4242import org .apiguardian .api .API ;
4343import org .neo4j .cypherdsl .core .Condition ;
4444import org .neo4j .cypherdsl .core .Cypher ;
45+ import org .neo4j .cypherdsl .core .FunctionInvocation ;
4546import org .neo4j .cypherdsl .core .Functions ;
47+ import org .neo4j .cypherdsl .core .Named ;
4648import org .neo4j .cypherdsl .core .Node ;
4749import org .neo4j .cypherdsl .core .Statement ;
4850import org .neo4j .cypherdsl .core .renderer .Configuration ;
8587import org .springframework .data .neo4j .core .mapping .NodeDescription ;
8688import org .springframework .data .neo4j .core .mapping .PropertyFilter ;
8789import org .springframework .data .neo4j .core .mapping .RelationshipDescription ;
90+ import org .springframework .data .neo4j .core .mapping .SpringDataCypherDsl ;
8891import org .springframework .data .neo4j .core .mapping .callback .EventSupport ;
8992import org .springframework .data .neo4j .core .schema .TargetNode ;
9093import org .springframework .data .neo4j .repository .NoResultException ;
@@ -129,6 +132,8 @@ public final class Neo4jTemplate implements
129132
130133 private Renderer renderer ;
131134
135+ private Function <Named , FunctionInvocation > elementIdOrIdFunction ;
136+
132137 public Neo4jTemplate (Neo4jClient neo4jClient ) {
133138 this (neo4jClient , new Neo4jMappingContext ());
134139 }
@@ -148,6 +153,7 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
148153 this .cypherGenerator = CypherGenerator .INSTANCE ;
149154 this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
150155 this .renderer = Renderer .getDefaultRenderer ();
156+ this .elementIdOrIdFunction = SpringDataCypherDsl .elementIdOrIdFunction .apply (null );
151157 }
152158
153159 ProjectionFactory getProjectionFactory () {
@@ -517,7 +523,7 @@ class Tuple3<T> {
517523 .query (() -> renderer .render (cypherGenerator .prepareSaveOfMultipleInstancesOf (entityMetaData )))
518524 .bind (entityList ).to (Constants .NAME_OF_ENTITY_LIST_PARAM )
519525 .fetchAs (Map .Entry .class )
520- .mappedBy ((t , r ) -> new AbstractMap .SimpleEntry <>(r .get (Constants .NAME_OF_ID ), r .get (Constants .NAME_OF_ELEMENT_ID ). asString ( )))
526+ .mappedBy ((t , r ) -> new AbstractMap .SimpleEntry <>(r .get (Constants .NAME_OF_ID ), TemplateSupport . convertIdOrElementIdToString ( r .get (Constants .NAME_OF_ELEMENT_ID ))))
521527 .all ()
522528 .stream ()
523529 .collect (Collectors .toMap (m -> (Value ) m .getKey (), m -> (String ) m .getValue ()));
@@ -746,7 +752,7 @@ private <T> T processNestedRelations(
746752 idProperty = null ;
747753 } else {
748754 Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
749- idProperty = relationshipPropertiesEntity .getIdProperty ();
755+ idProperty = relationshipPropertiesEntity .getIdProperty ();
750756 }
751757
752758 // break recursive procession and deletion of previously created relationships
@@ -1023,6 +1029,8 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
10231029 .getBeanProvider (Configuration .class )
10241030 .getIfAvailable (Configuration ::defaultConfig );
10251031 this .renderer = Renderer .getRenderer (cypherDslConfiguration );
1032+ this .elementIdOrIdFunction = SpringDataCypherDsl .elementIdOrIdFunction .apply (cypherDslConfiguration .getDialect ());
1033+ this .cypherGenerator .setElementIdOrIdFunction (elementIdOrIdFunction );
10261034 }
10271035
10281036 // only used for the CDI configuration
@@ -1178,7 +1186,7 @@ private NodesAndRelationshipsByIdStatementProvider createNodesAndRelationshipsBy
11781186 .bindAll (usedParameters )
11791187 .fetchAs (Value .class ).mappedBy ((t , r ) -> r .get (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ))
11801188 .one ()
1181- .map (value -> value .asList (Value :: asString ))
1189+ .map (value -> value .asList (TemplateSupport :: convertIdOrElementIdToString ))
11821190 .get ());
11831191
11841192 if (rootNodeIds .isEmpty ()) {
@@ -1204,7 +1212,7 @@ private NodesAndRelationshipsByIdStatementProvider createNodesAndRelationshipsBy
12041212 .ifPresent (iterateAndMapNextLevel (relationshipIds , relatedNodeIds , relationshipDescription , PropertyPathWalkStep .empty ()));
12051213 }
12061214
1207- return new NodesAndRelationshipsByIdStatementProvider (rootNodeIds , relationshipIds , relatedNodeIds , queryFragments );
1215+ return new NodesAndRelationshipsByIdStatementProvider (rootNodeIds , relationshipIds , relatedNodeIds , queryFragments , elementIdOrIdFunction );
12081216 }
12091217
12101218 private void iterateNextLevel (Collection <String > nodeIds , RelationshipDescription sourceRelationshipDescription , Set <String > relationshipIds ,
@@ -1235,11 +1243,11 @@ private void iterateNextLevel(Collection<String> nodeIds, RelationshipDescriptio
12351243
12361244 Statement statement = cypherGenerator
12371245 .prepareMatchOf (target , relationshipDescription , null ,
1238- Functions . elementId (node ).in (Cypher .parameter (Constants .NAME_OF_IDS )))
1246+ elementIdOrIdFunction . apply (node ).in (Cypher .parameter (Constants .NAME_OF_IDS )))
12391247 .returning (cypherGenerator .createGenericReturnStatement ()).build ();
12401248
12411249 neo4jClient .query (renderer .render (statement ))
1242- .bindAll (Collections .singletonMap (Constants .NAME_OF_IDS , nodeIds ))
1250+ .bindAll (Collections .singletonMap (Constants .NAME_OF_IDS , TemplateSupport . convertToLongIdOrStringElementId ( nodeIds ) ))
12431251 .fetch ()
12441252 .one ()
12451253 .ifPresent (iterateAndMapNextLevel (relationshipIds , relatedNodeIds , relationshipDescription , nextPathStep ));
@@ -1254,11 +1262,11 @@ private Consumer<Map<String, Object>> iterateAndMapNextLevel(Set<String> relatio
12541262
12551263 return record -> {
12561264 @ SuppressWarnings ("unchecked" )
1257- List <String > newRelationshipIds = (List <String >) record .get (Constants .NAME_OF_SYNTHESIZED_RELATIONS );
1265+ List <String > newRelationshipIds = (( List <Object >) record .get (Constants .NAME_OF_SYNTHESIZED_RELATIONS )). stream (). map ( TemplateSupport :: convertIdOrElementIdToString ). toList ( );
12581266 relationshipIds .addAll (newRelationshipIds );
12591267
12601268 @ SuppressWarnings ("unchecked" )
1261- List <String > newRelatedNodeIds = (List <String >) record .get (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES );
1269+ List <String > newRelatedNodeIds = (( List <Object >) record .get (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES )). stream (). map ( TemplateSupport :: convertIdOrElementIdToString ). toList ( );
12621270
12631271 Set <String > relatedIds = new HashSet <>(newRelatedNodeIds );
12641272 // use this list to get down the road
0 commit comments