Top Description Fields Constructors Methods
io.r2dbc.pool

pack-priv final Class PooledConnection

extends Object
implements Connection, Wrapped<Connection>
Class Inheritance
All Implemented Interfaces
io.r2dbc.spi.Wrapped, io.r2dbc.spi.Connection, io.r2dbc.spi.Closeable
Imports
io.r2dbc.spi.Batch, .Connection, .ConnectionMetadata, .IsolationLevel, .Lifecycle, .Statement, .TransactionDefinition, .ValidationDepth, .Wrapped, org.reactivestreams.Publisher, reactor.core.publisher.Mono, reactor.pool.PooledRef, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable, java.time.Duration, java.util.function.Function

Pooled Connection implementation. Performs a cleanup on close() if used transactionally.

Author
Mark Paluch

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final Connection
private volatile boolean
private static final Logger
private final PooledRef<Connection>
private final Mono<Void>

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
PooledConnection(PooledRef<Connection> ref, Function<? super Connection, ? extends Publisher<Void>> preRelease)

Method Summary

Modifier and TypeMethod and Description
private void
public Mono<Void>
beginTransaction()

Implements io.r2dbc.spi.Connection.beginTransaction.

Begins a new transaction.
public Mono<Void>
beginTransaction(TransactionDefinition
attributes for the transaction.
definition
)

Implements io.r2dbc.spi.Connection.beginTransaction.

Begins a new transaction.
public Mono<Void>
close()

Implements io.r2dbc.spi.Connection.close.

Release any resources held by the Connection.
public Mono<Void>
commitTransaction()

Implements io.r2dbc.spi.Connection.commitTransaction.

Commits the current transaction.
public Batch
createBatch()

Implements io.r2dbc.spi.Connection.createBatch.

Creates a new Batch instance for building a batched request.
public Publisher<Void>
createSavepoint(String
the name of the savepoint to create
s
)

Implements io.r2dbc.spi.Connection.createSavepoint.

Creates a savepoint in the current transaction.
public Statement
createStatement(String
the SQL of the statement
s
)

Implements io.r2dbc.spi.Connection.createStatement.

Creates a new statement for building a statement-based request.
public ConnectionMetadata
getMetadata()

Implements io.r2dbc.spi.Connection.getMetadata.

Returns the ConnectionMetadata about the product this Connection is connected to.
public IsolationLevel
private static Mono<Void>
public boolean
isAutoCommit()

Implements io.r2dbc.spi.Connection.isAutoCommit.

Returns the auto-commit mode for this connection.
public Publisher<Void>
releaseSavepoint(String
the name of the savepoint to release
s
)

Implements io.r2dbc.spi.Connection.releaseSavepoint.

Releases a savepoint in the current transaction.
public Mono<Void>
rollbackTransaction()

Implements io.r2dbc.spi.Connection.rollbackTransaction.

Rolls back the current transaction.
public Mono<Void>
rollbackTransactionToSavepoint(String
the name of the savepoint to rollback to
s
)

Implements io.r2dbc.spi.Connection.rollbackTransactionToSavepoint.

Rolls back to a savepoint in the current transaction.
public Mono<Void>
setAutoCommit(boolean
the isolation level for this transaction
autoCommit
)

Implements io.r2dbc.spi.Connection.setAutoCommit.

Configures the auto-commit mode for the current transaction.
public Mono<Void>
setLockWaitTimeout(Duration
the lock timeout for this connection. Support for no timeout is vendor-specific.
timeout
)

Implements io.r2dbc.spi.Connection.setLockWaitTimeout.

Configures the lock acquisition timeout for statements to be executed using the current connection.
public Mono<Void>
setStatementTimeout(Duration
the statement timeout for this connection. Duration#ZERO indicates no timeout.
timeout
)

Implements io.r2dbc.spi.Connection.setStatementTimeout.

Configures the statement timeout for statements to be executed using the current connection.
public Mono<Void>
setTransactionIsolationLevel(IsolationLevel
the isolation level for this transaction
isolationLevel
)

Implements io.r2dbc.spi.Connection.setTransactionIsolationLevel.

Configures the isolation level for the connection.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Connection
unwrap()

Implements io.r2dbc.spi.Wrapped.unwrap.

Returns the original instance wrapped by this object.
public Publisher<Boolean>
validate(ValidationDepth
the validation depth
validationDepth
)

Implements io.r2dbc.spi.Connection.validate.

Validates the connection according to the given ValidationDepth.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

closedback to summary
private volatile boolean closed
connectionback to summary
private final Connection connection
inTransactionback to summary
private volatile boolean inTransaction
loggerback to summary
private static final Logger logger
refback to summary
private final PooledRef<Connection> ref
releaseback to summary
private final Mono<Void> release

Constructor Detail

PooledConnectionback to summary
pack-priv PooledConnection(PooledRef<Connection> ref)
PooledConnectionback to summary
pack-priv PooledConnection(PooledRef<Connection> ref, Function<? super Connection, ? extends Publisher<Void>> preRelease)

Method Detail

assertNotClosedback to summary
private void assertNotClosed()
beginTransactionback to summary
public Mono<Void> beginTransaction()

Implements io.r2dbc.spi.Connection.beginTransaction.

Doc from io.r2dbc.spi.Connection.beginTransaction.

Begins a new transaction. Calling this method disables auto-commit mode.

Returns:Mono<Void>

a Publisher that indicates that the transaction is open

Annotations
@Override
beginTransactionback to summary
public Mono<Void> beginTransaction(TransactionDefinition definition)

Implements io.r2dbc.spi.Connection.beginTransaction.

Doc from io.r2dbc.spi.Connection.beginTransaction.

Begins a new transaction. Calling this method disables auto-commit mode. Beginning the transaction may fail if the TransactionDefinition conflicts with the connection configuration.

Parameters
definition:TransactionDefinition

attributes for the transaction.

Returns:Mono<Void>

a Publisher that indicates that the transaction is open

Annotations
@Override
closeback to summary
public Mono<Void> close()

Implements io.r2dbc.spi.Connection.close.

Doc from io.r2dbc.spi.Connection.close.

Release any resources held by the Connection.

Returns:Mono<Void>

a Publisher that termination is complete

Annotations
@Override
commitTransactionback to summary
public Mono<Void> commitTransaction()

Implements io.r2dbc.spi.Connection.commitTransaction.

Doc from io.r2dbc.spi.Connection.commitTransaction.

Commits the current transaction.

Returns:Mono<Void>

a Publisher that indicates that a transaction has been committed

Annotations
@Override
createBatchback to summary
public Batch createBatch()

Implements io.r2dbc.spi.Connection.createBatch.

Doc from io.r2dbc.spi.Connection.createBatch.

Creates a new Batch instance for building a batched request.

Returns:Batch

a new Batch instance

Annotations
@Override
createSavepointback to summary
public Publisher<Void> createSavepoint(String s)

Implements io.r2dbc.spi.Connection.createSavepoint.

Doc from io.r2dbc.spi.Connection.createSavepoint.

Creates a savepoint in the current transaction.

Parameters
s:String

the name of the savepoint to create

Returns:Publisher<Void>

a Publisher that indicates that a savepoint has been created

Annotations
@Override
createStatementback to summary
public Statement createStatement(String s)

Implements io.r2dbc.spi.Connection.createStatement.

Doc from io.r2dbc.spi.Connection.createStatement.

Creates a new statement for building a statement-based request.

Parameters
s:String

the SQL of the statement

Returns:Statement

a new Statement instance

Annotations
@Override
getMetadataback to summary
public ConnectionMetadata getMetadata()

Implements io.r2dbc.spi.Connection.getMetadata.

Doc from io.r2dbc.spi.Connection.getMetadata.

Returns the ConnectionMetadata about the product this Connection is connected to.

Returns:ConnectionMetadata

the ConnectionMetadata about the product this Connection is connected to

Annotations
@Override
getTransactionIsolationLevelback to summary
public IsolationLevel getTransactionIsolationLevel()

Implements io.r2dbc.spi.Connection.getTransactionIsolationLevel.

Doc from io.r2dbc.spi.Connection.getTransactionIsolationLevel.

Returns the IsolationLevel for this connection.

Isolation level is typically one of the following constants:

IsolationLevel is extensible so drivers can return a vendor-specific IsolationLevel.

Returns:IsolationLevel

the IsolationLevel for this connection.

Annotations
@Override
handleCleanupErrorback to summary
private static Mono<Void> handleCleanupError(Throwable throwable, PooledRef<Connection> ref)
isAutoCommitback to summary
public boolean isAutoCommit()

Implements io.r2dbc.spi.Connection.isAutoCommit.

Doc from io.r2dbc.spi.Connection.isAutoCommit.

Returns the auto-commit mode for this connection.

Returns:boolean

true if the connection is in auto-commit mode; false otherwise.

Annotations
@Override
releaseSavepointback to summary
public Publisher<Void> releaseSavepoint(String s)

Implements io.r2dbc.spi.Connection.releaseSavepoint.

Doc from io.r2dbc.spi.Connection.releaseSavepoint.

Releases a savepoint in the current transaction. Calling this for drivers not supporting savepoint release results in a no-op.

Parameters
s:String

the name of the savepoint to release

Returns:Publisher<Void>

a Publisher that indicates that a savepoint has been released

Annotations
@Override
rollbackTransactionback to summary
public Mono<Void> rollbackTransaction()

Implements io.r2dbc.spi.Connection.rollbackTransaction.

Doc from io.r2dbc.spi.Connection.rollbackTransaction.

Rolls back the current transaction.

Returns:Mono<Void>

a Publisher that indicates that a transaction has been rolled back

Annotations
@Override
rollbackTransactionToSavepointback to summary
public Mono<Void> rollbackTransactionToSavepoint(String s)

Implements io.r2dbc.spi.Connection.rollbackTransactionToSavepoint.

Doc from io.r2dbc.spi.Connection.rollbackTransactionToSavepoint.

Rolls back to a savepoint in the current transaction.

Parameters
s:String

the name of the savepoint to rollback to

Returns:Mono<Void>

a Publisher that indicates that a savepoint has been rolled back to

Annotations
@Override
setAutoCommitback to summary
public Mono<Void> setAutoCommit(boolean autoCommit)

Implements io.r2dbc.spi.Connection.setAutoCommit.

Doc from io.r2dbc.spi.Connection.setAutoCommit.

Configures the auto-commit mode for the current transaction. If a connection is in auto-commit mode, then all Statements will be executed and committed as individual transactions. Otherwise, in explicit transaction mode, transactions have to be started explicitly. A transaction needs to be either committed or rolled back to clean up the transaction state.

Calling this method during an active transaction and the auto-commit mode is changed, the transaction is committed. Calling this method without changing auto-commit mode this invocation results in a no-op.

Parameters
autoCommit:boolean

the isolation level for this transaction

Returns:Mono<Void>

a Publisher that indicates that auto-commit mode has been configured

Annotations
@Override
setLockWaitTimeoutback to summary
public Mono<Void> setLockWaitTimeout(Duration timeout)

Implements io.r2dbc.spi.Connection.setLockWaitTimeout.

Doc from io.r2dbc.spi.Connection.setLockWaitTimeout.

Configures the lock acquisition timeout for statements to be executed using the current connection. The default lock acquisition timeout is vendor-specific and can be specified for new connections through ConnectionFactoryOptions. If the timeout is exceeded, a R2dbcTimeoutException is raised.

In the case of Batch/Statement batching, it is vendor-specific as to whether the timeout is applied to individual SQL commands or the entire batch.

Parameters
timeout:Duration

the lock timeout for this connection. Support for no timeout is vendor-specific.

Returns:Mono<Void>

a Publisher that indicates that a lock timeout has been configured

Annotations
@Override
setStatementTimeoutback to summary
public Mono<Void> setStatementTimeout(Duration timeout)

Implements io.r2dbc.spi.Connection.setStatementTimeout.

Doc from io.r2dbc.spi.Connection.setStatementTimeout.

Configures the statement timeout for statements to be executed using the current connection. By default, there is no limit on the amount of time allowed for a running statement to complete unless specified through ConnectionFactoryOptions. If the limit is exceeded, a R2dbcTimeoutException is raised.

The minimum amount of time can be used to either let the data source cancel the statement or attempt a client-side cancellation. The timeout applies to statements through a combination of Statement#execute() and Result consumption. In the case of Batch/Statement batching, it is vendor-specific whether the timeout is applied to individual SQL commands or the entire batch.

Note that the timeout applies until receiving the first response from the data source and does not span until publisher completion.

Parameters
timeout:Duration

the statement timeout for this connection. Duration#ZERO indicates no timeout.

Returns:Mono<Void>

a Publisher that indicates that a statement timeout has been configured

Annotations
@Override
setTransactionIsolationLevelback to summary
public Mono<Void> setTransactionIsolationLevel(IsolationLevel isolationLevel)

Implements io.r2dbc.spi.Connection.setTransactionIsolationLevel.

Doc from io.r2dbc.spi.Connection.setTransactionIsolationLevel.

Configures the isolation level for the connection. When called outside a transaction, then the isolation level applies for all subsequent transactions. Setting the isolation level within a transaction results in vendor-specific behavior.

Isolation level is typically one of the following constants:

IsolationLevel is extensible so drivers can accept a vendor-specific IsolationLevel.

Parameters
isolationLevel:IsolationLevel

the isolation level for this transaction

Returns:Mono<Void>

a Publisher that indicates that a transaction level has been configured

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unwrapback to summary
public Connection unwrap()

Implements io.r2dbc.spi.Wrapped.unwrap.

Doc from io.r2dbc.spi.Wrapped.unwrap.

Returns the original instance wrapped by this object.

Returns:Connection

the original instance wrapped by this object

Annotations
@Override
validateback to summary
public Publisher<Boolean> validate(ValidationDepth validationDepth)

Implements io.r2dbc.spi.Connection.validate.

Doc from io.r2dbc.spi.Connection.validate.

Validates the connection according to the given ValidationDepth. Emits true if the validation was successful or false if the validation failed. Does not emit errors and does not complete empty.

Parameters
validationDepth:ValidationDepth

the validation depth

Returns:Publisher<Boolean>

a Publisher that indicates whether the validation was successful

Annotations
@Override