public interface Connection extends Closeable
Connection object can consist of any number of transport
connections to the underlying database or represent a session over a multiplexed transport connection. For maximum portability, connections should be used synchronously.
Connection objects initiate database conversations for transaction management and statement execution. Objects created by a connection are only valid as long as the connection remains
open.
When configuring a connection, R2DBC applications should use the appropriate methods such as beginTransaction(), setAutoCommit(boolean) and
setTransactionIsolationLevel(IsolationLevel) to change transaction properties instead. Applications should not execute SQL commands directly to change the connection configuration when
a R2DBC method is available.
New connections are by default created in auto-commit mode.
| Modifier and Type | Method and Description |
|---|---|
Publisher<Void> |
beginTransaction()
Begins a new transaction.
|
Publisher<Void> |
close()
Release any resources held by the
Connection. |
Publisher<Void> |
commitTransaction()
Commits the current transaction.
|
Batch |
createBatch()
Creates a new
Batch instance for building a batched request. |
Publisher<Void> |
createSavepoint(String name)
Creates a savepoint in the current transaction.
|
Statement |
createStatement(String sql)
Creates a new statement for building a statement-based request.
|
ConnectionMetadata |
getMetadata()
Returns the
ConnectionMetadata about the product this Connection is connected to. |
IsolationLevel |
getTransactionIsolationLevel()
Returns the
IsolationLevel for this connection. |
boolean |
isAutoCommit()
Returns the auto-commit mode for this connection.
|
Publisher<Void> |
releaseSavepoint(String name)
Releases a savepoint in the current transaction.
|
Publisher<Void> |
rollbackTransaction()
Rolls back the current transaction.
|
Publisher<Void> |
rollbackTransactionToSavepoint(String name)
Rolls back to a savepoint in the current transaction.
|
Publisher<Void> |
setAutoCommit(boolean autoCommit)
Configures the auto-commit mode for the current transaction.
|
Publisher<Void> |
setTransactionIsolationLevel(IsolationLevel isolationLevel)
Configures the isolation level for the current transaction.
|
Publisher<Boolean> |
validate(ValidationDepth depth)
Validates the connection according to the given
ValidationDepth. |
Publisher<Void> beginTransaction()
auto-commit mode.Publisher that indicates that the transaction is openPublisher<Void> close()
Connection.Publisher<Void> commitTransaction()
Publisher that indicates that a transaction has been committedBatch createBatch()
Batch instance for building a batched request.Batch instancePublisher<Void> createSavepoint(String name)
name - the name of the savepoint to createPublisher that indicates that a savepoint has been createdIllegalArgumentException - if name is nullUnsupportedOperationException - if savepoints are not supportedStatement createStatement(String sql)
sql - the SQL of the statementStatement instanceIllegalArgumentException - if sql is nullboolean isAutoCommit()
ConnectionMetadata getMetadata()
ConnectionMetadata about the product this Connection is connected to.ConnectionMetadata about the product this Connection is connected toIsolationLevel getTransactionIsolationLevel()
IsolationLevel for this connection.
Isolation level is typically one of the following constants:
IsolationLevel.READ_UNCOMMITTEDIsolationLevel.READ_COMMITTEDIsolationLevel.REPEATABLE_READIsolationLevel.SERIALIZABLE
IsolationLevel is extensible so drivers can return a vendor-specific IsolationLevel.
IsolationLevel for this connection.Publisher<Void> releaseSavepoint(String name)
name - the name of the savepoint to releasePublisher that indicates that a savepoint has been releasedIllegalArgumentException - if name is nullPublisher<Void> rollbackTransaction()
Publisher that indicates that a transaction has been rolled backPublisher<Void> rollbackTransactionToSavepoint(String name)
name - the name of the savepoint to rollback toPublisher that indicates that a savepoint has been rolled back toIllegalArgumentException - if name is nullUnsupportedOperationException - if savepoints are not supportedPublisher<Void> setAutoCommit(boolean autoCommit)
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.
autoCommit - the isolation level for this transactionPublisher that indicates that auto-commit mode has been configuredPublisher<Void> setTransactionIsolationLevel(IsolationLevel isolationLevel)
Isolation level is typically one of the following constants:
IsolationLevel.READ_UNCOMMITTEDIsolationLevel.READ_COMMITTEDIsolationLevel.REPEATABLE_READIsolationLevel.SERIALIZABLE
IsolationLevel is extensible so drivers can accept a vendor-specific IsolationLevel.
isolationLevel - the isolation level for this transactionPublisher that indicates that a transaction level has been configuredIllegalArgumentException - if isolationLevel is nullPublisher<Boolean> validate(ValidationDepth depth)
ValidationDepth.
Emits true if the validation was successful or false if the validation failed. Does not emit errors and does not complete empty.depth - the validation depthPublisher that indicates whether the validation was successfulIllegalArgumentException - if depth is nullCopyright © 2021. All rights reserved.