Package dev.grafeo.gwp
Class Transaction
java.lang.Object
dev.grafeo.gwp.Transaction
- All Implemented Interfaces:
AutoCloseable
An explicit transaction within a session.
Implements AutoCloseable for use with try-with-resources. If the
transaction has not been committed when close() is called, it will
be automatically rolled back.
try (Transaction tx = session.beginTransaction()) {
tx.execute("INSERT (:Person {name: 'Alice'})");
tx.commit();
}
// If commit() was not called, rollback happens automatically
-
Method Summary
-
Method Details
-
transactionId
The transaction identifier. -
execute
Execute a GQL statement within this transaction.- Parameters:
statement- the GQL statement to execute- Returns:
- a cursor over the results
-
execute
Execute a GQL statement within this transaction with parameters.- Parameters:
statement- the GQL statement to executeparameters- named parameters (may be null)- Returns:
- a cursor over the results
-
commit
public void commit()Commit the transaction.- Throws:
GqlStatusException- if the server returns an exception status
-
rollback
public void rollback()Roll back the transaction.This is a no-op if the transaction has already been committed or rolled back.
- Throws:
GqlStatusException- if the server returns an exception status
-
close
public void close()Close the transaction. If the transaction has not been committed, it will be rolled back automatically.- Specified by:
closein interfaceAutoCloseable
-