Class Transaction

java.lang.Object
dev.grafeo.gwp.Transaction
All Implemented Interfaces:
AutoCloseable

public class Transaction extends Object implements 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 Details

    • transactionId

      public String transactionId()
      The transaction identifier.
    • execute

      public ResultCursor execute(String statement)
      Execute a GQL statement within this transaction.
      Parameters:
      statement - the GQL statement to execute
      Returns:
      a cursor over the results
    • execute

      public ResultCursor execute(String statement, Map<String,Object> parameters)
      Execute a GQL statement within this transaction with parameters.
      Parameters:
      statement - the GQL statement to execute
      parameters - 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:
      close in interface AutoCloseable