Interface ITransactionService

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void beginTx()
      This is a shortcut for getUserTransaction().begin(), that wraps all checked exceptions thrown by the UserTransaction.begin() into unchecked RuntimeException, so that the users don't have to handle them (since they typically cannot be handled anyway).
      boolean canBeginTx()
      Shortcut method to determine, whether a transaction COULD be open.
      void commitTx()
      This is a shortcut for getUserTransaction().commit(), that wraps all checked exceptions thrown by UserTransaction.commit() into generic Exceptions.
      void endTx​(boolean rollback)
      Shortcut for
      TransactionExecuter execute()
      Returns a new instance of an executor that simplifies the transaction execution.
      javax.transaction.Transaction getTransaction()  
      javax.transaction.UserTransaction getUserTransaction()  
      void preventThreadKilling()
      void rollbackTx()
      This is a shortcut for getUserTransaction().rollback(), that wraps all exceptions thrown by the UserTransaction.rollback() into unchecked RuntimeException, so that the clients don't have to handle them (since they typically cannot be handled anyway).
      void setRollbackOnly​(java.lang.String msg)
      Calls getTransaction().setRollbackOnly() and also registers a message for a future exception that will be thrown by commitTx() if somebody attempts to commit this transaction.
      void setRollbackOnly​(java.lang.Throwable th)
      Calls getTransaction().setRollbackOnly() and also registers a throwable cause for a future exception that will be thrown by commitTx() if somebody attempts to commit this transaction.
      boolean txExists()
      Shortcut method to determine, whether a transaction is open.
    • Method Detail

      • getUserTransaction

        javax.transaction.UserTransaction getUserTransaction()
      • getTransaction

        javax.transaction.Transaction getTransaction()
      • txExists

        boolean txExists()
        Shortcut method to determine, whether a transaction is open.
        Returns:
        true if there is an open transaction.
      • canBeginTx

        boolean canBeginTx()
        Shortcut method to determine, whether a transaction COULD be open.

        Unlike txExists(), this will return true if and only if beginTx() is permitted = there is no transaction (either active or after completion).

        Returns:
        true if the transaction can be opened.
      • beginTx

        void beginTx()
        This is a shortcut for getUserTransaction().begin(), that wraps all checked exceptions thrown by the UserTransaction.begin() into unchecked RuntimeException, so that the users don't have to handle them (since they typically cannot be handled anyway).
      • commitTx

        void commitTx()
               throws java.lang.Exception
        This is a shortcut for getUserTransaction().commit(), that wraps all checked exceptions thrown by UserTransaction.commit() into generic Exceptions.

        This method intentionally declares a checked exception, since all clients should be prepared to handle commit failures appropriately.

        Throws:
        java.lang.Exception
      • rollbackTx

        void rollbackTx()
        This is a shortcut for getUserTransaction().rollback(), that wraps all exceptions thrown by the UserTransaction.rollback() into unchecked RuntimeException, so that the clients don't have to handle them (since they typically cannot be handled anyway).
      • endTx

        void endTx​(boolean rollback)
            throws java.lang.Exception
        Shortcut for
                if(rollback) {
                        rollbackTx();
                } else {
                        commitTx();
             }
         
        Parameters:
        rollback -
        Throws:
        java.lang.Exception
      • setRollbackOnly

        void setRollbackOnly​(java.lang.String msg)
        Calls getTransaction().setRollbackOnly() and also registers a message for a future exception that will be thrown by commitTx() if somebody attempts to commit this transaction.
        Parameters:
        msg -
        Since:
        3.3.1
      • setRollbackOnly

        void setRollbackOnly​(java.lang.Throwable th)
        Calls getTransaction().setRollbackOnly() and also registers a throwable cause for a future exception that will be thrown by commitTx() if somebody attempts to commit this transaction.
        Parameters:
        th -
        Since:
        3.5.3
      • execute

        @NotNull
        TransactionExecuter execute()
        Returns a new instance of an executor that simplifies the transaction execution.
        Since:
        3.18.0
      • preventThreadKilling

        void preventThreadKilling()

        Used to prevent the killing of threads when called inside a custom extension.

        To prevent clogging up the server, a functionality was implemented in 18.2 that interrupts the processing of UI requests that take longer than a specified amount of time.

        Only read-only user requests are affected. Requests with write operations are not.

        All write operations performed via the Polarion API won't be interrupted, but if you have, or plan to implement, a custom extension that needs to write data to an external system, use this method to mark the current thread as non-interruptible prior to any write operation to prevent data inconsistency.

        For more information see

        Polarion ALM Platform Help --> Administrator's Guide --> System Maintenance --> Topics --> Prevent Long Running Transactions from Clogging up the Server

        Since:
        3.18.2