Top Description Fields Constructors Methods
org.springframework.r2dbc.connection

public Class ConnectionHolder

extends ResourceHolderSupport
Class Inheritance
Imports
io.r2dbc.spi.Connection, .ConnectionFactory, org.springframework.lang.Nullable, org.springframework.transaction.support.ResourceHolderSupport, org.springframework.util.Assert

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.

Authors
Mark Paluch, Christoph Strobl
Since
5.3
See Also
R2dbcTransactionManager, ConnectionFactoryUtils

Field Summary

Modifier and TypeField and Description
private Connection
pack-priv static final String
SAVEPOINT_NAME_PREFIX

Prefix for savepoint names.

private int
private boolean

Constructor Summary

AccessConstructor and Description
public
ConnectionHolder(Connection
the R2DBC Connection to hold
connection
)

Create a new ConnectionHolder for the given R2DBC Connection, assuming that there is no ongoing transaction.

public
ConnectionHolder(Connection
the R2DBC Connection to hold
connection
,
boolean
whether the given Connection is involved in an ongoing transaction
transactionActive
)

Create a new ConnectionHolder for the given R2DBC Connection.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides org.springframework.transaction.support.ResourceHolderSupport.clear.

Clear the transactional state of this resource holder.

public Connection
getConnection()

Return the current Connection held by this ConnectionHolder.

protected boolean
hasConnection()

Return whether this holder currently has a Connection.

protected boolean
isTransactionActive()

Return whether this holder represents an active, R2DBC-managed transaction.

pack-priv String

Returns:

the name of the new savepoint
nextSavepoint
()

Create a new savepoint for the current Connection, using generated savepoint names that are unique for the Connection.

public void
protected void
setConnection(Connection connection)

Override the existing Connection with the given Connection.

protected void
setTransactionActive(boolean transactionActive)

Set whether this holder represents an active, R2DBC-managed transaction.

Inherited from org.springframework.transaction.support.ResourceHolderSupport:
getDeadlinegetTimeToLiveInMillisgetTimeToLiveInSecondshasTimeoutisOpenisRollbackOnlyisSynchronizedWithTransactionisVoidrequestedresetresetRollbackOnlysetRollbackOnlysetSynchronizedWithTransactionsetTimeoutInMillissetTimeoutInSecondsunbound

Field Detail

currentConnectionback to summary
private Connection currentConnection
Annotations
@Nullable
SAVEPOINT_NAME_PREFIXback to summary
pack-priv static final String SAVEPOINT_NAME_PREFIX

Prefix for savepoint names.

Since
6.0.10
savepointCounterback to summary
private int savepointCounter
transactionActiveback to summary
private boolean transactionActive

Constructor Detail

ConnectionHolderback to summary
public ConnectionHolder(Connection connection)

Create a new ConnectionHolder for the given R2DBC Connection, assuming that there is no ongoing transaction.

Parameters
connection:Connection

the R2DBC Connection to hold

See Also
ConnectionHolder(Connection, boolean)
ConnectionHolderback to summary
public ConnectionHolder(Connection connection, boolean transactionActive)

Create a new ConnectionHolder for the given R2DBC Connection.

Parameters
connection:Connection

the R2DBC Connection to hold

transactionActive:boolean

whether the given Connection is involved in an ongoing transaction

Method Detail

clearback to summary
public void clear()

Overrides org.springframework.transaction.support.ResourceHolderSupport.clear.

Doc from org.springframework.transaction.support.ResourceHolderSupport.clear.

Clear the transactional state of this resource holder.

Annotations
@Override
getConnectionback to summary
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()
hasConnectionback to summary
protected boolean hasConnection()

Return whether this holder currently has a Connection.

isTransactionActiveback to summary
protected boolean isTransactionActive()

Return whether this holder represents an active, R2DBC-managed transaction.

nextSavepointback to summary
pack-priv String nextSavepoint()

Create a new savepoint for the current Connection, using generated savepoint names that are unique for the Connection.

Returns:String

the name of the new savepoint

Since
6.0.10
releasedback to summary
public void released()

Overrides org.springframework.transaction.support.ResourceHolderSupport.released.

Releases the current Connection.

Annotations
@Override
setConnectionback to summary
protected void setConnection(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.

setTransactionActiveback to summary
protected void setTransactionActive(boolean transactionActive)

Set whether this holder represents an active, R2DBC-managed transaction.

See Also
R2dbcTransactionManager