Search in sources :

Example 86 with Something

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

the class TestNamedParams method testFunctionsBinding.

@Test
public void testFunctionsBinding() throws Exception {
    Handle h = dbRule.openHandle();
    assertThat(h.createUpdate("insert into something (id, name) values (:id, :name)").bindMethods(new NoArgFunctions(0, "Keith")).execute()).isEqualTo(1);
    assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 87 with Something

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

the class TestNamedParams method testBeanPropertyPrefixBinding.

@Test
public void testBeanPropertyPrefixBinding() throws Exception {
    Handle h = dbRule.openHandle();
    Something original = new Something(0, "Keith");
    assertThat(h.createUpdate("insert into something (id, name) values (:my.id, :my.name)").bindBean("my", original).execute()).isEqualTo(1);
    assertThat(h.select("select * from something where id = ?", original.getId()).mapToBean(Something.class).findOnly()).isEqualTo(original);
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 88 with Something

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

the class TestNamedParams method testFieldsPrefixBinding.

@Test
public void testFieldsPrefixBinding() throws Exception {
    Handle h = dbRule.openHandle();
    assertThat(h.createUpdate("insert into something (id, name) values (:my.id, :my.name)").bindFields("my", new PublicFields(0, "Keith")).execute()).isEqualTo(1);
    assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 89 with Something

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

the class TestNamedParams method testFieldsNestedBinding.

@Test
public void testFieldsNestedBinding() throws Exception {
    Handle h = dbRule.openHandle();
    assertThat(h.createUpdate("insert into something (id, name) values (:my.nested.id, :my.nested.name)").bindFields("my", new Object() {

        @SuppressWarnings("unused")
        public PublicFields nested = new PublicFields(0, "Keith");
    }).execute()).isEqualTo(1);
    assertThat(h.select("select * from something where id = ?", 0).mapToBean(Something.class).findOnly()).isEqualTo(new Something(0, "Keith"));
}
Also used : Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 90 with Something

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

the class TestNamedParams method testBeanPropertyBinding.

@Test
public void testBeanPropertyBinding() throws Exception {
    Handle h = dbRule.openHandle();
    Something original = new Something(0, "Keith");
    assertThat(h.createUpdate("insert into something (id, name) values (:id, :name)").bindBean(original).execute()).isEqualTo(1);
    assertThat(h.select("select * from something where id = ?", original.getId()).mapToBean(Something.class).findOnly()).isEqualTo(original);
}
Also used : Something(org.jdbi.v3.core.Something) 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