Class ResourceHolderSupport

  • All Implemented Interfaces:
    ResourceHolder
    Direct Known Subclasses:
    ConnectionHolder, EntityManagerHolder

    public abstract class ResourceHolderSupport
    extends java.lang.Object
    implements ResourceHolder
    Convenient base class for resource holders.

    Features rollback-only support for participating transactions. Can expire after a certain number of seconds or milliseconds in order to determine a transactional timeout.

    Since:
    02.02.2004
    Author:
    Juergen Hoeller
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the transactional state of this resource holder.
      java.util.Date getDeadline()
      Return the expiration deadline of this object.
      long getTimeToLiveInMillis()
      Return the time to live for this object in milliseconds.
      int getTimeToLiveInSeconds()
      Return the time to live for this object in seconds.
      boolean hasTimeout()  
      boolean isOpen()  
      boolean isRollbackOnly()  
      boolean isSynchronizedWithTransaction()  
      boolean isVoid()
      Determine whether this holder is considered as 'void', i.e.
      void released()
      Decrease the reference count by one because the holder has been released (i.e.
      void requested()
      Increase the reference count by one because the holder has been requested (i.e.
      void reset()
      Reset this resource holder - transactional state as well as reference count.
      void resetRollbackOnly()
      Reset the rollback-only status for this resource transaction.
      void setRollbackOnly()
      Mark the resource transaction as rollback-only.
      void setSynchronizedWithTransaction​(boolean synchronizedWithTransaction)
      Mark the resource as synchronized with a transaction.
      void setTimeout​(java.time.Duration timeout)
      Set the timeout for this object in seconds.
      void setTimeoutInMillis​(long millis)
      Set the timeout for this object in milliseconds.
      void unbound()
      Notify this holder that it has been unbound from transaction synchronization.
      • Methods inherited from class java.lang.Object

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

      • ResourceHolderSupport

        public ResourceHolderSupport()
    • Method Detail

      • setSynchronizedWithTransaction

        public void setSynchronizedWithTransaction​(boolean synchronizedWithTransaction)
        Mark the resource as synchronized with a transaction.
        Parameters:
        synchronizedWithTransaction - True if synchronized with transaction
      • isSynchronizedWithTransaction

        public boolean isSynchronizedWithTransaction()
        Returns:
        Return whether the resource is synchronized with a transaction.
      • setRollbackOnly

        public void setRollbackOnly()
        Mark the resource transaction as rollback-only.
      • resetRollbackOnly

        public void resetRollbackOnly()
        Reset the rollback-only status for this resource transaction.

        Only really intended to be called after custom rollback steps which keep the original resource in action, e.g. in case of a savepoint.

        Since:
        5.0
        See Also:
        SavepointManager.rollbackToSavepoint(java.lang.Object)
      • isRollbackOnly

        public boolean isRollbackOnly()
        Returns:
        Return whether the resource transaction is marked as rollback-only.
      • setTimeout

        public void setTimeout​(java.time.Duration timeout)
        Set the timeout for this object in seconds.
        Parameters:
        timeout - The timeout
      • setTimeoutInMillis

        public void setTimeoutInMillis​(long millis)
        Set the timeout for this object in milliseconds.
        Parameters:
        millis - number of milliseconds until expiration
      • hasTimeout

        public boolean hasTimeout()
        Returns:
        Return whether this object has an associated timeout.
      • getDeadline

        @Nullable
        public java.util.Date getDeadline()
        Return the expiration deadline of this object.
        Returns:
        the deadline as Date object
      • getTimeToLiveInSeconds

        public int getTimeToLiveInSeconds()
        Return the time to live for this object in seconds. Rounds up eagerly, e.g. 9.00001 still to 10.
        Returns:
        number of seconds until expiration
        Throws:
        TransactionTimedOutException - if the deadline has already been reached
      • getTimeToLiveInMillis

        public long getTimeToLiveInMillis()
                                   throws TransactionTimedOutException
        Return the time to live for this object in milliseconds.
        Returns:
        number of milliseconds until expiration
        Throws:
        TransactionTimedOutException - if the deadline has already been reached
      • requested

        public void requested()
        Increase the reference count by one because the holder has been requested (i.e. someone requested the resource held by it).
      • released

        public void released()
        Decrease the reference count by one because the holder has been released (i.e. someone released the resource held by it).
      • isOpen

        public boolean isOpen()
        Returns:
        Return whether there are still open references to this holder.
      • clear

        public void clear()
        Clear the transactional state of this resource holder.
      • reset

        public void reset()
        Reset this resource holder - transactional state as well as reference count.
        Specified by:
        reset in interface ResourceHolder
      • unbound

        public void unbound()
        Description copied from interface: ResourceHolder
        Notify this holder that it has been unbound from transaction synchronization.
        Specified by:
        unbound in interface ResourceHolder
      • isVoid

        public boolean isVoid()
        Description copied from interface: ResourceHolder
        Determine whether this holder is considered as 'void', i.e. as a leftover from a previous thread.
        Specified by:
        isVoid in interface ResourceHolder
        Returns:
        If the resource is void