Search in sources :

Example 61 with Handle

use of org.jdbi.v3.core.Handle 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 62 with Handle

use of org.jdbi.v3.core.Handle 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 63 with Handle

use of org.jdbi.v3.core.Handle 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 64 with Handle

use of org.jdbi.v3.core.Handle 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 65 with Handle

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