com.github.zhengframework.jdbc.JooqModule Maven / Gradle / Ivy
package com.github.zhengframework.jdbc;
import static com.google.inject.name.Names.named;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.multibindings.OptionalBinder;
import java.lang.annotation.Annotation;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
@EqualsAndHashCode(callSuper = false)
public class JooqModule extends AbstractModule {
private Annotation qualifier;
public JooqModule() {
this.qualifier = null;
}
public JooqModule(Annotation qualifier) {
this.qualifier = qualifier;
}
public JooqModule(String name) {
this.qualifier = named(Objects.requireNonNull(name));
}
@Override
protected void configure() {
DSLContextProvider dslContextProvider = new DSLContextProvider(qualifier,
getProvider(Injector.class));
if (qualifier == null) {
OptionalBinder.newOptionalBinder(binder(), Key.get(SQLDialect.class))
.setDefault().toInstance(SQLDialect.DEFAULT);
bind(Key.get(DSLContext.class)).toProvider(dslContextProvider);
} else {
OptionalBinder.newOptionalBinder(binder(), Key.get(SQLDialect.class, qualifier))
.setDefault().toInstance(SQLDialect.DEFAULT);
bind(Key.get(DSLContext.class, qualifier)).toProvider(dslContextProvider);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy