Search in sources :

Example 11 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrOptionMapperWithDB method addData.

@Before
public void addData() {
    Handle handle = dbRule.openHandle();
    handle.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
    handle.createUpdate("insert into something (id) values (2)").execute();
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Example 12 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple3WithExtraSpecifiedColumn_shouldSucceed.

@Test
public void testMapTuple3WithExtraSpecifiedColumn_shouldSucceed() throws SQLException {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(new SomethingMapper());
    handle.configure(TupleMappers.class, c -> c.setColumn(2, "integerValue").setColumn(3, "intValue"));
    Tuple3<Something, Integer, Integer> result = handle.createQuery("select * from something where id = 1").mapTo(new GenericType<Tuple3<Something, Integer, Integer>>() {
    }).findOnly();
    assertThat(result._1).isEqualTo(new Something(1, "eric"));
    assertThat(result._2).isEqualTo(99);
    assertThat(result._3).isEqualTo(100);
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) GenericType(org.jdbi.v3.core.generic.GenericType) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 13 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple2UsingRegisteredRowMappers_shouldSucceed.

@Test
public void testMapTuple2UsingRegisteredRowMappers_shouldSucceed() throws SQLException {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(new SomethingMapper());
    handle.registerRowMapper(SomethingValues.class, (rs, ctx) -> new SomethingValues(rs.getInt("integerValue"), rs.getInt("intValue")));
    Tuple2<Something, SomethingValues> result = handle.createQuery("select * from something where id = 2").mapTo(new GenericType<Tuple2<Something, SomethingValues>>() {
    }).findOnly();
    assertThat(result._1).isEqualTo(new Something(2, "brian"));
    assertThat(result._2).isEqualTo(new SomethingValues(101, 102));
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) GenericType(org.jdbi.v3.core.generic.GenericType) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 14 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method addData.

@Before
public void addData() {
    Handle handle = dbRule.openHandle();
    handle.createUpdate("insert into something (id, name, integerValue, intValue) values (1, 'eric', 99, 100)").execute();
    handle.createUpdate("insert into something (id, name, integerValue, intValue) values (2, 'brian', 101, 102)").execute();
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Example 15 with Handle

use of org.jdbi.v3.core.Handle in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple2HavingOnlyOneRowMapper_shouldFail.

@Test
public void testMapTuple2HavingOnlyOneRowMapper_shouldFail() throws SQLException {
    final Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(new SomethingMapper());
    assertThatThrownBy(() -> handle.createQuery("select * from something where id = 1").mapTo(new GenericType<Tuple2<Something, SomethingValues>>() {
    }).findOnly()).isInstanceOf(NoSuchMapperException.class).hasMessageContaining("SomethingValues");
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) Tuple2(io.vavr.Tuple2) NoSuchMapperException(org.jdbi.v3.core.mapper.NoSuchMapperException) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Handle (org.jdbi.v3.core.Handle)134 Test (org.junit.Test)124 Jdbi (org.jdbi.v3.core.Jdbi)36 Something (org.jdbi.v3.core.Something)29 Before (org.junit.Before)21 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 Namespace (net.sourceforge.argparse4j.inf.Namespace)11 Test (org.junit.jupiter.api.Test)11 SQLException (java.sql.SQLException)10 Query (org.jdbi.v3.core.statement.Query)8 Map (java.util.Map)7 Update (org.jdbi.v3.core.statement.Update)7 GenericType (org.jdbi.v3.core.generic.GenericType)6 Rule (org.junit.Rule)5 List (java.util.List)4 BrokenDao (org.jdbi.v3.sqlobject.subpackage.BrokenDao)4 SomethingDao (org.jdbi.v3.sqlobject.subpackage.SomethingDao)4 ArrayList (java.util.ArrayList)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 JdbiPlugin (org.jdbi.v3.core.spi.JdbiPlugin)3