Class JPAEntityTransaction

  • All Implemented Interfaces:
    javax.persistence.EntityTransaction

    public class JPAEntityTransaction
    extends Object
    implements javax.persistence.EntityTransaction
    EntityTransaction implementation for JPA for ResourceLocal transaction. Utilises the underlying ExecutionContext and its real transaction, providing a JPA layer on top.
    • Constructor Summary

      Constructors 
      Constructor Description
      JPAEntityTransaction​(org.datanucleus.ExecutionContext ec)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void assertActive()
      Convenience method to throw an exception if the transaction is not active.
      protected void assertNotActive()
      Convenience method to throw an exception if the transaction is active.
      void begin()
      Start a resource transaction.
      void commit()
      Commit the current transaction, writing any unflushed changes to the database.
      void deregisterEventListener​(org.datanucleus.transaction.TransactionEventListener listener)
      Method to deregister a listener for transaction events.
      boolean getRollbackOnly()
      Determine whether the current transaction has been marked for rollback.
      boolean isActive()
      Indicate whether a transaction is in progress.
      void registerEventListener​(org.datanucleus.transaction.TransactionEventListener listener)
      Method to register a listener for transaction events.
      void releaseSavepoint​(String name)
      Method to mark the current point as a savepoint with the provided name.
      void rollback()
      Roll back the current transaction.
      void rollbackToSavepoint​(String name)
      Method to mark the current point as a savepoint with the provided name.
      void setOption​(String option, boolean value)
      Convenience accessor for setting a transaction option.
      void setOption​(String option, int value)
      Convenience accessor for setting a transaction option.
      void setOption​(String option, String value)
      Convenience accessor for setting a transaction option.
      void setRollbackOnly()
      Mark the current transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.
      void setSavepoint​(String name)
      Method to mark the current point as a savepoint with the provided name.
    • Constructor Detail

      • JPAEntityTransaction

        public JPAEntityTransaction​(org.datanucleus.ExecutionContext ec)
        Constructor.
        Parameters:
        ec - The ExecutionContext providing the transaction.
    • Method Detail

      • isActive

        public boolean isActive()
        Indicate whether a transaction is in progress.
        Specified by:
        isActive in interface javax.persistence.EntityTransaction
        Throws:
        javax.persistence.PersistenceException - if an unexpected error condition is encountered.
      • begin

        public void begin()
        Start a resource transaction.
        Specified by:
        begin in interface javax.persistence.EntityTransaction
        Throws:
        IllegalStateException - if the transaction is active
      • commit

        public void commit()
        Commit the current transaction, writing any unflushed changes to the database.
        Specified by:
        commit in interface javax.persistence.EntityTransaction
        Throws:
        IllegalStateException - if isActive() is false.
        javax.persistence.RollbackException - if the commit fails.
      • rollback

        public void rollback()
        Roll back the current transaction.
        Specified by:
        rollback in interface javax.persistence.EntityTransaction
        Throws:
        IllegalStateException - if isActive() is false.
        javax.persistence.PersistenceException - if an unexpected error condition is encountered.
      • getRollbackOnly

        public boolean getRollbackOnly()
        Determine whether the current transaction has been marked for rollback.
        Specified by:
        getRollbackOnly in interface javax.persistence.EntityTransaction
        Throws:
        IllegalStateException - if isActive() is false.
      • setRollbackOnly

        public void setRollbackOnly()
        Mark the current transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.
        Specified by:
        setRollbackOnly in interface javax.persistence.EntityTransaction
        Throws:
        IllegalStateException - Thrown if the transaction is not active
      • setOption

        public void setOption​(String option,
                              int value)
        Convenience accessor for setting a transaction option.
        Parameters:
        option - option name
        value - The value
      • setOption

        public void setOption​(String option,
                              boolean value)
        Convenience accessor for setting a transaction option.
        Parameters:
        option - option name
        value - The value
      • setOption

        public void setOption​(String option,
                              String value)
        Convenience accessor for setting a transaction option.
        Parameters:
        option - option name
        value - The value
      • setSavepoint

        public void setSavepoint​(String name)
        Method to mark the current point as a savepoint with the provided name.
        Parameters:
        name - Name of the savepoint.
        Throws:
        UnsupportedOperationException - if the underlying datastore doesn't support savepoints
        IllegalStateException - if no name is provided
      • releaseSavepoint

        public void releaseSavepoint​(String name)
        Method to mark the current point as a savepoint with the provided name.
        Parameters:
        name - Name of the savepoint.
        Throws:
        UnsupportedOperationException - if the underlying datastore doesn't support savepoints
        IllegalStateException - if no name is provided, or the name doesn't correspond to a known savepoint
      • rollbackToSavepoint

        public void rollbackToSavepoint​(String name)
        Method to mark the current point as a savepoint with the provided name.
        Parameters:
        name - Name of the savepoint.
        Throws:
        UnsupportedOperationException - if the underlying datastore doesn't support savepoints
        IllegalStateException - if no name is provided, or the name doesn't correspond to a known savepoint
      • assertActive

        protected void assertActive()
        Convenience method to throw an exception if the transaction is not active.
        Throws:
        IllegalStateException - Thrown if the transaction is not active.
      • assertNotActive

        protected void assertNotActive()
        Convenience method to throw an exception if the transaction is active.
        Throws:
        IllegalStateException - Thrown if the transaction is active.
      • registerEventListener

        public void registerEventListener​(org.datanucleus.transaction.TransactionEventListener listener)
        Method to register a listener for transaction events.
        Parameters:
        listener - The listener
      • deregisterEventListener

        public void deregisterEventListener​(org.datanucleus.transaction.TransactionEventListener listener)
        Method to deregister a listener for transaction events.
        Parameters:
        listener - The listener to remove