Class TxnExecutor


  • public class TxnExecutor
    extends Object
    Provides a Cayenne Transaction Executor class, which will execute the specified function in a Cayenne Transaction.
    Since:
    4.0.0
    • Constructor Detail

      • TxnExecutor

        public TxnExecutor​(Class callingClass,
                           String errorType)
        Create a Transaction Executor object with the given logger.
        Parameters:
        callingClass - the class calling the service, used for error logging purposes
        errorType - the error type to log (required)
      • TxnExecutor

        public TxnExecutor​(Class callingClass,
                           String errorType,
                           int transactionIsolation,
                           boolean readOnly)
        Create a Transaction Executor object with the given logger.
        Parameters:
        callingClass - the class calling the service, used for error logging purposes
        errorType - the error type to log (required)
        transactionIsolation - the transaction isolation level
        readOnly - the connection ready only flag
        Since:
        4.3.4
    • Method Detail

      • execute

        public Object execute​(TxnExecutor.IFunction function)
                       throws ApplicationException
        Execute the given function inside a Cayenne transaction. If an error occurs that is a RuntimeException, it will be thrown as is; other errors will be wrapped in an ApplicationException.
        Parameters:
        function - the function to execute
        Returns:
        the function result if successful
        Throws:
        ApplicationException - if an error occurs executing the function or performing a transaction commit