Skip to content

Commit 44185a4

Browse files
committed
GH-2341 - Use domainClassName as root node name.
Original pull request: #2341
1 parent 868096e commit 44185a4

File tree

18 files changed

+99
-82
lines changed

18 files changed

+99
-82
lines changed

src/main/java/org/springframework/data/neo4j/core/DynamicLabels.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.neo4j.cypherdsl.core.Node;
2626
import org.neo4j.cypherdsl.core.StatementBuilder.OngoingMatchAndUpdate;
2727
import org.springframework.data.neo4j.core.mapping.Constants;
28+
import org.springframework.data.neo4j.core.mapping.NodeDescription;
29+
import org.springframework.lang.Nullable;
2830

2931
/**
3032
* Decorator for an ongoing update statement that removes obsolete dynamic labels and adds new ones.
@@ -33,16 +35,17 @@
3335
*/
3436
final class DynamicLabels implements UnaryOperator<OngoingMatchAndUpdate> {
3537

36-
public static final DynamicLabels EMPTY = new DynamicLabels(Collections.emptyList(), Collections.emptyList());
38+
public static final DynamicLabels EMPTY = new DynamicLabels(null, Collections.emptyList(), Collections.emptyList());
3739

38-
private static final Node rootNode = Cypher.anyNode(Constants.NAME_OF_ROOT_NODE);
40+
private final Node rootNode;
3941

4042
private final List<String> oldLabels;
4143
private final List<String> newLabels;
4244

43-
DynamicLabels(Collection<String> oldLabels, Collection<String> newLabels) {
45+
DynamicLabels(@Nullable NodeDescription<?> nodeDescription, Collection<String> oldLabels, Collection<String> newLabels) {
4446
this.oldLabels = new ArrayList<>(oldLabels);
4547
this.newLabels = new ArrayList<>(newLabels);
48+
this.rootNode = Cypher.anyNode(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
4649
}
4750

4851
@Override

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ private <T> DynamicLabels determineDynamicLabels(T entityToBeSaved, Neo4jPersist
413413
}
414414

415415
Optional<Map<String, Object>> optionalResult = runnableQuery.fetch().one();
416-
return new DynamicLabels(optionalResult.map(r -> (Collection<String>) r.get(Constants.NAME_OF_LABELS))
416+
return new DynamicLabels(entityMetaData, optionalResult.map(r -> (Collection<String>) r.get(Constants.NAME_OF_LABELS))
417417
.orElseGet(Collections::emptyList), (Collection<String>) propertyAccessor.getProperty(p));
418418
}).orElse(DynamicLabels.EMPTY);
419419
}
@@ -545,12 +545,12 @@ public <T> void deleteByIdWithVersion(Object id, Class<T> domainType, Neo4jPersi
545545

546546
String nameOfParameter = "id";
547547
Condition condition = entityMetaData.getIdExpression().isEqualTo(parameter(nameOfParameter))
548-
.and(Cypher.property(Constants.NAME_OF_ROOT_NODE, versionProperty.getPropertyName())
548+
.and(Cypher.property(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData), versionProperty.getPropertyName())
549549
.isEqualTo(parameter(Constants.NAME_OF_VERSION_PARAM))
550-
.or(Cypher.property(Constants.NAME_OF_ROOT_NODE, versionProperty.getPropertyName()).isNull()));
550+
.or(Cypher.property(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData), versionProperty.getPropertyName()).isNull()));
551551

552552
Statement statement = cypherGenerator.prepareMatchOf(entityMetaData, condition)
553-
.returning(Constants.NAME_OF_ROOT_NODE).build();
553+
.returning(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData)).build();
554554

555555
Map<String, Object> parameters = new HashMap<>();
556556
parameters.put(nameOfParameter, convertIdValues(entityMetaData.getRequiredIdProperty(), id));
@@ -971,7 +971,7 @@ private Optional<Neo4jClient.RecordFetchSpec<T>> createFetchSpec() {
971971
if (nodesAndRelationshipsById.hasRootNodeIds()) {
972972
return Optional.empty();
973973
}
974-
cypherQuery = renderer.render(nodesAndRelationshipsById.toStatement());
974+
cypherQuery = renderer.render(nodesAndRelationshipsById.toStatement(entityMetaData));
975975
finalParameters = nodesAndRelationshipsById.getParameters();
976976
} else {
977977
Statement statement = queryFragments.toStatement();
@@ -1036,7 +1036,7 @@ private void iterateNextLevel(Collection<Long> nodeIds, Neo4jPersistentEntity<?>
10361036
Collection<RelationshipDescription> relationships = target.getRelationshipsInHierarchy(preparedQuery.getQueryFragmentsAndParameters().getQueryFragments()::includeField);
10371037
for (RelationshipDescription relationshipDescription : relationships) {
10381038

1039-
Node node = anyNode(Constants.NAME_OF_ROOT_NODE);
1039+
Node node = anyNode(Constants.NAME_OF_TYPED_ROOT_NODE.apply(target));
10401040

10411041
Statement statement = cypherGenerator
10421042
.prepareMatchOf(target, relationshipDescription, null,

src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private <T> Mono<Tuple2<T, DynamicLabels>> determineDynamicLabels(T entityToBeSa
422422
return runnableQuery.fetch().one().map(m -> (Collection<String>) m.get(Constants.NAME_OF_LABELS))
423423
.switchIfEmpty(Mono.just(Collections.emptyList()))
424424
.zipWith(Mono.just((Collection<String>) propertyAccessor.getProperty(p)))
425-
.map(t -> Tuples.of(entityToBeSaved, new DynamicLabels(t.getT1(), t.getT2())));
425+
.map(t -> Tuples.of(entityToBeSaved, new DynamicLabels(entityMetaData, t.getT1(), t.getT2())));
426426
}).orElse(Mono.just(Tuples.of(entityToBeSaved, DynamicLabels.EMPTY)));
427427
}
428428

@@ -548,12 +548,12 @@ public <T> Mono<Void> deleteByIdWithVersion(Object id, Class<T> domainType, Neo4
548548
String nameOfParameter = "id";
549549
Neo4jPersistentEntity<?> entityMetaData = neo4jMappingContext.getPersistentEntity(domainType);
550550
Condition condition = entityMetaData.getIdExpression().isEqualTo(parameter(nameOfParameter))
551-
.and(Cypher.property(Constants.NAME_OF_ROOT_NODE, versionProperty.getPropertyName())
551+
.and(Cypher.property(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData), versionProperty.getPropertyName())
552552
.isEqualTo(parameter(Constants.NAME_OF_VERSION_PARAM))
553-
.or(Cypher.property(Constants.NAME_OF_ROOT_NODE, versionProperty.getPropertyName()).isNull()));
553+
.or(Cypher.property(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData), versionProperty.getPropertyName()).isNull()));
554554

555555
Statement statement = cypherGenerator.prepareMatchOf(entityMetaData, condition)
556-
.returning(Constants.NAME_OF_ROOT_NODE).build();
556+
.returning(Constants.NAME_OF_TYPED_ROOT_NODE.apply(entityMetaData)).build();
557557

558558
Map<String, Object> parameters = new HashMap<>();
559559
parameters.put(nameOfParameter, convertIdValues(entityMetaData.getRequiredIdProperty(), id));
@@ -612,7 +612,7 @@ private <T> Mono<ExecutableQuery<T>> createExecutableQuery(Class<T> domainType,
612612
if (containsPossibleCircles && !queryFragments.isScalarValueReturn()) {
613613
return createNodesAndRelationshipsByIdStatementProvider(entityMetaData, queryFragments, queryFragmentsAndParameters.getParameters())
614614
.flatMap(finalQueryAndParameters ->
615-
createExecutableQuery(domainType, resultType, renderer.render(finalQueryAndParameters.toStatement()),
615+
createExecutableQuery(domainType, resultType, renderer.render(finalQueryAndParameters.toStatement(entityMetaData)),
616616
finalQueryAndParameters.getParameters()));
617617
}
618618

@@ -665,7 +665,7 @@ private Flux<Tuple2<Collection<Long>, Collection<Long>>> iterateNextLevel(Collec
665665

666666
return Flux.fromIterable(target.getRelationshipsInHierarchy(queryFragments::includeField))
667667
.flatMap(relDe -> {
668-
Node node = anyNode(Constants.NAME_OF_ROOT_NODE);
668+
Node node = anyNode(Constants.NAME_OF_TYPED_ROOT_NODE.apply(target));
669669

670670
Statement statement = cypherGenerator
671671
.prepareMatchOf(target, relDe, null,
@@ -995,7 +995,7 @@ public <T> Mono<ExecutableQuery<T>> toExecutableQuery(PreparedQuery<T> preparedQ
995995
return createNodesAndRelationshipsByIdStatementProvider(entityMetaData, queryFragments, finalParameters)
996996
.map(nodesAndRelationshipsById -> {
997997
ReactiveNeo4jClient.MappingSpec<T> mappingSpec = this.neo4jClient.query(renderer.render(
998-
nodesAndRelationshipsById.toStatement()))
998+
nodesAndRelationshipsById.toStatement(entityMetaData)))
999999
.bindAll(nodesAndRelationshipsById.getParameters()).fetchAs(resultType);
10001000

10011001
ReactiveNeo4jClient.RecordFetchSpec<T> fetchSpec = preparedQuery.getOptionalMappingFunction()

src/main/java/org/springframework/data/neo4j/core/TemplateSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ boolean hasRootNodeIds() {
180180
return parameters.get(ROOT_NODE_IDS).isEmpty();
181181
}
182182

183-
Statement toStatement() {
183+
Statement toStatement(NodeDescription<?> nodeDescription) {
184184

185185
String rootNodeIds = "rootNodeIds";
186186
String relationshipIds = "relationshipIds";
@@ -195,12 +195,12 @@ Statement toStatement() {
195195
.optionalMatch(relatedNodes)
196196
.where(Functions.id(relatedNodes).in(Cypher.parameter(relatedNodeIds)))
197197
.with(
198-
rootNodes.as(Constants.NAME_OF_ROOT_NODE.getValue()),
198+
rootNodes.as(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription).getValue()),
199199
Functions.collectDistinct(relationships).as(Constants.NAME_OF_SYNTHESIZED_RELATIONS),
200200
Functions.collectDistinct(relatedNodes).as(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES))
201201
.orderBy(queryFragments.getOrderBy())
202202
.returning(
203-
Constants.NAME_OF_ROOT_NODE.as(Constants.NAME_OF_SYNTHESIZED_ROOT_NODE),
203+
Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription).as(Constants.NAME_OF_SYNTHESIZED_ROOT_NODE),
204204
Cypher.name(Constants.NAME_OF_SYNTHESIZED_RELATIONS),
205205
Cypher.name(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES)
206206
)

src/main/java/org/springframework/data/neo4j/core/mapping/Constants.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.apiguardian.api.API.Status;
2020
import org.neo4j.cypherdsl.core.Cypher;
2121
import org.neo4j.cypherdsl.core.SymbolicName;
22+
import org.springframework.util.StringUtils;
23+
24+
import java.util.function.Function;
2225

2326
/**
2427
* A pool of constants used in our Cypher generation. These constants may change without further notice and are meant
@@ -31,7 +34,12 @@
3134
@API(status = Status.EXPERIMENTAL, since = "6.0")
3235
public final class Constants {
3336

34-
public static final SymbolicName NAME_OF_ROOT_NODE = Cypher.name("n");
37+
public static final Function<NodeDescription<?>, SymbolicName> NAME_OF_TYPED_ROOT_NODE =
38+
(nodeDescription) -> nodeDescription != null
39+
? Cypher.name(StringUtils.uncapitalize(nodeDescription.getUnderlyingClass().getSimpleName()))
40+
: Cypher.name("n");
41+
42+
public static final SymbolicName NAME_OF_ROOT_NODE = NAME_OF_TYPED_ROOT_NODE.apply(null);
3543

3644
public static final String NAME_OF_INTERNAL_ID = "__internalNeo4jId__";
3745
/**
@@ -54,7 +62,6 @@ public final class Constants {
5462
public static final String NAME_OF_ENTITY_LIST_PARAM = "__entities__";
5563
public static final String NAME_OF_KNOWN_RELATIONSHIP_PARAM = "__knownRelationShipId__";
5664
public static final String NAME_OF_KNOWN_RELATIONSHIPS_PARAM = "__knownRelationShipIds__";
57-
public static final String NAME_OF_PATHS = "__paths__";
5865
public static final String NAME_OF_ALL_PROPERTIES = "__allProperties__";
5966

6067
public static final String NAME_OF_SYNTHESIZED_ROOT_NODE = "__sn__";

src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public StatementBuilder.OrderableOngoingReadingAndWith prepareMatchOf(NodeDescri
109109
Node rootNode = createRootNode(nodeDescription);
110110

111111
List<Expression> expressions = new ArrayList<>();
112-
expressions.add(Constants.NAME_OF_ROOT_NODE);
112+
expressions.add(rootNode.getRequiredSymbolicName());
113113
expressions.add(Functions.id(rootNode).as(Constants.NAME_OF_INTERNAL_ID));
114114

115115
return match(rootNode).where(conditionOrNoCondition(condition)).with(expressions.toArray(new Expression[] {}));
@@ -121,7 +121,7 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
121121
String primaryLabel = nodeDescription.getPrimaryLabel();
122122
List<String> additionalLabels = nodeDescription.getAdditionalLabels();
123123

124-
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_ROOT_NODE);
124+
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
125125

126126
StatementBuilder.OngoingReadingWithoutWhere match = null;
127127
if (initialMatchOn == null || initialMatchOn.isEmpty()) {
@@ -150,7 +150,7 @@ public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription<?> nodeDes
150150
String primaryLabel = nodeDescription.getPrimaryLabel();
151151
List<String> additionalLabels = nodeDescription.getAdditionalLabels();
152152

153-
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_ROOT_NODE);
153+
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
154154

155155
StatementBuilder.OngoingReadingWithoutWhere match = null;
156156
if (initialMatchOn == null || initialMatchOn.isEmpty()) {
@@ -210,7 +210,7 @@ public Node createRootNode(NodeDescription<?> nodeDescription) {
210210
String primaryLabel = nodeDescription.getPrimaryLabel();
211211
List<String> additionalLabels = nodeDescription.getAdditionalLabels();
212212

213-
return node(primaryLabel, additionalLabels).named(Constants.NAME_OF_ROOT_NODE);
213+
return node(primaryLabel, additionalLabels).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
214214
}
215215

216216
/**
@@ -223,7 +223,7 @@ public Node createRootNode(NodeDescription<?> nodeDescription) {
223223
*/
224224
public Statement createStatementReturningDynamicLabels(NodeDescription<?> nodeDescription) {
225225

226-
final Node rootNode = Cypher.anyNode(Constants.NAME_OF_ROOT_NODE);
226+
final Node rootNode = Cypher.anyNode(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
227227

228228
Condition versionCondition;
229229
if (((Neo4jPersistentEntity) nodeDescription).hasVersionProperty()) {
@@ -254,7 +254,7 @@ public Statement prepareDeleteOf(NodeDescription<?> nodeDescription, @Nullable C
254254
public Statement prepareDeleteOf(NodeDescription<?> nodeDescription, @Nullable Condition condition, boolean count) {
255255

256256
Node rootNode = node(nodeDescription.getPrimaryLabel(), nodeDescription.getAdditionalLabels())
257-
.named(Constants.NAME_OF_ROOT_NODE);
257+
.named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
258258
OngoingUpdate ongoingUpdate = match(rootNode).where(conditionOrNoCondition(condition)).detachDelete(rootNode);
259259
if (count) {
260260
return ongoingUpdate.returning(Functions.count(rootNode)).build();
@@ -268,7 +268,7 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription,
268268
String primaryLabel = nodeDescription.getPrimaryLabel();
269269
List<String> additionalLabels = nodeDescription.getAdditionalLabels();
270270

271-
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_ROOT_NODE);
271+
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
272272
IdDescription idDescription = nodeDescription.getIdDescription();
273273
Parameter idParameter = parameter(Constants.NAME_OF_ID);
274274

@@ -356,7 +356,7 @@ public Statement prepareSaveOfMultipleInstancesOf(NodeDescription<?> nodeDescrip
356356
"Only entities that use external IDs can be saved in a batch.");
357357

358358
Node rootNode = node(nodeDescription.getPrimaryLabel(), nodeDescription.getAdditionalLabels())
359-
.named(Constants.NAME_OF_ROOT_NODE);
359+
.named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription));
360360
IdDescription idDescription = nodeDescription.getIdDescription();
361361

362362
String nameOfIdProperty = idDescription.getOptionalGraphPropertyName()
@@ -519,7 +519,13 @@ public Collection<Expression> createReturnStatementForMatch(Neo4jPersistentEntit
519519
if (nodeDescription.containsPossibleCircles(includeField)) {
520520
return createGenericReturnStatement();
521521
} else {
522-
return Collections.singleton(projectPropertiesAndRelationships(PropertyFilter.RelaxedPropertyPath.withRootType(nodeDescription.getUnderlyingClass()), nodeDescription, Constants.NAME_OF_ROOT_NODE, includeField, null, processedRelationships));
522+
return Collections.singleton(projectPropertiesAndRelationships(
523+
PropertyFilter.RelaxedPropertyPath.withRootType(nodeDescription.getUnderlyingClass()),
524+
nodeDescription,
525+
Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription),
526+
includeField,
527+
null,
528+
processedRelationships));
523529
}
524530
}
525531

@@ -612,7 +618,7 @@ private List<Object> generateListsFor(PropertyFilter.RelaxedPropertyPath parentP
612618

613619
// if we already processed the other way before, do not try to jump in the infinite loop
614620
// unless it is a root node relationship
615-
if (!nodeName.equals(Constants.NAME_OF_ROOT_NODE) && relationshipDescription.hasRelationshipObverse()
621+
if (relationshipDescription.hasRelationshipObverse()
616622
&& processedRelationships.contains(relationshipDescription.getRelationshipObverse())) {
617623
continue;
618624
}

src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private IdDescription computeIdDescription() {
420420

421421
// Assigned ids
422422
if (generatedValueAnnotation == null) {
423-
return IdDescription.forAssignedIds(propertyName);
423+
return IdDescription.forAssignedIds(Constants.NAME_OF_TYPED_ROOT_NODE.apply(this), propertyName);
424424
}
425425

426426
Class<? extends IdGenerator<?>> idGeneratorClass = generatedValueAnnotation.generatorClass();
@@ -443,11 +443,11 @@ private IdDescription computeIdDescription() {
443443
"Internally generated ids can only be assigned to one of " + VALID_GENERATED_ID_TYPES);
444444
}
445445

446-
return IdDescription.forInternallyGeneratedIds();
446+
return IdDescription.forInternallyGeneratedIds(Constants.NAME_OF_TYPED_ROOT_NODE.apply(this));
447447
}
448448

449449
// Externally generated ids.
450-
return IdDescription.forExternallyGeneratedIds(idGeneratorClass, idGeneratorRef, propertyName);
450+
return IdDescription.forExternallyGeneratedIds(Constants.NAME_OF_TYPED_ROOT_NODE.apply(this), idGeneratorClass, idGeneratorRef, propertyName);
451451
}
452452

453453
@Override

src/main/java/org/springframework/data/neo4j/core/mapping/IdDescription.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.neo4j.cypherdsl.core.Expression;
2323
import org.neo4j.cypherdsl.core.Functions;
2424
import org.neo4j.cypherdsl.core.Node;
25+
import org.neo4j.cypherdsl.core.SymbolicName;
2526
import org.springframework.data.neo4j.core.schema.GeneratedValue;
2627
import org.springframework.data.neo4j.core.schema.IdGenerator;
2728
import org.springframework.data.util.Lazy;
@@ -54,45 +55,48 @@ public final class IdDescription {
5455

5556
private final Lazy<Expression> idExpression;
5657

57-
public static IdDescription forAssignedIds(String graphPropertyName) {
58+
public static IdDescription forAssignedIds(SymbolicName symbolicName, String graphPropertyName) {
5859

5960
Assert.notNull(graphPropertyName, "Graph property name is required.");
60-
return new IdDescription(null, null, graphPropertyName);
61+
return new IdDescription(symbolicName, null, null, graphPropertyName);
6162
}
6263

63-
public static IdDescription forInternallyGeneratedIds() {
64-
return new IdDescription(GeneratedValue.InternalIdGenerator.class, null, null);
64+
public static IdDescription forInternallyGeneratedIds(SymbolicName symbolicName) {
65+
return new IdDescription(symbolicName, GeneratedValue.InternalIdGenerator.class, null, null);
6566
}
6667

67-
public static IdDescription forExternallyGeneratedIds(@Nullable Class<? extends IdGenerator<?>> idGeneratorClass,
68+
public static IdDescription forExternallyGeneratedIds(SymbolicName symbolicName,
69+
@Nullable Class<? extends IdGenerator<?>> idGeneratorClass,
6870
@Nullable String idGeneratorRef, String graphPropertyName) {
6971

7072
Assert.notNull(graphPropertyName, "Graph property name is required.");
7173
try {
7274
Assert.hasText(idGeneratorRef, "Reference to an ID generator has precedence.");
7375

74-
return new IdDescription(null, idGeneratorRef, graphPropertyName);
76+
return new IdDescription(symbolicName, null, idGeneratorRef, graphPropertyName);
7577
} catch (IllegalArgumentException e) {
7678
Assert.notNull(idGeneratorClass, "Class of id generator is required.");
7779
Assert.isTrue(idGeneratorClass != GeneratedValue.InternalIdGenerator.class,
7880
"Cannot use InternalIdGenerator for externally generated ids.");
7981

80-
return new IdDescription(idGeneratorClass, null, graphPropertyName);
82+
return new IdDescription(symbolicName, idGeneratorClass, null, graphPropertyName);
8183
}
8284
}
8385

84-
private IdDescription(@Nullable Class<? extends IdGenerator<?>> idGeneratorClass, @Nullable String idGeneratorRef,
85-
@Nullable String graphPropertyName) {
86+
private IdDescription(SymbolicName symbolicName, @Nullable Class<? extends IdGenerator<?>> idGeneratorClass,
87+
@Nullable String idGeneratorRef, @Nullable String graphPropertyName) {
88+
8689
this.idGeneratorClass = idGeneratorClass;
8790
this.idGeneratorRef = idGeneratorRef != null && idGeneratorRef.isEmpty() ? null : idGeneratorRef;
8891
this.graphPropertyName = graphPropertyName;
92+
8993
this.idExpression = Lazy.of(() -> {
90-
final Node rootNode = Cypher.anyNode(Constants.NAME_OF_ROOT_NODE);
94+
final Node rootNode = Cypher.anyNode(symbolicName);
9195
if (this.isInternallyGeneratedId()) {
9296
return Functions.id(rootNode);
9397
} else {
9498
return this.getOptionalGraphPropertyName()
95-
.map(propertyName -> Cypher.property(Constants.NAME_OF_ROOT_NODE, propertyName)).get();
99+
.map(propertyName -> Cypher.property(symbolicName, propertyName)).get();
96100
}
97101
});
98102
}

0 commit comments

Comments
 (0)