Class DbTransactionFactory

java.lang.Object
org.tentackle.dbms.DbTransactionFactory

@Service(DbTransactionFactory.class) public class DbTransactionFactory extends Object
Factory for transactions.
Collects duration statistics and monitors transactions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the transaction factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Configures the factory from the main session properties.
    create(Db db, String txName, boolean fromRemote)
    Creates a transaction.
    Notice that this method is only invoked for local sessions, never for remote sessions.
    protected long
    createVoucher(boolean fromRemote)
    Creates a new transaction voucher.
    void
    finish(DbTransaction transaction, boolean rolledBack)
    Finishes a transaction.
    Invoked when a transaction is committed or rolled back.
    Notice that this method is only invoked for local sessions, never for remote sessions.
    The singleton.
    long
    Gets the check interval for idle or unreferenced transactions in ms.
    int
    Gets the number of check intervals that must elapse for an idle transaction to time out.
    boolean
    Returns whether statistics are collected.
    boolean
    Returns whether the supervisor thread is running.
    void
    logStatistics(Logger.Level level, boolean clear)
    Logs the statistics.
    void
    Requests supervisor thread termination.
    If transactions are still running, the supervisor keeps running until they are finished or timed out.
    void
    setCollectingStatistics(boolean collectingStatistics)
    Sets whether statistics should be collected.
    void
    setTxIdleInterval(long txIdleInterval)
    Sets the check interval for idle or unreferenced transactions in ms.
    void
    setTxIdleTimeout(int txIdleTimeout)
    Sets the number of check intervals that must elapse for an idle transaction to time out.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DbTransactionFactory

      public DbTransactionFactory()
      Creates the transaction factory.
  • Method Details

    • getInstance

      public static DbTransactionFactory getInstance()
      The singleton.
      Returns:
      the singleton
    • configure

      public void configure(EncryptedProperties properties)
      Configures the factory from the main session properties.
      Parameters:
      properties - the properties
    • create

      public DbTransaction create(Db db, String txName, boolean fromRemote)
      Creates a transaction.
      Notice that this method is only invoked for local sessions, never for remote sessions.
      Parameters:
      db - the session
      txName - the transaction name, null if <unnamed>
      fromRemote - true if initiated from the remote client
      Returns:
      the transaction
    • finish

      public void finish(DbTransaction transaction, boolean rolledBack)
      Finishes a transaction.
      Invoked when a transaction is committed or rolled back.
      Notice that this method is only invoked for local sessions, never for remote sessions.
      Parameters:
      transaction - the transaction
      rolledBack - true if transaction was rolled back, false if committed
    • setCollectingStatistics

      public void setCollectingStatistics(boolean collectingStatistics)
      Sets whether statistics should be collected.
      Parameters:
      collectingStatistics - true if transactions are counted and execution times measured
    • isCollectingStatistics

      public boolean isCollectingStatistics()
      Returns whether statistics are collected.
      Returns:
      true if transactions are counted and execution times measured
    • logStatistics

      public void logStatistics(Logger.Level level, boolean clear)
      Logs the statistics.
      Parameters:
      level - the logging level
      clear - true if clear statistics after dump
    • getTxIdleInterval

      public long getTxIdleInterval()
      Gets the check interval for idle or unreferenced transactions in ms.
      Returns:
      the check interval
    • setTxIdleInterval

      public void setTxIdleInterval(long txIdleInterval)
      Sets the check interval for idle or unreferenced transactions in ms.
      Parameters:
      txIdleInterval - the check interval
    • getTxIdleTimeout

      public int getTxIdleTimeout()
      Gets the number of check intervals that must elapse for an idle transaction to time out.
      Returns:
      the idle count
    • setTxIdleTimeout

      public void setTxIdleTimeout(int txIdleTimeout)
      Sets the number of check intervals that must elapse for an idle transaction to time out.
      Parameters:
      txIdleTimeout - the idle count, ≤ 0 to disable
    • requestTermination

      public void requestTermination()
      Requests supervisor thread termination.
      If transactions are still running, the supervisor keeps running until they are finished or timed out. The supervisor is started again when the next transaction is created.
    • isSupervisorRunning

      public boolean isSupervisorRunning()
      Returns whether the supervisor thread is running.
      Returns:
      true if running, false if not started yet or terminated
    • createVoucher

      protected long createVoucher(boolean fromRemote)
      Creates a new transaction voucher.
      Parameters:
      fromRemote - true if the transaction was started at the remote client
      Returns:
      the voucher