Search in sources :

Example 31 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestCollectorFactory method testExists.

@Test
public void testExists() throws Exception {
    Handle h = dbRule.getSharedHandle();
    h.execute("insert into something (id, name) values (1, 'Coda')");
    Optional<String> rs = h.createQuery("select name from something where id = :id").bind("id", 1).mapTo(String.class).collect(GuavaCollectors.toOptional());
    assertThat(rs).contains("Coda");
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 32 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestCollectorFactory method testDoesNotExist.

@Test
public void testDoesNotExist() throws Exception {
    Handle h = dbRule.getSharedHandle();
    h.execute("insert into something (id, name) values (1, 'Coda')");
    Optional<String> rs = h.createQuery("select name from something where id = :id").bind("id", 2).mapTo(String.class).collect(GuavaCollectors.toOptional());
    assertThat(rs).isAbsent();
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 33 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestDocumentation method testSomeQueriesWorkCorrectly.

@Test
public void testSomeQueriesWorkCorrectly() throws Exception {
    try (Handle h = dbRule.openHandle()) {
        h.prepareBatch("insert into something (id, name) values (:id, :name)").bind("id", 1).bind("name", "Brian").add().bind("id", 2).bind("name", "Robert").add().bind("id", 3).bind("name", "Patrick").add().bind("id", 4).bind("name", "Maniax").add().execute();
        SomeQueries sq = h.attach(SomeQueries.class);
        assertThat(sq.findName(2)).isEqualTo("Robert");
        assertThat(sq.findNamesBetween(1, 4)).containsExactly("Robert", "Patrick");
        Iterator<String> names = sq.findAllNames();
        assertThat(names).containsExactly("Brian", "Robert", "Patrick", "Maniax");
    }
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 34 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestVavrValueArgumentFactoryWithDB method testGetEitherRight_shouldReturnCorrectRow.

@Test
public void testGetEitherRight_shouldReturnCorrectRow() {
    Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Either.right("brian")).mapToBean(Something.class).findOnly();
    assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 35 with Bind

use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.

the class TestVavrValueArgumentFactoryWithDB method testGetLazy_shouldReturnCorrectRow.

@Test
public void testGetLazy_shouldReturnCorrectRow() {
    Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Lazy.of(() -> "brian")).mapToBean(Something.class).findOnly();
    assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Handle (org.jdbi.v3.core.Handle)18 Something (org.jdbi.v3.core.Something)15 Jdbi (org.jdbi.v3.core.Jdbi)4 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 Parameter (java.lang.reflect.Parameter)2 Type (java.lang.reflect.Type)2 OptionalFields (net.morimekta.test.providence.storage.jdbc.OptionalFields)2 PreparedBatch (org.jdbi.v3.core.statement.PreparedBatch)2 Query (org.jdbi.v3.core.statement.Query)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Types (java.sql.Types)1 Clock (java.time.Clock)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 ProvidenceJdbi.columnsFromAllFields (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.columnsFromAllFields)1 ProvidenceJdbi.forMessage (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.forMessage)1 ProvidenceJdbi.toField (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toField)1 ProvidenceJdbi.toMessage (net.morimekta.providence.jdbi.v3.ProvidenceJdbi.toMessage)1