public interface Transaction extends Resource, StatementRunner
A driver Transaction object corresponds to a server transaction.
Transactions are typically wrapped in a try-with-resources block
which ensures that COMMIT
or ROLLBACK
occurs correctly on close.Note that ROLLBACK
is the
default action unless success()
is called before closing.
try(Transaction tx = session.beginTransaction())
{
tx.run("CREATE (a:Person {name: {x}})", parameters("x", "Alice"));
tx.success();
}
StatementRunner.run(java.lang.String, org.neo4j.driver.v1.Value)
,
StatementRunner
Modifier and Type | Method and Description |
---|---|
void |
close()
Closing the transaction will complete it - it will commit if
success() has been called. |
void |
failure()
Mark this transaction as failed.
|
void |
success()
Mark this transaction as successful.
|
run, run, run, run, run, typeSystem
void success()
close()
to have your
transaction committed.void failure()
close()
, the transaction will value rolled back.
After this method has been called, there is nothing that can be done to "un-mark" it. This is a safety feature
to make sure no other code calls success()
and makes a transaction commit that was meant to be rolled
back.
Example:
try(Transaction tx = session.beginTransaction() )
{
tx.run("CREATE (a:Person {name: {x}})", parameters("x", "Alice"));
tx.failure();
}
void close()
success()
has been called.
When this method returns, all outstanding statements in the transaction are guaranteed to
have completed, meaning any writes you performed are guaranteed to be durably stored.close
in interface AutoCloseable
close
in interface Resource
Copyright © 2017. All rights reserved.