Search in sources :

Example 11 with SomethingMapper

use of org.jdbi.v3.core.mapper.SomethingMapper in project jdbi by jdbi.

the class TestNewApiOnDbiAndHandle method setUp.

@Before
public void setUp() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:" + 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))");
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Before(org.junit.Before)

Example 12 with SomethingMapper

use of org.jdbi.v3.core.mapper.SomethingMapper in project jdbi by jdbi.

the class TestReentrancy method setUp.

@Before
public void setUp() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    // 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))");
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Before(org.junit.Before)

Example 13 with SomethingMapper

use of org.jdbi.v3.core.mapper.SomethingMapper 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 14 with SomethingMapper

use of org.jdbi.v3.core.mapper.SomethingMapper 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)

Example 15 with SomethingMapper

use of org.jdbi.v3.core.mapper.SomethingMapper in project jdbi by jdbi.

the class BindBeanListTest method init.

@BeforeClass
public static void init() {
    final Jdbi db = dbRule.getJdbi();
    db.installPlugin(new SqlObjectPlugin());
    db.registerRowMapper(new SomethingMapper());
    handle = db.open();
    handle.execute("insert into something(id, name) values(1, '1')");
    handle.execute("insert into something(id, name) values(2, '2')");
    // "control group" element that should *not* be returned by the queries
    handle.execute("insert into something(id, name) values(3, '3')");
    expectedSomethings = Arrays.asList(new Something(1, "1"), new Something(2, "2"));
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) Jdbi(org.jdbi.v3.core.Jdbi) Something(org.jdbi.v3.core.Something) BeforeClass(org.junit.BeforeClass)

Aggregations

SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)16 Something (org.jdbi.v3.core.Something)8 Test (org.junit.Test)8 Handle (org.jdbi.v3.core.Handle)7 Before (org.junit.Before)6 GenericType (org.jdbi.v3.core.generic.GenericType)4 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)3 Jdbi (org.jdbi.v3.core.Jdbi)3 NoSuchMapperException (org.jdbi.v3.core.mapper.NoSuchMapperException)3 BeforeClass (org.junit.BeforeClass)3 Tuple2 (io.vavr.Tuple2)1 Tuple3 (io.vavr.Tuple3)1 Connection (java.sql.Connection)1