use of org.jdbi.v3.sqlobject.HandlerFactory in project jdbi by jdbi.
the class TestUseCustomHandlerFactory method setUp.
@Before
public void setUp() throws Exception {
Jdbi db = dbRule.getJdbi();
HandlerFactory defaultHandlerFactory = new HandlerFactory() {
@Override
public Optional<Handler> buildHandler(Class<?> sqlObjectType, Method method) {
return getImplementation(sqlObjectType, method).map(m -> (Handler) (target, args, handle) -> m.invoke(null, Stream.concat(Stream.of(target), Stream.of(args)).toArray()));
}
private Optional<Method> getImplementation(Class<?> type, Method method) {
return Stream.of(type.getClasses()).filter(c -> c.getSimpleName().equals("DefaultImpls")).flatMap(c -> Stream.of(c.getMethods()).filter(m -> m.getName().equals(method.getName()))).findAny();
}
};
db.configure(Handlers.class, c -> c.register(defaultHandlerFactory));
handle = db.open();
}
Aggregations