Can I force transaction neo4j?

This might be a typical Java 7 template for accessing some Neo4j data.

Is there any mechanism by which you can configure a transaction to automatically fail and rollback based on a timeout?

try (Transaction tx = graphdb.beginTx()) {
    Node node = // Get some Nodes ...
    Iterable<Relationship> rels = node.getRelationships(...);
    for (Relationship rel : rels) {
        // Oh no! This is a super-node with a billion Relationships!
    }
    tx.success();
    return data;
} 

I assume that there is only int count = 0and increase each iteration, and then:

if(count > XYZ) throw TakingTooLongException(count)

?

0
source share
1 answer

You can also simply check with node.getDegree()upfront before your loop, which is a constant time operation for dense nodes and a small counter for everyone else (<50 rels).

, , .

tx tx.success(), .

+1

Source: https://habr.com/ru/post/1616173/


All Articles