Top Description Methods
org.jooq

public Interface ConnectionProvider

Known Direct Implementers
org.jooq.impl.DataSourceConnectionProvider, org.jooq.impl.DefaultConnectionProvider, org.jooq.impl.DefaultInterpreterConnectionProvider, org.jooq.impl.NoConnectionProvider, org.jooq.impl.ThreadLocalTransactionProvider.ThreadLocalConnectionProvider, org.jooq.impl.DefaultExecuteContext.ExecuteContextConnectionProvider, org.jooq.tools.jdbc.MockConnectionProvider
Imports
java.sql.Connection, org.jooq.exception.DataAccessException, .DetachedException, org.jetbrains.annotations.Nullable

A connection lifecycle handler API.

The ConnectionProvider allows for abstracting the handling of custom Connection lifecycles outside of jOOQ, injecting behaviour into jOOQ's internals. jOOQ will try to acquire a new JDBC Connection from the connection provider as early as needed, and will release it as early as possible.

TransactionProvider implementations may choose to influence ConnectionProvider behaviour, e.g. by acquiring connections upon TransactionProvider#begin(TransactionContext) and by releasing connections only upon TransactionProvider#commit(TransactionContext), or TransactionProvider#rollback(TransactionContext).

Authors
Aaron Digulla, Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public @Nullable Connection

Returns:

A connection for the current ExecuteContext. If null is returned (e.g. by NoConnectionProvider), then statements cannot be executed. Attempts to execute statements will result in a DetachedException.
acquire
()

Acquire a connection from the connection lifecycle handler.

public void
release(Connection
A connection that was previously obtained from acquire(). This is never null.
connection
)

Release a connection to the connection lifecycle handler.

Method Detail

acquireback to summary
public @Nullable Connection acquire() throws DataAccessException

Acquire a connection from the connection lifecycle handler.

This method is called by jOOQ exactly once per execution lifecycle, i.e. per ExecuteContext. Implementations may freely chose, whether subsequent calls to this method:

  • return the same connection instance
  • return the same connection instance for the same thread
  • return the same connection instance for the same transaction (e.g. a javax.transaction.UserTransaction)
  • return a fresh connection instance every time

jOOQ will guarantee that every acquired connection is released through release(Connection) exactly once.

Returns:@Nullable Connection

A connection for the current ExecuteContext. If null is returned (e.g. by NoConnectionProvider), then statements cannot be executed. Attempts to execute statements will result in a DetachedException.

Annotations
@Nullable
Exceptions
DataAccessException:
If anything went wrong while acquiring a connection
releaseback to summary
public void release(Connection connection) throws DataAccessException

Release a connection to the connection lifecycle handler.

jOOQ will guarantee that every acquired connection is released exactly once.

Parameters
connection:Connection

A connection that was previously obtained from acquire(). This is never null.

Exceptions
DataAccessException:
If anything went wrong while releasing a connection