Interface ConnectionProvider
-
- All Known Implementing Classes:
DataSourceConnectionProvider
,DefaultConnectionProvider
,MockConnectionProvider
,NoConnectionProvider
public interface ConnectionProvider
A connection lifecycle handler API.The
ConnectionProvider
allows for abstracting the handling of customConnection
lifecycles outside of jOOQ, injecting behaviour into jOOQ's internals. jOOQ will try to acquire a new JDBCConnection
from the connection provider as early as needed, and will release it as early as possible.TransactionProvider
implementations may choose to influenceConnectionProvider
behaviour, e.g. by acquiring connections uponTransactionProvider.begin(TransactionContext)
and by releasing connections only uponTransactionProvider.commit(TransactionContext)
, orTransactionProvider.rollback(TransactionContext)
.- Author:
- Aaron Digulla, Lukas Eder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.sql.Connection
acquire()
Acquire a connection from the connection lifecycle handler.void
release(java.sql.Connection connection)
Release a connection to the connection lifecycle handler.
-
-
-
Method Detail
-
acquire
java.sql.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:
- A connection for the current
ExecuteContext
. - Throws:
DataAccessException
- If anything went wrong while acquiring a connection
-
release
void release(java.sql.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
- A connection that was previously obtained fromacquire()
. This is nevernull
.- Throws:
DataAccessException
- If anything went wrong while releasing a connection
-
-