io.dropwizard.jdbi.OptionalContainerFactory Maven / Gradle / Ivy
package io.dropwizard.jdbi;
import org.skife.jdbi.v2.ContainerBuilder;
import org.skife.jdbi.v2.tweak.ContainerFactory;
import java.util.Optional;
public class OptionalContainerFactory implements ContainerFactory> {
@Override
public boolean accepts(Class> type) {
return Optional.class.isAssignableFrom(type);
}
@Override
public ContainerBuilder> newContainerBuilderFor(Class> type) {
return new OptionalContainerBuilder();
}
private static class OptionalContainerBuilder implements ContainerBuilder> {
private Optional> optional = Optional.empty();
@Override
public ContainerBuilder> add(Object it) {
optional = Optional.ofNullable(it);
return this;
}
@Override
public Optional> build() {
return optional;
}
}
}