Search in sources :

Example 1 with PostgresTypes

use of org.jdbi.v3.postgres.PostgresTypes 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;
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SQLException(java.sql.SQLException) TransactionAwareDataSourceProxy(org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy) PostgresTypes(org.jdbi.v3.postgres.PostgresTypes) SqlLogger(org.jdbi.v3.core.statement.SqlLogger) StatementContext(org.jdbi.v3.core.statement.StatementContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

SQLException (java.sql.SQLException)1 Jdbi (org.jdbi.v3.core.Jdbi)1 SqlLogger (org.jdbi.v3.core.statement.SqlLogger)1 StatementContext (org.jdbi.v3.core.statement.StatementContext)1 PostgresTypes (org.jdbi.v3.postgres.PostgresTypes)1 Bean (org.springframework.context.annotation.Bean)1 TransactionAwareDataSourceProxy (org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy)1