Hi Gorka
If it helps, have a look at the way I've presented the transactional endpoint in py2neo:
At the top level is a Session object that maintains the root URI for the database then, from that, transactions can be created. For each transaction, it's possible to add any number of statements and send these to the server for execution or commit/rollback as required. The precise REST endpoint used varies depending on the order in which executes and commits are received.
For example:
from py2neo import cypher
session = cypher.Session("http://localhost:7474")
tx = session.create_transaction()
# send three statements to for execution but leave the transaction open
tx.append("MERGE (a:Person {name:'Alice'})")
tx.append("MERGE (b:Person {name:'Bob'})")
tx.append("CREATE UNIQUE (a)-[:KNOWS]->(b)")
tx.execute()
# send another three statements and commit the transaction
tx.append("MERGE (c:Person {name:'Carol'})")
tx.append("MERGE (d:Person {name:'Dave'})")
tx.append("CREATE UNIQUE (c)-[:KNOWS]->(d)")
tx.commit()Each
execute() or
commit() method call will use one of four possible URIs:
- BEGIN -> /db/data/transaction
- BEGIN_COMMIT -> /db/data/transaction/commit
- EXECUTE -> /db/data/transaction/{id}
- COMMIT -> /db/data/transaction/{id}/commit
If the transaction ID is unknown (because no calls have previously been made) then the execute() method will use the BEGIN endpoint, otherwise it will use EXECUTE. Similarly, the commit() method will use either BEGIN_COMMIT or COMMIT. The actual code behind these methods is here:
By the way, I can't claim credit for this approach. It was inspired by a conversation with Tatham Oddie, author of the .NET driver, at GraphConnect SF last year :-)
Cheers
Nige