-
Notifications
You must be signed in to change notification settings - Fork 619
Parameterize Node DynamicLabels #3034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,12 @@ final class DynamicLabels implements UnaryOperator<OngoingMatchAndUpdate> { | |
public OngoingMatchAndUpdate apply(OngoingMatchAndUpdate ongoingMatchAndUpdate) { | ||
|
||
OngoingMatchAndUpdate decoratedMatchAndUpdate = ongoingMatchAndUpdate; | ||
|
||
if (oldLabels.equals(newLabels) || oldLabels.isEmpty()) { | ||
// Returning if old label equals new label or old labels are empty, nothing to do here | ||
return decoratedMatchAndUpdate; | ||
} | ||
|
||
if (!oldLabels.isEmpty()) { | ||
decoratedMatchAndUpdate = decoratedMatchAndUpdate.remove(rootNode, oldLabels.toArray(new String[0])); | ||
} | ||
|
@@ -60,4 +66,8 @@ public OngoingMatchAndUpdate apply(OngoingMatchAndUpdate ongoingMatchAndUpdate) | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Parameter names are to be added to |
||
return decoratedMatchAndUpdate; | ||
} | ||
|
||
public List<String> getNewLabels() { | ||
return newLabels; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,6 +303,10 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription, | |
String primaryLabel = nodeDescription.getPrimaryLabel(); | ||
List<String> additionalLabels = nodeDescription.getAdditionalLabels(); | ||
|
||
List<String> additionalLabelsNew = new ArrayList<>(additionalLabels); | ||
additionalLabelsNew.addAll(nodeDescription.getDynamicLabels()); | ||
Node rootNodeWithDynamicLabels = node(primaryLabel, additionalLabelsNew).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still generates a non-parametrized query for |
||
|
||
Node rootNode = node(primaryLabel, additionalLabels).named(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription)); | ||
IdDescription idDescription = nodeDescription.getIdDescription(); | ||
Assert.notNull(idDescription, "Cannot save individual nodes without an id attribute"); | ||
|
@@ -320,9 +324,9 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription, | |
.where(createCompositePropertyCondition(idPropertyDescription, possibleExistingNode.getRequiredSymbolicName(), idParameter)) | ||
.with(possibleExistingNode) | ||
.where(possibleExistingNode.isNull()) | ||
.create(rootNode.withProperties(versionProperty, literalOf(0))) | ||
.with(rootNode) | ||
.mutate(rootNode, parameter(Constants.NAME_OF_PROPERTIES_PARAM))).returning(rootNode) | ||
.create(rootNodeWithDynamicLabels.withProperties(versionProperty, literalOf(0))) | ||
.with(rootNodeWithDynamicLabels) | ||
.mutate(rootNodeWithDynamicLabels, parameter(Constants.NAME_OF_PROPERTIES_PARAM))).returning(rootNodeWithDynamicLabels) | ||
.build(); | ||
|
||
Statement updateIfExists = updateDecorator.apply(match(rootNode) | ||
|
@@ -345,9 +349,9 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription, | |
.where(createCompositePropertyCondition(idPropertyDescription, possibleExistingNode.getRequiredSymbolicName(), idParameter)) | ||
.with(possibleExistingNode) | ||
.where(possibleExistingNode.isNull()) | ||
.create(rootNode) | ||
.with(rootNode) | ||
.mutate(rootNode, parameter(Constants.NAME_OF_PROPERTIES_PARAM))).returning(rootNode) | ||
.create(rootNodeWithDynamicLabels) | ||
.with(rootNodeWithDynamicLabels) | ||
.mutate(rootNodeWithDynamicLabels, parameter(Constants.NAME_OF_PROPERTIES_PARAM))).returning(rootNodeWithDynamicLabels) | ||
.build(); | ||
|
||
Statement updateIfExists = updateDecorator.apply(match(rootNode) | ||
|
@@ -375,10 +379,10 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription, | |
.where(nodeIdFunction.apply(possibleExistingNode).isEqualTo(idParameter)) | ||
.with(possibleExistingNode) | ||
.where(possibleExistingNode.isNull()) | ||
.create(rootNode.withProperties(versionProperty, literalOf(0))) | ||
.with(rootNode) | ||
.mutate(rootNode, parameter(Constants.NAME_OF_PROPERTIES_PARAM))) | ||
.returning(rootNode) | ||
.create(rootNodeWithDynamicLabels.withProperties(versionProperty, literalOf(0))) | ||
.with(rootNodeWithDynamicLabels) | ||
.mutate(rootNodeWithDynamicLabels, parameter(Constants.NAME_OF_PROPERTIES_PARAM))) | ||
.returning(rootNodeWithDynamicLabels) | ||
.build(); | ||
|
||
updateIfExists = updateDecorator.apply(match(rootNode) | ||
|
@@ -393,9 +397,9 @@ public Statement prepareSaveOf(NodeDescription<?> nodeDescription, | |
} else { | ||
createIfNew = updateDecorator | ||
.apply(optionalMatch(possibleExistingNode).where(nodeIdFunction.apply(possibleExistingNode).isEqualTo(idParameter)) | ||
.with(possibleExistingNode).where(possibleExistingNode.isNull()).create(rootNode) | ||
.set(rootNode, parameter(Constants.NAME_OF_PROPERTIES_PARAM))) | ||
.returning(rootNode).build(); | ||
.with(possibleExistingNode).where(possibleExistingNode.isNull()).create(rootNodeWithDynamicLabels) | ||
.set(rootNodeWithDynamicLabels, parameter(Constants.NAME_OF_PROPERTIES_PARAM))) | ||
.returning(rootNodeWithDynamicLabels).build(); | ||
|
||
updateIfExists = updateDecorator.apply(match(rootNode).where(nodeIdFunction.apply(rootNode).isEqualTo(idParameter)) | ||
.mutate(rootNode, parameter(Constants.NAME_OF_PROPERTIES_PARAM))).returning(rootNode).build(); | ||
|