Class DataSourceConnectionProvider
- java.lang.Object
-
- org.jooq.impl.DataSourceConnectionProvider
-
- All Implemented Interfaces:
ConnectionProvider
public class DataSourceConnectionProvider extends java.lang.Object implements ConnectionProvider
A default implementation for a pooledDataSource
-orientedConnectionProvider
This implementation wraps a JDBC
DataSource
. jOOQ will use that data source for initialising connections, and creating statements.Use this connection provider if you want to run distributed transactions, such as
javax.transaction.UserTransaction
. jOOQ willclose()
all connections after query execution (and result fetching) in order to return the connection to the connection pool. If you do not use distributed transactions, this will produce driver-specific behaviour at the end of query execution atclose()
invocation (e.g. a transaction rollback). Use aDefaultConnectionProvider
instead, to control the connection's lifecycle, or implement your ownConnectionProvider
.- Author:
- Aaron Digulla, Lukas Eder
-
-
Constructor Summary
Constructors Constructor Description DataSourceConnectionProvider(javax.sql.DataSource dataSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.sql.Connection
acquire()
Acquire a connection from the connection lifecycle handler.javax.sql.DataSource
dataSource()
void
release(java.sql.Connection connection)
Release a connection to the connection lifecycle handler.
-
-
-
Method Detail
-
dataSource
public javax.sql.DataSource dataSource()
-
acquire
public java.sql.Connection acquire()
Description copied from interface:ConnectionProvider
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
ConnectionProvider.release(Connection)
exactly once.- Specified by:
acquire
in interfaceConnectionProvider
- Returns:
- A connection for the current
ExecuteContext
.
-
release
public void release(java.sql.Connection connection)
Description copied from interface:ConnectionProvider
Release a connection to the connection lifecycle handler.jOOQ will guarantee that every acquired connection is released exactly once.
- Specified by:
release
in interfaceConnectionProvider
- Parameters:
connection
- A connection that was previously obtained fromConnectionProvider.acquire()
. This is nevernull
.
-
-