Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Guice-persist extension for using jOOQ based persistence layer
Java
Branch: master
Failed to load latest commit information.
src/main/java/com/adamlewis/guice/persist/jooq
LICENSE
NOTES.md
NOTICE Adding licensing information
README.md
pom.xml

README.md

Guice Persist / jOOQ Integration

A simple integration between Guice's persistence extensions and jOOQ. Follows closely in the pattern of of the JPA persistence extension written by Dhanji R. Prasanna (dhanji@gmail.com).

Maven Coordinates

The project is deployed to Maven Central:

<dependency>
   <groupId>com.adamlewis</groupId>
   <artifactId>guice-persist-jooq</artifactId>
   <version>0.1.2</version>
</dependency>

Basic Usage

See Guice Persist and Transactions and Units of Work for a reference on the basic semantics of the Guice Persist extension.

In your module, install a new com.adamlewis.guice.persist.jooq.JooqPersistModule and then provide bindings for javax.sql.DataSource and org.jooq.SQLDialect. Then write @Injectable DAOs which depend on org.jooq.DSLContext.

Example

Here is an example Guice module written to connect guice-persist-jooq up to the Dropwizard connection factory:

import javax.sql.DataSource;

import org.jooq.SQLDialect;

import com.adamlewis.guice.persist.jooq.JooqPersistModule;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.yammer.dropwizard.db.DatabaseConfiguration;
import com.yammer.dropwizard.db.ManagedDataSource;
import com.yammer.dropwizard.db.ManagedDataSourceFactory;

public class MyPersistenceModule extends AbstractModule {

    private final DatabaseConfiguration configuration;

    public MyPersistenceModule(final DatabaseConfiguration configuration) {
        this.configuration = configuration;
    }

    @Override
    protected void configure() {
        install(new JooqPersistModule());
        bind(DataSource.class).to(ManagedDataSource.class);
    }


    @Provides ManagedDataSource dataSource(final ManagedDataSourceFactory factory) throws ClassNotFoundException {
        return factory.build(configuration);
    }

    @Provides
    public SQLDialect dialect() {
        //TODO read from DB configuration
        return SQLDialect.POSTGRES;
    }
}

And here is an example of what a DAO might look like:

public class UserDao {

    private final DSLContext create;

    @Inject
    public UserDao(final DSLContext dsl) {
        this.create = dsl;
    }


    public List<String> getUsernames() {
        return create.selectDistinct(User.USER.NAME).from(User.USER).fetch(User.USER.NAME);
    }   
}
Something went wrong with that request. Please try again.