Search in sources :

Example 66 with Something

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

the class TestScript method testFuzzyScript.

@Test
public void testFuzzyScript() throws Exception {
    Handle h = dbRule.openHandle();
    Script script = h.createScript(getResourceOnClasspath("script/fuzzy-script.sql"));
    script.executeAsSeparateStatements();
    List<Map<String, Object>> rows = h.select("select id, name from something order by id").mapToMap().list();
    assertThat(rows).isEqualTo(ImmutableList.of(ImmutableMap.of("id", 1L, "name", "eric"), ImmutableMap.of("id", 2L, "name", "sally;ann"), ImmutableMap.of("id", 3L, "name", "bob"), ImmutableMap.of("id", 12L, "name", "sally;ann;junior")));
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 67 with Something

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

the class TestStatements method testSimpleUpdate.

@Test
public void testSimpleUpdate() throws Exception {
    h.execute("insert into something (id, name) values (1, 'eric')");
    h.execute("update something set name = 'cire' where id = 1");
    Something eric = h.createQuery("select * from something where id = 1").mapToBean(Something.class).list().get(0);
    assertThat(eric.getName()).isEqualTo("cire");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 68 with Something

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

the class TestStatements method testUpdate.

@Test
public void testUpdate() throws Exception {
    h.execute("insert into something (id, name) values (1, 'eric')");
    h.createUpdate("update something set name = 'ERIC' where id = 1").execute();
    Something eric = h.createQuery("select * from something where id = 1").mapToBean(Something.class).list().get(0);
    assertThat(eric.getName()).isEqualTo("ERIC");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 69 with Something

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

the class TestClasspathSqlLocator method testPositionalParamsInPrepared.

@Test
public void testPositionalParamsInPrepared() throws Exception {
    Handle h = dbRule.openHandle();
    h.execute(findSqlOnClasspath("insert-id-name-positional"), 3, "Tip");
    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 70 with Something

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

Aggregations

Test (org.junit.Test)170 Something (org.jdbi.v3.core.Something)123 Handle (org.jdbi.v3.core.Handle)80 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)6 Jdbi (org.jdbi.v3.core.Jdbi)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 GenericType (org.jdbi.v3.core.generic.GenericType)5 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 H2DatabaseRule (org.jdbi.v3.core.rule.H2DatabaseRule)4 Rule (org.junit.Rule)4 Connection (java.sql.Connection)3 LinkedHashMap (java.util.LinkedHashMap)3 Collector (java.util.stream.Collector)3 Collectors.toList (java.util.stream.Collectors.toList)3 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)3 NoSuchMapperException (org.jdbi.v3.core.mapper.NoSuchMapperException)3