Search in sources :

Example 1 with PostgresPlugin

use of org.jdbi.v3.postgres.PostgresPlugin in project baremaps by baremaps.

the class Studio method call.

@Override
public Integer call() throws Exception {
    // Configure serialization
    ObjectMapper mapper = defaultObjectMapper();
    // Configure jdbi and set the ObjectMapper
    DataSource datasource = PostgresUtils.datasource(this.database);
    Jdbi jdbi = Jdbi.create(datasource).installPlugin(new PostgresPlugin()).installPlugin(new Jackson2Plugin()).configure(Jackson2Config.class, config -> config.setMapper(mapper));
    // Initialize the application
    ResourceConfig application = new ResourceConfig().registerClasses(SwaggerResource.class, RootResource.class, CorsFilter.class, ConformanceResource.class, CollectionsResource.class, StylesResource.class, TilesetsResource.class, StudioResource.class, ImportResource.class, MultiPartFeature.class).register(new ApiResource("studio-openapi.yaml")).register(contextResolverFor(mapper)).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(datasource).to(DataSource.class);
            bind(jdbi).to(Jdbi.class);
        }
    });
    BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
    ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
    logger.info("Listening on {}", serverContext.listenAddress());
    serverContext.awaitShutdown();
    return 0;
}
Also used : SwaggerResource(com.baremaps.server.ogcapi.SwaggerResource) RootResource(com.baremaps.server.ogcapi.RootResource) CorsFilter(com.baremaps.server.common.CorsFilter) Jdbi(org.jdbi.v3.core.Jdbi) ApiResource(com.baremaps.server.ogcapi.ApiResource) ConformanceResource(com.baremaps.server.ogcapi.ConformanceResource) StylesResource(com.baremaps.server.ogcapi.StylesResource) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin) DataSource(javax.sql.DataSource) HttpJerseyRouterBuilder(io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) ServerContext(io.servicetalk.transport.api.ServerContext) ImportResource(com.baremaps.server.studio.ImportResource) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) CollectionsResource(com.baremaps.server.ogcapi.CollectionsResource) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) StudioResource(com.baremaps.server.studio.StudioResource) TilesetsResource(com.baremaps.server.ogcapi.TilesetsResource) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PostgresPlugin

use of org.jdbi.v3.postgres.PostgresPlugin in project cudami by dbmdz.

the class SpringConfigBackendDatabase method jdbi.

@Bean
public JdbiFactoryBean jdbi(DataSource ds, ObjectMapper objectMapper) throws Exception {
    JdbiFactoryBean jdbiFactoryBean = new JdbiFactoryBean(ds);
    List plugins = new ArrayList();
    plugins.add(new SqlObjectPlugin());
    plugins.add(new PostgresPlugin());
    plugins.add(new DcCommonsJdbiPlugin());
    plugins.add(new JsonbJdbiPlugin(objectMapper));
    jdbiFactoryBean.setPlugins(plugins);
    return jdbiFactoryBean;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SqlObjectPlugin(org.jdbi.v3.sqlobject.SqlObjectPlugin) JdbiFactoryBean(org.jdbi.v3.spring5.JdbiFactoryBean) DcCommonsJdbiPlugin(de.digitalcollections.commons.jdbi.DcCommonsJdbiPlugin) JsonbJdbiPlugin(de.digitalcollections.cudami.server.backend.impl.jdbi.plugins.JsonbJdbiPlugin) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin) JdbiFactoryBean(org.jdbi.v3.spring5.JdbiFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with PostgresPlugin

use of org.jdbi.v3.postgres.PostgresPlugin in project cudami by dbmdz.

the class SpringConfigBackendDatabase method jdbi.

@Bean
Jdbi jdbi(ObjectMapper objectMapper, DataSource dataSource) {
    Jdbi jdbi = Jdbi.create(dataSource);
    jdbi.installPlugin(new SqlObjectPlugin());
    jdbi.installPlugin(new DcCommonsJdbiPlugin());
    jdbi.installPlugin(new PostgresPlugin());
    jdbi.installPlugin(new JsonbJdbiPlugin(objectMapper));
    if (!isMigrated) {
        synchronized (isMigrated) {
            Map<String, String> placeholders = Map.of("iiifBaseUrl", "foo");
            Flyway flyway = Flyway.configure().dataSource(dataSource).placeholders(placeholders).locations("classpath:/de/digitalcollections/cudami/server/backend/impl/database/migration").load();
            flyway.migrate();
            isMigrated = true;
        }
    }
    return jdbi;
}
Also used : Flyway(org.flywaydb.core.Flyway) Jdbi(org.jdbi.v3.core.Jdbi) SqlObjectPlugin(org.jdbi.v3.sqlobject.SqlObjectPlugin) DcCommonsJdbiPlugin(de.digitalcollections.commons.jdbi.DcCommonsJdbiPlugin) JsonbJdbiPlugin(de.digitalcollections.cudami.server.backend.impl.jdbi.plugins.JsonbJdbiPlugin) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin) Bean(org.springframework.context.annotation.Bean)

Example 4 with PostgresPlugin

use of org.jdbi.v3.postgres.PostgresPlugin in project nzyme by lennartkoopmann.

the class Database method initializeAndMigrate.

public void initializeAndMigrate() throws LiquibaseException {
    this.jdbi = Jdbi.create("jdbc:" + configuration.databasePath()).installPlugin(new PostgresPlugin()).installPlugin(new JodaTimePlugin()).registerRowMapper(new MeasurementMapper()).registerRowMapper(new BeaconRateMapper()).registerRowMapper(new SignalIndexHistogramHistoryDBEntryMapper()).registerRowMapper(new AlertDatabaseEntryMapper()).registerRowMapper(new BanditMapper()).registerRowMapper(new BanditIdentifierMapper()).registerRowMapper(new ContactMapper()).registerRowMapper(new SentrySSIDMapper()).registerRowMapper(new DeauthenticationMonitorRecordingMapper()).registerRowMapper(new EventRecordMapper()).registerRowMapper(new ScheduledReportEntryMapper()).registerRowMapper(new ExecutionLogEntryMapper()).registerRowMapper(new ContactRecordMapper()).registerRowMapper(new ContactRecordValueAggregationMapper()).registerRowMapper(new ContactRecorderHistogramEntryMapper());
    // Run migrations against underlying JDBC connection.
    JdbcConnection connection = new JdbcConnection(jdbi.open().getConnection());
    try {
        liquibase.database.Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        Liquibase liquibase = new liquibase.Liquibase("db/migrations.xml", new ClassLoaderResourceAccessor(), database);
        liquibase.update(new Contexts(), new LabelExpression());
    } finally {
        connection.close();
    }
}
Also used : ExecutionLogEntryMapper(horse.wtf.nzyme.reporting.db.ExecutionLogEntryMapper) DeauthenticationMonitorRecordingMapper(horse.wtf.nzyme.dot11.deauth.db.DeauthenticationMonitorRecordingMapper) JodaTimePlugin(org.jdbi.v3.jodatime2.JodaTimePlugin) BeaconRateMapper(horse.wtf.nzyme.dot11.networks.beaconrate.BeaconRateMapper) SignalIndexHistogramHistoryDBEntryMapper(horse.wtf.nzyme.dot11.networks.signalstrength.SignalIndexHistogramHistoryDBEntryMapper) JdbcConnection(liquibase.database.jvm.JdbcConnection) Contexts(liquibase.Contexts) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin) Liquibase(liquibase.Liquibase) SentrySSIDMapper(horse.wtf.nzyme.dot11.networks.sentry.db.SentrySSIDMapper) horse.wtf.nzyme.bandits.database(horse.wtf.nzyme.bandits.database) MeasurementMapper(horse.wtf.nzyme.measurements.mappers.MeasurementMapper) EventRecordMapper(horse.wtf.nzyme.events.db.EventRecordMapper) LabelExpression(liquibase.LabelExpression) AlertDatabaseEntryMapper(horse.wtf.nzyme.alerts.service.AlertDatabaseEntryMapper) ScheduledReportEntryMapper(horse.wtf.nzyme.reporting.db.ScheduledReportEntryMapper) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 5 with PostgresPlugin

use of org.jdbi.v3.postgres.PostgresPlugin 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);
    }
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) JdbiFactory(io.dropwizard.jdbi3.JdbiFactory) TracingSQLLogger(marquez.tracing.TracingSQLLogger) InstrumentedSqlLogger(com.codahale.metrics.jdbi3.InstrumentedSqlLogger) SqlObjectPlugin(org.jdbi.v3.sqlobject.SqlObjectPlugin) SqlLogger(org.jdbi.v3.core.statement.SqlLogger) InstrumentedSqlLogger(com.codahale.metrics.jdbi3.InstrumentedSqlLogger) PostgresPlugin(org.jdbi.v3.postgres.PostgresPlugin)

Aggregations

PostgresPlugin (org.jdbi.v3.postgres.PostgresPlugin)5 Jdbi (org.jdbi.v3.core.Jdbi)3 SqlObjectPlugin (org.jdbi.v3.sqlobject.SqlObjectPlugin)3 DcCommonsJdbiPlugin (de.digitalcollections.commons.jdbi.DcCommonsJdbiPlugin)2 JsonbJdbiPlugin (de.digitalcollections.cudami.server.backend.impl.jdbi.plugins.JsonbJdbiPlugin)2 Bean (org.springframework.context.annotation.Bean)2 CorsFilter (com.baremaps.server.common.CorsFilter)1 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)1 ApiResource (com.baremaps.server.ogcapi.ApiResource)1 CollectionsResource (com.baremaps.server.ogcapi.CollectionsResource)1 ConformanceResource (com.baremaps.server.ogcapi.ConformanceResource)1 RootResource (com.baremaps.server.ogcapi.RootResource)1 StylesResource (com.baremaps.server.ogcapi.StylesResource)1 SwaggerResource (com.baremaps.server.ogcapi.SwaggerResource)1 TilesetsResource (com.baremaps.server.ogcapi.TilesetsResource)1 ImportResource (com.baremaps.server.studio.ImportResource)1 StudioResource (com.baremaps.server.studio.StudioResource)1 InstrumentedSqlLogger (com.codahale.metrics.jdbi3.InstrumentedSqlLogger)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AlertDatabaseEntryMapper (horse.wtf.nzyme.alerts.service.AlertDatabaseEntryMapper)1