public DBI build(Environment environment,
DataSourceFactory configuration,
ManagedDataSource dataSource,
String name) {
final String validationQuery = configuration.getValidationQuery();
final DBI dbi = new DBI(dataSource);
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name, new DBIHealthCheck(dbi, validationQuery));
dbi.setSQLLog(new LogbackLog(LOGGER, Level.TRACE));
dbi.setTimingCollector(new InstrumentedTimingCollector(environment.metrics(),
new SanerNamingStrategy()));
if (configuration.isAutoCommentsEnabled()) {
dbi.setStatementRewriter(new NamePrependingStatementRewriter(new ColonPrefixNamedParamStatementRewriter()));
}
dbi.registerArgumentFactory(new OptionalArgumentFactory(configuration.getDriverClass()));
dbi.registerContainerFactory(new ImmutableListContainerFactory());
dbi.registerContainerFactory(new ImmutableSetContainerFactory());
dbi.registerContainerFactory(new OptionalContainerFactory());
dbi.registerArgumentFactory(new JodaDateTimeArgumentFactory());
dbi.registerMapper(new JodaDateTimeMapper());
return dbi;
}