42
42
import org .apiguardian .api .API ;
43
43
import org .neo4j .cypherdsl .core .Condition ;
44
44
import org .neo4j .cypherdsl .core .Cypher ;
45
+ import org .neo4j .cypherdsl .core .FunctionInvocation ;
45
46
import org .neo4j .cypherdsl .core .Functions ;
47
+ import org .neo4j .cypherdsl .core .Named ;
46
48
import org .neo4j .cypherdsl .core .Node ;
47
49
import org .neo4j .cypherdsl .core .Statement ;
48
50
import org .neo4j .cypherdsl .core .renderer .Configuration ;
85
87
import org .springframework .data .neo4j .core .mapping .NodeDescription ;
86
88
import org .springframework .data .neo4j .core .mapping .PropertyFilter ;
87
89
import org .springframework .data .neo4j .core .mapping .RelationshipDescription ;
90
+ import org .springframework .data .neo4j .core .mapping .SpringDataCypherDsl ;
88
91
import org .springframework .data .neo4j .core .mapping .callback .EventSupport ;
89
92
import org .springframework .data .neo4j .core .schema .TargetNode ;
90
93
import org .springframework .data .neo4j .repository .NoResultException ;
@@ -129,6 +132,8 @@ public final class Neo4jTemplate implements
129
132
130
133
private Renderer renderer ;
131
134
135
+ private Function <Named , FunctionInvocation > elementIdOrIdFunction ;
136
+
132
137
public Neo4jTemplate (Neo4jClient neo4jClient ) {
133
138
this (neo4jClient , new Neo4jMappingContext ());
134
139
}
@@ -148,6 +153,7 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
148
153
this .cypherGenerator = CypherGenerator .INSTANCE ;
149
154
this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
150
155
this .renderer = Renderer .getDefaultRenderer ();
156
+ this .elementIdOrIdFunction = SpringDataCypherDsl .elementIdOrIdFunction .apply (null );
151
157
}
152
158
153
159
ProjectionFactory getProjectionFactory () {
@@ -517,7 +523,7 @@ class Tuple3<T> {
517
523
.query (() -> renderer .render (cypherGenerator .prepareSaveOfMultipleInstancesOf (entityMetaData )))
518
524
.bind (entityList ).to (Constants .NAME_OF_ENTITY_LIST_PARAM )
519
525
.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 ))))
521
527
.all ()
522
528
.stream ()
523
529
.collect (Collectors .toMap (m -> (Value ) m .getKey (), m -> (String ) m .getValue ()));
@@ -746,7 +752,7 @@ private <T> T processNestedRelations(
746
752
idProperty = null ;
747
753
} else {
748
754
Neo4jPersistentEntity <?> relationshipPropertiesEntity = (Neo4jPersistentEntity <?>) relationshipDescription .getRelationshipPropertiesEntity ();
749
- idProperty = relationshipPropertiesEntity .getIdProperty ();
755
+ idProperty = relationshipPropertiesEntity .getIdProperty ();
750
756
}
751
757
752
758
// break recursive procession and deletion of previously created relationships
@@ -1023,6 +1029,8 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
1023
1029
.getBeanProvider (Configuration .class )
1024
1030
.getIfAvailable (Configuration ::defaultConfig );
1025
1031
this .renderer = Renderer .getRenderer (cypherDslConfiguration );
1032
+ this .elementIdOrIdFunction = SpringDataCypherDsl .elementIdOrIdFunction .apply (cypherDslConfiguration .getDialect ());
1033
+ this .cypherGenerator .setElementIdOrIdFunction (elementIdOrIdFunction );
1026
1034
}
1027
1035
1028
1036
// only used for the CDI configuration
@@ -1178,7 +1186,7 @@ private NodesAndRelationshipsByIdStatementProvider createNodesAndRelationshipsBy
1178
1186
.bindAll (usedParameters )
1179
1187
.fetchAs (Value .class ).mappedBy ((t , r ) -> r .get (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ))
1180
1188
.one ()
1181
- .map (value -> value .asList (Value :: asString ))
1189
+ .map (value -> value .asList (TemplateSupport :: convertIdOrElementIdToString ))
1182
1190
.get ());
1183
1191
1184
1192
if (rootNodeIds .isEmpty ()) {
@@ -1204,7 +1212,7 @@ private NodesAndRelationshipsByIdStatementProvider createNodesAndRelationshipsBy
1204
1212
.ifPresent (iterateAndMapNextLevel (relationshipIds , relatedNodeIds , relationshipDescription , PropertyPathWalkStep .empty ()));
1205
1213
}
1206
1214
1207
- return new NodesAndRelationshipsByIdStatementProvider (rootNodeIds , relationshipIds , relatedNodeIds , queryFragments );
1215
+ return new NodesAndRelationshipsByIdStatementProvider (rootNodeIds , relationshipIds , relatedNodeIds , queryFragments , elementIdOrIdFunction );
1208
1216
}
1209
1217
1210
1218
private void iterateNextLevel (Collection <String > nodeIds , RelationshipDescription sourceRelationshipDescription , Set <String > relationshipIds ,
@@ -1235,11 +1243,11 @@ private void iterateNextLevel(Collection<String> nodeIds, RelationshipDescriptio
1235
1243
1236
1244
Statement statement = cypherGenerator
1237
1245
.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 )))
1239
1247
.returning (cypherGenerator .createGenericReturnStatement ()).build ();
1240
1248
1241
1249
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 ) ))
1243
1251
.fetch ()
1244
1252
.one ()
1245
1253
.ifPresent (iterateAndMapNextLevel (relationshipIds , relatedNodeIds , relationshipDescription , nextPathStep ));
@@ -1254,11 +1262,11 @@ private Consumer<Map<String, Object>> iterateAndMapNextLevel(Set<String> relatio
1254
1262
1255
1263
return record -> {
1256
1264
@ 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 ( );
1258
1266
relationshipIds .addAll (newRelationshipIds );
1259
1267
1260
1268
@ 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 ( );
1262
1270
1263
1271
Set <String > relatedIds = new HashSet <>(newRelatedNodeIds );
1264
1272
// use this list to get down the road
0 commit comments