Search in sources :

Example 11 with Update

use of org.jdbi.v3.core.statement.Update in project metrics by dropwizard.

the class TimedAnnotationNameStrategyTest method testAnnotationOnMethodWithCustomAbsoluteName.

@Test
public void testAnnotationOnMethodWithCustomAbsoluteName() throws Exception {
    when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("absoluteUpdate")));
    assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("absolute-update");
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.Test)

Example 12 with Update

use of org.jdbi.v3.core.statement.Update in project metrics by dropwizard.

the class TimedAnnotationNameStrategyTest method testAnnotationOnMethodWithCustomName.

@Test
public void testAnnotationOnMethodWithCustomName() throws Exception {
    when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("customUpdate")));
    assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategyTest$Foo.custom-update");
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.Test)

Example 13 with Update

use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.

the class TestNamedParams method testMapKeyBinding.

@Test
public void testMapKeyBinding() throws Exception {
    Handle h = dbRule.openHandle();
    Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
    Map<String, Object> args = new HashMap<>();
    args.put("id", 0);
    args.put("name", "Keith");
    s.bindMap(args);
    int insert_count = s.execute();
    Query q = h.createQuery("select * from something where id = :id").bind("id", 0);
    final Something fromDb = q.mapToBean(Something.class).findOnly();
    assertThat(insert_count).isEqualTo(1);
    assertThat(fromDb).extracting(Something::getId, Something::getName).containsExactly(0, "Keith");
}
Also used : Query(org.jdbi.v3.core.statement.Query) HashMap(java.util.HashMap) Update(org.jdbi.v3.core.statement.Update) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 14 with Update

use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.

the class TestNamedParams method testCascadedLazyArgs.

@Test
public void testCascadedLazyArgs() throws Exception {
    Handle h = dbRule.openHandle();
    Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
    Map<String, Object> args = new HashMap<>();
    args.put("id", 0);
    s.bindMap(args);
    s.bindBean(new Object() {

        @SuppressWarnings("unused")
        public String getName() {
            return "Keith";
        }
    });
    int insert_count = s.execute();
    assertThat(insert_count).isEqualTo(1);
    Something something = h.createQuery("select id, name from something").mapToBean(Something.class).findOnly();
    assertThat(something).isEqualTo(new Something(0, "Keith"));
}
Also used : HashMap(java.util.HashMap) Update(org.jdbi.v3.core.statement.Update) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 15 with Update

use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.

the class TestNamedParams method testInsert.

@Test
public void testInsert() throws Exception {
    Handle h = dbRule.openHandle();
    Update insert = h.createUpdate("insert into something (id, name) values (:id, :name)");
    insert.bind("id", 1);
    insert.bind("name", "Brian");
    int count = insert.execute();
    assertThat(count).isEqualTo(1);
}
Also used : Update(org.jdbi.v3.core.statement.Update) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 Handle (org.jdbi.v3.core.Handle)10 Update (org.jdbi.v3.core.statement.Update)8 Something (org.jdbi.v3.core.Something)6 Jdbi (org.jdbi.v3.core.Jdbi)4 ExtensionMethod (org.jdbi.v3.core.extension.ExtensionMethod)4 HashMap (java.util.HashMap)3 SqlUpdate (org.jdbi.v3.sqlobject.statement.SqlUpdate)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1