Search in sources :

Example 96 with Handle

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

the class TestClasspathSqlLocator method testUsefulExceptionForBackTracing.

@Test
public void testUsefulExceptionForBackTracing() throws Exception {
    Handle h = dbRule.openHandle();
    exception.expect(StatementException.class);
    exception.expectMessage("insert into something(id, name) values (:id, :name)");
    exception.expectMessage("insert into something(id, name) values (?, ?)");
    h.createUpdate(findSqlOnClasspath("insert-id-name")).bind("id", 1).execute();
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 97 with Handle

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

the class TestClasspathSqlLocator method testNamedParamsInExternal.

@Test
public void testNamedParamsInExternal() throws Exception {
    Handle h = dbRule.openHandle();
    h.createUpdate(findSqlOnClasspath("insert-id-name")).bind("id", 1).bind("name", "Tip").execute();
    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 98 with Handle

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

the class TestClasspathSqlLocator method testLocateNamed.

@Test
public void testLocateNamed() throws Exception {
    Handle h = dbRule.openHandle();
    h.execute(findSqlOnClasspath("insert-keith"));
    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 99 with Handle

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

the class MapOptionalTest method testMapOptional.

@Test
public void testMapOptional() throws Exception {
    final Handle h = db.getSharedHandle();
    h.execute("insert into something(intValue, name) values(1, 'Duke')");
    h.execute("insert into something(intValue, name) values(null, null)");
    assertThat(h.createQuery("select * from something order by id").map(ConstructorMapper.of(OptionalBean.class)).list()).extracting("intValue", "name").containsExactly(tuple(OptionalInt.of(1), Optional.of("Duke")), tuple(OptionalInt.empty(), Optional.empty()));
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 100 with Handle

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

the class TestEnums method testMapInvalidEnumValue.

@Test(expected = IllegalArgumentException.class)
public void testMapInvalidEnumValue() throws SQLException {
    Handle h = dbRule.openHandle();
    h.createUpdate("insert into something (id, name) values (1, 'joe')").execute();
    h.createQuery("select * from something order by id").mapToBean(SomethingElse.class).findFirst();
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)123 Handle (org.jdbi.v3.core.Handle)119 Jdbi (org.jdbi.v3.core.Jdbi)31 Something (org.jdbi.v3.core.Something)29 Before (org.junit.Before)20 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 SQLException (java.sql.SQLException)8 Update (org.jdbi.v3.core.statement.Update)7 GenericType (org.jdbi.v3.core.generic.GenericType)6 Query (org.jdbi.v3.core.statement.Query)6 Rule (org.junit.Rule)5 Map (java.util.Map)4 BrokenDao (org.jdbi.v3.sqlobject.subpackage.BrokenDao)4 SomethingDao (org.jdbi.v3.sqlobject.subpackage.SomethingDao)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Method (java.lang.reflect.Method)3 Connection (java.sql.Connection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3