Search in sources :

Example 1 with PostgisPlugin

use of com.baremaps.postgres.jdbi.PostgisPlugin in project baremaps by baremaps.

the class ImportResourceIntegrationTest method configure.

@Override
protected ResourceConfig configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    // Create a datasource to a throwaway postgis database
    DataSource dataSource = PostgresUtils.datasource(DATABASE_URL);
    // Initialize the database
    jdbi = Jdbi.create(dataSource).installPlugin(new Jackson2Plugin()).installPlugin(new PostgisPlugin());
    jdbi.useHandle(handle -> handle.execute("create extension if not exists hstore;" + "create table collections (id uuid primary key, collection jsonb)"));
    // Configure the service
    return new ResourceConfig().registerClasses(MultiPartFeature.class, ImportResource.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(jdbi).to(Jdbi.class);
        }
    });
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) Jackson2Plugin(org.jdbi.v3.jackson2.Jackson2Plugin) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) PostgisPlugin(com.baremaps.postgres.jdbi.PostgisPlugin) DataSource(javax.sql.DataSource)

Example 2 with PostgisPlugin

use of com.baremaps.postgres.jdbi.PostgisPlugin in project baremaps by baremaps.

the class PostgisPluginTest method test.

@Test
@Tag("integration")
void test() {
    Jdbi jdbi = Jdbi.create("jdbc:tc:postgis:13-3.1:///test").installPlugin(new PostgisPlugin());
    PostgisRecord record = new PostgisRecord();
    record.setId(1);
    record.setPoint(new GeometryFactory().createPoint(new Coordinate(1, 1)));
    record.setLineString(new GeometryFactory().createLineString(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(2, 1) }));
    record.setPolygon(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(2, 1), new Coordinate(1, 1) }));
    List<PostgisRecord> result = jdbi.withHandle(handle -> {
        handle.execute("DROP TABLE IF EXISTS record");
        handle.execute("CREATE TABLE record (id INTEGER PRIMARY KEY, point geometry(point), linestring geometry(linestring), polygon geometry(polygon))");
        handle.createUpdate("INSERT INTO record (id, point, linestring, polygon) VALUES (:id, :point, :lineString, :polygon)").bindBean(record).execute();
        return handle.createQuery("SELECT * FROM record ORDER BY id").mapToBean(PostgisRecord.class).list();
    });
    assertEquals(record.getPoint(), result.get(0).getPoint());
    assertEquals(record.getLineString(), result.get(0).getLineString());
    assertEquals(record.getPolygon(), result.get(0).getPolygon());
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PostgisPlugin(com.baremaps.postgres.jdbi.PostgisPlugin) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

PostgisPlugin (com.baremaps.postgres.jdbi.PostgisPlugin)2 Jdbi (org.jdbi.v3.core.Jdbi)2 DataSource (javax.sql.DataSource)1 AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)1 MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 Jackson2Plugin (org.jdbi.v3.jackson2.Jackson2Plugin)1 Tag (org.junit.jupiter.api.Tag)1 Test (org.junit.jupiter.api.Test)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1