-
Notifications
You must be signed in to change notification settings - Fork 22
Guice Persist
FluentJdbc has an extension library to support integration with Guice Persist.
<dependency>
<groupId>org.codejargon</groupId>
<artifactId>fluentjdbc-guice-persist</artifactId>
<version>0.9.1</version>
</dependency>Note: version should match FluentJdbc's version
It contains 2 modules to support:
- Standalone FluentJdbc - including transaction management
- Integration to Guice Persist with JPA (JpaPersistModule)
StandaloneFluentJdbcModule will set / override the ConnectionProvider with an own implementation and
binds FluentJdbc and Query instances to Guice container. @Transactional annotation can be used to
declare transactions.
Needs configuration of FluentJdbc (through FluentJdbcBuilder), and a DataSource (preferably one based on
a pool).
DataSource dataSource = ...
FluentJdbcBuilder builder = new FluentJdbcBuilder()...
StandaloneFluentJdbcModule fluentJdbcModule = new StandaloneFluentJdbcModule(builder, dataSource);
install(fluentJdbcModule);JpaFluentJdbcModule can be used in conjunction with JpaPersistModule to integrate seamlessly with JPA
(including transactions). The module will override the ConnectionProvider with an own implementation
that extracts Connections from the JPA EntityManager.
Extraction of Connections from an EntityManager requires the use of vendor specific API. The modules
also needs configuration of FluentJdbc (through FluentJdbcBuilder)
FluentJdbcBuilder fluentJdbcBuilder = new FluentJdbcBuilder()...
JpaConnectionExtractor extractor = ...
JpaFluentJdbcModule fluentJdbcModule = new JpaFluentJdbcModule(fluentJdbcBuilder, extractor);
install(..., jpaPersistModule, fluentJdbcModule, ...)Examples for JpaConnectionExtractor:
JpaConnectionExtractor extractor = entityManager -> {
return entityManager.unwrap(java.sql.Connection.class);
}JpaConnectionExtractor extractor = entityManager -> {
Session session = entityManager.unwrap(Session.class);
SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
return sfi.getConnectionProvider().getConnection();
}