Skip to content

Commit ed6dcf8

Browse files
committed
feat: udpate cypher query
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent 398d9b6 commit ed6dcf8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,19 @@ public CommunicationEdge edge(CommunicationEntity source, String label, Communic
330330

331331
String cypher = "MATCH (s) WHERE elementId(s) = $sourceElementId " +
332332
"MATCH (t) WHERE elementId(t) = $targetElementId " +
333-
"WITH s, t " +
334-
"WHERE NOT EXISTS { MATCH (s)-[r:" + label + "]->(t) } " +
335-
"CREATE (s)-[r:" + label + " $props]->(t) " +
333+
"OPTIONAL MATCH (s)-[existing:" + label + "]->(t) " +
334+
"WITH s, t, existing " +
335+
"CALL { " +
336+
" WITH s, t, existing " +
337+
" WHERE existing IS NULL " +
338+
" CREATE (s)-[r:" + label + " $props]->(t) " +
339+
" RETURN r " +
340+
" UNION " +
341+
" RETURN existing AS r " +
342+
"} " +
336343
"RETURN r";
337344

345+
LOGGER.fine(() -> "Creating edge with Cypher query: " + cypher);
338346
try (Transaction tx = session.beginTransaction()) {
339347
var sourceId = source.find(ID).orElseThrow(() ->
340348
new EdgeCommunicationException("The source entity should have the " + ID + " property")).get();

0 commit comments

Comments
 (0)