Class ConnectionHolder

java.lang.Object
org.springframework.transaction.support.ResourceHolderSupport
org.springframework.r2dbc.connection.ConnectionHolder
All Implemented Interfaces:
org.springframework.transaction.support.ResourceHolder

public class ConnectionHolder extends org.springframework.transaction.support.ResourceHolderSupport
Resource holder wrapping a R2DBC Connection. R2dbcTransactionManager binds instances of this class to the subscription, for a specific ConnectionFactory.

Inherits rollback-only support for nested R2DBC transactions and reference count functionality from the base class.

Note: This is an SPI class, not intended to be used by applications.

Since:
5.3
Author:
Mark Paluch, Christoph Strobl
See Also:
  • Constructor Details

    • ConnectionHolder

      public ConnectionHolder(Connection connection)
      Create a new ConnectionHolder for the given R2DBC Connection, assuming that there is no ongoing transaction.
      Parameters:
      connection - the R2DBC Connection to hold
      See Also:
    • ConnectionHolder

      public ConnectionHolder(Connection connection, boolean transactionActive)
      Create a new ConnectionHolder for the given R2DBC Connection.
      Parameters:
      connection - the R2DBC Connection to hold
      transactionActive - whether the given Connection is involved in an ongoing transaction
  • Method Details

    • hasConnection

      protected boolean hasConnection()
      Return whether this holder currently has a Connection.
    • setTransactionActive

      protected void setTransactionActive(boolean transactionActive)
      Set whether this holder represents an active, R2DBC-managed transaction.
      See Also:
    • isTransactionActive

      protected boolean isTransactionActive()
      Return whether this holder represents an active, R2DBC-managed transaction.
    • setConnection

      protected void setConnection(@Nullable Connection connection)
      Override the existing Connection with the given Connection.

      Used for releasing the Connection on suspend (with a null argument) and setting a fresh Connection on resume.

    • getConnection

      public Connection getConnection()
      Return the current Connection held by this ConnectionHolder.

      This will be the same Connection until released gets called on the ConnectionHolder, which will reset the held Connection, fetching a new Connection on demand.

      See Also:
    • released

      public void released()
      Releases the current Connection.
      Overrides:
      released in class org.springframework.transaction.support.ResourceHolderSupport
    • clear

      public void clear()
      Overrides:
      clear in class org.springframework.transaction.support.ResourceHolderSupport