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

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

package com.github.mlk.guice;

import org.skife.jdbi.v2.DBI;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class JdbiModule extends ExternalCreationModule {

    private final List packagesToScan;
    private final Function, ?> function;

    JdbiModule(Function, ?> function, List packagesToScan) {
        super(function);
        this.packagesToScan = packagesToScan;
        this.function = function;
    }

    @Override
    protected void configure() {
        requestInjection(function);
        for(String scanPackage : packagesToScan) {
            scan(scanPackage);
        }
    }

    public static JdbiModuleBuilder builder() {
        return new JdbiModuleBuilder();
    }

    public static class JdbiModuleBuilder {
        private DBI builder;
        private final List packages = new ArrayList<>();

        public JdbiModuleBuilder withBuilder(DBI builder) {
            this.builder = builder;
            return this;

        }

        public JdbiModuleBuilder scan(String packageToScan) {
            packages.add(packageToScan);
            return this;
        }

        public JdbiModuleBuilder scan(String... packagesToScan) {
            for(String packageToScan : packagesToScan) {
                packages.add(packageToScan);
            }
            return this;
        }

        public JdbiModule build() {
            return new JdbiModule(new JdbiSuppler(builder), packages);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy