clojurewerkz.neocons.rest.transaction

Transaction management functions (Neo4J 2.0+ only).

begin

(begin connection)(begin connection xs)
Starts a transaction with the given cypher statements and returns a transaction record along with
the result of the cypher statements. 0-arity function call starts a transaction without any cypher statements.

For more information, see http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html#rest-api-begin-a-transaction

begin-tx

(begin-tx connection)
Starts a transaction without any cypher statements and returns it.

commit

(commit connection transaction)(commit connection transaction xs)
Commits an existing transaction with optional cypher statements which are applied
before the transaction is committed. It returns the result of the cypher statements.

For more information, see http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html#rest-api-commit-an-open-transaction

execute

(execute connection transaction)(execute connection transaction xs)
Executes cypher statements in an existing transaction and returns the new transaction record along
with the cypher results. If no cypher statements are give, the effect is to keep the transaction alive
(prevent it from timing out).

For more information, see http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html#rest-api-execute-statements-in-an-open-transaction

in-transaction

(in-transaction connection & coll)
It takes multiple statements and starts a transaction and commits them in a single HTTP request.

For more information, see http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html#rest-api-begin-and-commit-a-transaction-in-one-request

A simple example is given below:

  (tx/in-transaction connection
    (tx/statement "CREATE (n {props}) RETURN n" {:props {:name "My Node"}})
    (tx/statement "CREATE (n {props}) RETURN n" {:props {:name "My Another Node"}}))

rollback

(rollback connection transaction)

statement

(statement query)(statement query parameters)

tx-payload-from

(tx-payload-from xs)

tx-statement-from

(tx-statement-from m)

with-transaction

macro

(with-transaction connection transaction commit-on-success? & body)
A basic macro which gives a fine grained control of working in a transaction without manually
committing or checking for exceptions.

If commit-on-success? is true, then the given transaction is committed on success. Else the user
is responsible for manually committing/rolling back the transaction. At any stage if there is an
error, the transaction is rolled back if necessary.

A simple example is given below:

(let [transaction (tx/begin-tx)]
(tx/with-transaction
  connection
  transaction
  true
  (let [[_ result] (tx/execute connection transaction [(tx/statement "CREATE (n) RETURN ID(n)")])]
    (println result))))