Search in sources :

Example 41 with Handle

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

the class TestClasspathSqlLocator method testCommentsInExternalSql.

@Test
public void testCommentsInExternalSql() throws Exception {
    Handle h = dbRule.openHandle();
    h.execute(findSqlOnClasspath("insert-eric-with-comments"));
    assertThat(h.select("select name from something").mapTo(String.class).list()).hasSize(1);
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 42 with Handle

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

the class TestEnums method testMapToEnum.

@Test
public void testMapToEnum() throws Exception {
    Handle h = dbRule.openHandle();
    h.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
    h.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
    List<SomethingElse.Name> results = h.createQuery("select name from something order by id").mapTo(SomethingElse.Name.class).list();
    assertThat(results).containsExactly(SomethingElse.Name.eric, SomethingElse.Name.brian);
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 43 with Handle

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

the class BeanMapperTest method testNestedPrefix.

@Test
public void testNestedPrefix() {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(BeanMapper.factory(NestedPrefixBean.class));
    handle.execute("insert into something (id, name) values (1, 'foo')");
    assertThat(handle.createQuery("select id nested_id, name nested_name from something").mapTo(NestedPrefixBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 44 with Handle

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

the class BeanMapperTest method testNested.

@Test
public void testNested() {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(BeanMapper.factory(NestedBean.class));
    handle.execute("insert into something (id, name) values (1, 'foo')");
    assertThat(handle.createQuery("select id, name from something").mapTo(NestedBean.class).findOnly()).extracting("nested.id", "nested.name").containsExactly(1, "foo");
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 45 with Handle

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

the class BeanMapperTest method testColumnNameAnnotation.

@Test
public void testColumnNameAnnotation() {
    Handle handle = dbRule.getSharedHandle();
    handle.registerRowMapper(BeanMapper.factory(ColumnNameBean.class));
    handle.execute("insert into something (id, name) values (1, 'foo')");
    ColumnNameBean bean = handle.createQuery("select * from something").mapTo(ColumnNameBean.class).findOnly();
    assertThat(bean.getI()).isEqualTo(1);
    assertThat(bean.getS()).isEqualTo("foo");
}
Also used : 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