All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mlk.guice.JdbiSuppler Maven / Gradle / Ivy

package com.github.mlk.guice;

import com.google.inject.Inject;
import com.google.inject.Injector;
import org.skife.jdbi.v2.DBI;

import java.util.function.Function;

public class JdbiSuppler implements Function, Object> {
    private final DBI dbi;
    private Injector injector;

    JdbiSuppler(DBI dbi) {
        this.dbi = dbi;
    }

    @Inject
    public void setInjector(Injector injector) {
        this.injector = injector;
    }

    @Override
    public Object apply(Class aClass) {
        DBI dbi = this.dbi;
        if(dbi == null) {
            dbi = injector.getInstance(DBI.class);
        }
        return dbi.onDemand(aClass);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy