226226import org .jooby .funzy .Try ;
227227
228228import javax .sql .DataSource ;
229- import java .util .ArrayList ;
230229import java .util .Arrays ;
231230import java .util .HashMap ;
232231import java .util .HashSet ;
406405 */
407406public final class Jdbc implements Jooby .Module {
408407
409- static final Function <Throwable , Void > CCE = x -> {
410- if (x instanceof ClassCastException ) {
411- StackTraceElement src = x .getStackTrace ()[0 ];
412- if (src .getFileName () == null || src .getClassName ().equals (Jdbc .class .getName ())) {
413- return null ;
414- }
415- }
416- throw Throwing .sneakyThrow (x );
417- };
418-
419408 public static Function <String , String > DB_NAME = url -> {
420409 Throwing .Function3 <String , String , String , Object []> indexOf = (str , t1 ,
421410 t2 ) -> {
@@ -444,8 +433,7 @@ public final class Jdbc implements Jooby.Module {
444433
445434 private static final int DEFAULT_POOL_SIZE = 10 ;
446435
447- @ SuppressWarnings ("rawtypes" )
448- private final List <BiConsumer > callback = new ArrayList <>();
436+ private BiConsumer <HikariConfig , Config > callback ;
449437
450438 protected final String dbref ;
451439
@@ -471,40 +459,34 @@ public Jdbc() {
471459 }
472460
473461 /**
474- * Configurer callback to apply advanced configuration while bootstrapping hibernate :
462+ * Apply advanced configuration options :
475463 *
476464 * <pre>{@code
477465 * {
478466 * use(new Jdbc()
479- * .doWith((HikariConfig conf) -> {
480- * // do with conf
481- * })
482- * .doWith((HikariDataSource ds) -> {
483- * // do with ds
467+ * .doWith((hikari, conf) -> {
468+ * // do with hikari
484469 * })
485470 * );
486471 * }
487472 * }</pre>
488473 *
489474 * @param configurer Configurer callback.
490- * @return This module
475+ * @return This module.
491476 */
492- public <T > Jdbc doWith (final BiConsumer <T , Config > configurer ) {
493- this .callback . add ( requireNonNull (configurer , "Configurer required." ) );
477+ public <T > Jdbc doWith (final BiConsumer <HikariConfig , Config > configurer ) {
478+ this .callback = requireNonNull (configurer , "Callback required." );
494479 return this ;
495480 }
496481
497482 /**
498- * Configurer callback to apply advanced configuration while bootstrapping hibernate :
483+ * Apply advanced configuration options :
499484 *
500485 * <pre>{@code
501486 * {
502487 * use(new Jdbc()
503- * .doWith((HikariConfig conf) -> {
504- * // do with conf
505- * })
506- * .doWith((HikariDataSource ds) -> {
507- * // do with ds
488+ * .doWith(hikari -> {
489+ * // do with hikari
508490 * })
509491 * );
510492 * }
@@ -513,9 +495,9 @@ public <T> Jdbc doWith(final BiConsumer<T, Config> configurer) {
513495 * @param configurer Configurer callback.
514496 * @return This module
515497 */
516- public < T > Jdbc doWith (final Consumer <T > configurer ) {
498+ public Jdbc doWith (final Consumer <HikariConfig > configurer ) {
517499 requireNonNull (configurer , "Configurer required." );
518- return doWith ((final T b , final Config c ) -> configurer .accept (b ));
500+ return doWith ((h , c ) -> configurer .accept (h ));
519501 }
520502
521503 @ Override
@@ -543,7 +525,9 @@ public void configure(final Env env, final Config config, final Binder binder) {
543525 props .setProperty ("url" , url );
544526 }
545527
546- callback (hikariConf , config );
528+ if (callback != null ) {
529+ callback .accept (hikariConf , config );
530+ }
547531 HikariDataSource ds = new HikariDataSource (hikariConf );
548532
549533 // bind datasource using dbkey and dbname
@@ -680,15 +664,6 @@ private boolean dataSourcePresent(final ClassLoader loader, final String classNa
680664 }
681665 }
682666
683- @ SuppressWarnings ("unchecked" )
684- protected void callback (final Object value , final Config conf ) {
685- callback .forEach (it -> Try .apply (() -> {
686- it .accept (value , conf );
687- return null ;
688- // FIXME: review recover
689- }).recover (CCE ::apply ).get ());
690- }
691-
692667 private Optional <String > dbtype (final String url ) {
693668 String type = Arrays .stream (url .toLowerCase ().split (":" ))
694669 .filter (
0 commit comments