Skip to content

Commit 26a7394

Browse files
committed
feat: check if the properties existe on neo4j
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent c14614e commit 26a7394

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

jnosql-neo4j/src/main/java/org/eclipse/jnosql/databases/neo4j/communication/DefaultNeo4JDatabaseManager.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,19 @@ public CommunicationEdge edge(CommunicationEntity source, String label, Communic
349349
org.neo4j.driver.types.Relationship relationship;
350350

351351
if (result.hasNext()) {
352-
relationship = result.single().get("r").asRelationship();
352+
String updateQuery = "MATCH (s)-[r:" + label + "]->(t) " +
353+
"WHERE elementId(s) = $sourceElementId AND elementId(t) = $targetElementId " +
354+
"SET r += $props " +
355+
"RETURN r";
356+
LOGGER.fine(() -> "Updating existing edge with ID: " + sourceId + " to " + targetId);
357+
LOGGER.fine(() -> "Cypher Query: " + updateQuery);
358+
var updateResult = tx.run(updateQuery, Values.parameters(
359+
"sourceElementId", sourceId,
360+
"targetElementId", targetId,
361+
"props", properties
362+
));
363+
364+
relationship = updateResult.single().get("r").asRelationship();
353365
LOGGER.fine(() -> "Found existing edge with ID: " + relationship.elementId());
354366
} else {
355367
String createEdge = "MATCH (s) WHERE elementId(s) = $sourceElementId " +

0 commit comments

Comments
 (0)