the parameters are a start node and end node.

I'd like to check there's an edge named 'KNOWS' between them and connect 
them with the edge.

It's written in my java code as follows.
Transaction tx = graphDb.beginTx();
boolean result = checkIfKnowsEdgeExists(startNode, endNode));
tx.success();
tx.close();

if (!result) {
    Transaction tx = graphDb.beginTx();    
    makeKnowsEdge(startNode, endNode);
    tx.success();
    tx.close();
}

The problem of the code above is it can be performed in 2 transactions. 
I'd like to perform it in one transaction for performance, which creates an 
edge when there's no such an edge.
Is there any better way to solve it? Cypher does not matter.

The following code throws a deadlock related exception.
Transaction tx = graphDb.beginTx();

boolean result = checkIfKnowsEdgeExists(startNode, endNode));

if (!result) {
    Transaction tx = graphDb.beginTx();    
    makeKnowsEdge(startNode, endNode);
    tx.success();
    tx.close();
}


    

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to