@FunctionalInterface public interface ConnectionProvider
Provides Connections to FluentJdbc Queries. It allows both acquiring and releasing a Connection. This makes it possible to integrate FluentJdbc to most pooling / transaction management solutions.
Implementation pattern
query -> { Connection connection = ... // acquire a connection query.receive(connection) // make the connection available to FluentJdbc queries connection.close() // release connection - may not be needed if connection is already managed }
Example implementations:
Getting connection from a datasource (provided in the library as DataSourceConnectionProvider):
query -> { try(Connection connection = dataSource.getConnection()) { query.receive(connection); } }
Getting connection from a callback mechanism (eg Spring JdbcOperations/JdbcTemplate):
query -> { jdbcTemplate.execute(connection -> { query.receive(connection); }); }
Modifier and Type | Method and Description |
---|---|
void |
provide(QueryConnectionReceiver query) |
void provide(QueryConnectionReceiver query) throws SQLException
SQLException
Copyright © 2016. All rights reserved.