use of org.jdbi.v3.core.statement.SqlLogger in project ADP-Core by AlessioDP.
the class SQLDispatcher method init.
@Override
public void init() {
// Initialize DAO
connectionFactory = initConnectionFactory();
// Check if initialized
if (connectionFactory != null) {
connectionFactory.init();
// Check for failures
if (!connectionFactory.isFailed()) {
// Setup logger
connectionFactory.getJdbi().setSqlLogger(new SqlLogger() {
@Override
public void logBeforeExecution(StatementContext context) {
plugin.getLoggerManager().logDebug(String.format(Constants.DEBUG_DB_QUERY_EXECUTE, context.getRenderedSql()), true);
}
});
try {
MigratorConfiguration migratorConfiguration = prepareMigrator();
migrateTables(migratorConfiguration.load(plugin, this));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
}
use of org.jdbi.v3.core.statement.SqlLogger in project nia-patient-switching-standard-adaptor by NHSDigital.
the class DbConnectorConfiguration method jdbi.
@Bean
public Jdbi jdbi(DataSource ds, List<JdbiPlugin> jdbiPlugins, List<RowMapper<?>> rowMappers) {
TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds);
Jdbi jdbi = Jdbi.create(proxy);
SqlLogger sqlLogger = new SqlLogger() {
@Override
public void logAfterExecution(StatementContext context) {
LOGGER.debug("sql {}, parameters {}, timeTaken {} ms", context.getRenderedSql(), context.getBinding().toString(), context.getElapsedTime(ChronoUnit.MILLIS));
}
};
jdbi.setSqlLogger(sqlLogger);
jdbiPlugins.forEach(jdbi::installPlugin);
rowMappers.forEach(jdbi::registerRowMapper);
return jdbi;
}
use of org.jdbi.v3.core.statement.SqlLogger in project jdbi by jdbi.
the class TestTimestamped method before.
@BeforeEach
public void before() {
TimestampedFactory.setTimeSource(clock::withZone);
final Jdbi db = h2Extension.getJdbi();
db.getConfig(TimestampedConfig.class).setTimezone(GMT_PLUS_2);
db.setSqlLogger(new SqlLogger() {
@Override
public void logBeforeExecution(StatementContext ctx) {
String name = logNext.get();
if (name != null) {
String toString = ctx.getBinding().findForName(name, ctx).orElseThrow(AssertionError::new).toString();
insertedTimestamp.set(OffsetDateTime.parse(toString));
logNext.set(null);
}
}
});
personDAO = db.onDemand(PersonDAO.class);
personDAO.createTable();
}
use of org.jdbi.v3.core.statement.SqlLogger in project marquez by MarquezProject.
the class MarquezApp method registerResources.
public void registerResources(@NonNull MarquezConfig config, @NonNull Environment env, @NonNull DataSource source) {
final JdbiFactory factory = new JdbiFactory();
final Jdbi jdbi = factory.build(env, config.getDataSourceFactory(), (ManagedDataSource) source, DB_POSTGRES).installPlugin(new SqlObjectPlugin()).installPlugin(new PostgresPlugin());
SqlLogger sqlLogger = new InstrumentedSqlLogger(env.metrics());
if (isSentryEnabled(config)) {
sqlLogger = new TracingSQLLogger(sqlLogger);
}
jdbi.setSqlLogger(sqlLogger);
final MarquezContext context = MarquezContext.builder().jdbi(jdbi).tags(config.getTags()).build();
if (config.getGraphql().isEnabled()) {
env.servlets().addServlet("api/v1-beta/graphql", context.getGraphqlServlet()).addMapping("/api/v1-beta/graphql", "/api/v1/schema.json");
}
log.debug("Registering resources...");
for (final Object resource : context.getResources()) {
env.jersey().register(resource);
}
}
use of org.jdbi.v3.core.statement.SqlLogger in project Hangar by HangarMC.
the class JDBIConfig method jdbi.
@Bean
public Jdbi jdbi(DataSource dataSource, List<JdbiPlugin> jdbiPlugins, List<RowMapper<?>> rowMappers, List<RowMapperFactory> rowMapperFactories, List<ColumnMapper<?>> columnMappers) {
SqlLogger myLogger = new SqlLogger() {
@Override
public void logException(StatementContext context, SQLException ex) {
Logger.getLogger("sql").info("sql: " + context.getRenderedSql());
}
@Override
public void logAfterExecution(StatementContext context) {
Logger.getLogger("sql").info("sql ae: " + context.getRenderedSql());
}
};
TransactionAwareDataSourceProxy dataSourceProxy = new TransactionAwareDataSourceProxy(dataSource);
Jdbi jdbi = Jdbi.create(dataSourceProxy);
// jdbi.setSqlLogger(myLogger); // for debugging sql statements
PostgresTypes config = jdbi.getConfig(PostgresTypes.class);
jdbiPlugins.forEach(jdbi::installPlugin);
rowMappers.forEach(jdbi::registerRowMapper);
rowMapperFactories.forEach(jdbi::registerRowMapper);
columnMappers.forEach(jdbi::registerColumnMapper);
config.registerCustomType(PGLoggedAction.class, "logged_action_type");
config.registerCustomType(RoleCategory.class, "role_category");
config.registerCustomType(JobState.class, "job_state");
config.registerCustomType(JSONB.class, "jsonb");
return jdbi;
}
Aggregations