use of org.jdbi.v3.core.mapper.SomethingMapper in project jdbi by jdbi.
the class TestTransactional method setUp.
@Before
public void setUp() throws Exception {
final JdbcDataSource ds = new JdbcDataSource() {
private static final long serialVersionUID = 1L;
@Override
public Connection getConnection() throws SQLException {
final Connection real = super.getConnection();
return (Connection) Proxy.newProxyInstance(real.getClass().getClassLoader(), new Class<?>[] { Connection.class }, new TxnIsolationCheckingInvocationHandler(real));
}
};
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
use of org.jdbi.v3.core.mapper.SomethingMapper 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);
}
use of org.jdbi.v3.core.mapper.SomethingMapper 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));
}
use of org.jdbi.v3.core.mapper.SomethingMapper 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");
}
use of org.jdbi.v3.core.mapper.SomethingMapper in project jdbi by jdbi.
the class TestVavrTupleRowMapperFactoryWithDB method testMapTuple1UsingRegisteredRowMapper_shouldSucceed.
@Test
public void testMapTuple1UsingRegisteredRowMapper_shouldSucceed() throws SQLException {
Handle handle = dbRule.getSharedHandle();
handle.registerRowMapper(new SomethingMapper());
Tuple1<Something> result = handle.createQuery("select id, name from something where id = 1").mapTo(new GenericType<Tuple1<Something>>() {
}).findOnly();
assertThat(result._1).isEqualTo(new Something(1, "eric"));
}
Aggregations