Class Transaction

java.lang.Object
com.dieselpoint.norm.Transaction
All Implemented Interfaces:
Closeable, AutoCloseable

public class Transaction extends Object implements Closeable
Represents a database transaction. Create it using Transaction trans = Database.startTransation(), pass it to the query object using .transaction(trans), and then call trans.commit() or trans.rollback().

Some things to note: commit() and rollback() also call close() on the connection, so this class cannot be reused after the transaction is committed or rolled back.

This is just a convenience class. If the implementation is too restrictive, then you can manage your own transactions by calling Database.getConnection() and operate on the Connection directly.

  • Method Details

    • commit

      public void commit()
    • rollback

      public void rollback()
    • getConnection

      public Connection getConnection()
    • close

      public void close() throws IOException
      This simply calls .commit();
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getDatabase

      public Database getDatabase()
    • maxLatency

      public Transaction maxLatency(long millis)
      sets the maximum acceptable latency for this transaction. Must be called before commit().
      If latency of the query exceeds the threshold then the LatencyAlerter that have been added to the Database will be called in order.
      Parameters:
      millis - maximum number of milliseconds that a query can take to execute before an alert will be generated
      Returns:
      this, to enable maxLatency to be chained, a la trans.maxLatency("Ten People Transaction", 50).commit()
    • getMaxLatencyMillis

      public long getMaxLatencyMillis()