Skip to content

Commit c7ec2f5

Browse files
committed
Give unique element ids for virtual nodes as well
1 parent 02317e8 commit c7ec2f5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

common/src/main/java/apoc/result/VirtualNode.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public VirtualNode(Label[] labels, Map<String, Object> props) {
4747
this.id = MIN_ID.decrementAndGet();
4848
addLabels(asList(labels));
4949
this.props.putAll(props);
50-
this.elementId = null;
50+
this.elementId = UUID.randomUUID().toString();
5151
}
5252

5353
@SuppressWarnings("unused") // used from extended
@@ -65,15 +65,17 @@ public VirtualNode(long nodeId) {
6565

6666
public VirtualNode(Node node, List<String> propertyNames, boolean wrapNodeIDs) {
6767
Objects.requireNonNull(node, ERROR_NODE_NULL);
68-
final long id = node.getId();
69-
// if node is already virtual, we return the same id
70-
this.id = id < 0 || wrapNodeIDs ? id : -id - 1;
68+
final long givenNodeId = node.getId();
69+
// if node is already virtual, we return the same id/element id
70+
this.id = givenNodeId < 0 || wrapNodeIDs ? givenNodeId : -givenNodeId - 1;
71+
this.elementId = givenNodeId < 0 || wrapNodeIDs
72+
? node.getElementId()
73+
: UUID.randomUUID().toString();
7174
// to not overlap this nodes ids with ids from VirtualNode(Label[] labels, Map<String, Object> props)
7275
MIN_ID.updateAndGet(x -> Math.min(x, this.id));
7376
this.labels.addAll(Util.labelStrings(node));
7477
String[] keys = propertyNames.toArray(new String[propertyNames.size()]);
7578
this.props.putAll(node.getProperties(keys));
76-
this.elementId = node.getElementId();
7779
}
7880

7981
public VirtualNode(Node node, List<String> propertyNames) {

0 commit comments

Comments
 (0)