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 Summary
ConstructorsConstructorDescriptionConnectionHolder(Connection connection) Create a new ConnectionHolder for the given R2DBCConnection, assuming that there is no ongoing transaction.ConnectionHolder(Connection connection, boolean transactionActive) Create a new ConnectionHolder for the given R2DBCConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Return the currentConnectionheld by thisConnectionHolder.protected booleanReturn whether this holder currently has aConnection.protected booleanReturn whether this holder represents an active, R2DBC-managed transaction.voidreleased()Releases the currentConnection.protected voidsetConnection(Connection connection) Override the existing Connection with the givenConnection.protected voidsetTransactionActive(boolean transactionActive) Set whether this holder represents an active, R2DBC-managed transaction.Methods inherited from class org.springframework.transaction.support.ResourceHolderSupport
getDeadline, getTimeToLiveInMillis, getTimeToLiveInSeconds, hasTimeout, isOpen, isRollbackOnly, isSynchronizedWithTransaction, isVoid, requested, reset, resetRollbackOnly, setRollbackOnly, setSynchronizedWithTransaction, setTimeoutInMillis, setTimeoutInSeconds, unbound
-
Constructor Details
-
ConnectionHolder
Create a new ConnectionHolder for the given R2DBCConnection, assuming that there is no ongoing transaction.- Parameters:
connection- the R2DBCConnectionto hold- See Also:
-
ConnectionHolder
Create a new ConnectionHolder for the given R2DBCConnection.- Parameters:
connection- the R2DBCConnectionto holdtransactionActive- whether the givenConnectionis involved in an ongoing transaction
-
-
Method Details
-
hasConnection
protected boolean hasConnection()Return whether this holder currently has aConnection. -
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
Override the existing Connection with the givenConnection.Used for releasing the
Connectionon suspend (with anullargument) and setting a freshConnectionon resume. -
getConnection
Return the currentConnectionheld by thisConnectionHolder.This will be the same
Connectionuntilreleasedgets called on theConnectionHolder, which will reset the heldConnection, fetching a newConnectionon demand.- See Also:
-
released
public void released()Releases the currentConnection.- Overrides:
releasedin classorg.springframework.transaction.support.ResourceHolderSupport
-
clear
public void clear()- Overrides:
clearin classorg.springframework.transaction.support.ResourceHolderSupport
-