Search in sources :

Example 16 with GenericType

use of org.jdbi.v3.core.generic.GenericType in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple3WithoutSpecifiedColumn_shouldFail.

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

Example 17 with GenericType

use of org.jdbi.v3.core.generic.GenericType in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple3WithAllSpecifiedColumns_shouldRespectConfiguration.

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

Example 18 with GenericType

use of org.jdbi.v3.core.generic.GenericType in project jdbi by jdbi.

the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple3WithOnlyOneSpecifiedColumn_shouldFail.

@Test
public void testMapTuple3WithOnlyOneSpecifiedColumn_shouldFail() throws SQLException {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(new SomethingMapper());
    handle.configure(TupleMappers.class, c -> c.setColumn(1, "integerValue"));
    assertThatThrownBy(() -> handle.createQuery("select * from something where id = 1").mapTo(new GenericType<Tuple3<Integer, Something, Integer>>() {
    }).findOnly()).isInstanceOf(NoSuchMapperException.class).isInstanceOf(NoSuchMapperException.class).hasMessageContaining("TupleMappers config class");
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) GenericType(org.jdbi.v3.core.generic.GenericType) Something(org.jdbi.v3.core.Something) NoSuchMapperException(org.jdbi.v3.core.mapper.NoSuchMapperException) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 GenericType (org.jdbi.v3.core.generic.GenericType)11 Handle (org.jdbi.v3.core.Handle)10 Something (org.jdbi.v3.core.Something)6 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)6 Collector (java.util.stream.Collector)5 Type (java.lang.reflect.Type)3 Map (java.util.Map)3 GenericTypes.getErasedType (org.jdbi.v3.core.generic.GenericTypes.getErasedType)3 GenericTypes.resolveMapEntryType (org.jdbi.v3.core.generic.GenericTypes.resolveMapEntryType)3 NoSuchMapperException (org.jdbi.v3.core.mapper.NoSuchMapperException)3 Optional (com.google.common.base.Optional)2 BiMap (com.google.common.collect.BiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Tuple2 (io.vavr.Tuple2)2 HashMap (io.vavr.collection.HashMap)2 JdbiCollectors (org.jdbi.v3.core.collector.JdbiCollectors)2 Tuple3 (io.vavr.Tuple3)1 Map (io.vavr.collection.Map)1 Multimap (io.vavr.collection.Multimap)1