Search in sources :

Example 36 with Something

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

the class TestMixinInterfaces method testInTransactionWithLevel.

@Test
public void testInTransactionWithLevel() throws Exception {
    TransactionStuff txl = handle.attach(TransactionStuff.class);
    txl.insert(7, "Keith");
    Something s = txl.inTransaction(TransactionIsolationLevel.SERIALIZABLE, conn -> {
        assertThat(conn.getHandle().getTransactionIsolationLevel()).isEqualTo(TransactionIsolationLevel.SERIALIZABLE);
        return conn.byId(7);
    });
    assertThat(s.getName()).isEqualTo("Keith");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 37 with Something

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

the class TestNewApiOnDbiAndHandle method testAttach.

@Test
public void testAttach() throws Exception {
    Spiffy spiffy = handle.attach(Spiffy.class);
    spiffy.insert(new Something(1, "Tim"));
    spiffy.insert(new Something(2, "Diego"));
    assertThat(spiffy.findNameById(2)).isEqualTo("Diego");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 38 with Something

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

the class TestBatching method testInsertSingleIterable.

@Test
public void testInsertSingleIterable() throws Exception {
    UsesBatching b = handle.attach(UsesBatching.class);
    List<Something> to_insert = Arrays.asList(new Something(1, "Tom"), new Something(2, "Tatu"));
    int[] counts = b.insertBeans(to_insert);
    assertThat(counts).containsExactly(1, 1);
    assertThat(b.size()).isEqualTo(2);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 39 with Something

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

the class TestBatching method testNoIterable.

@Test(expected = UnableToCreateStatementException.class, timeout = 5000)
public void testNoIterable() throws Exception {
    BadBatch b = handle.attach(BadBatch.class);
    b.insertBeans(new Something(1, "x"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 40 with Something

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

the class TestBatching method testChunkedBatchingOnParam.

@Test
public void testChunkedBatchingOnParam() throws Exception {
    UsesBatching b = handle.attach(UsesBatching.class);
    List<Something> things = Arrays.asList(new Something(1, "Brian"), new Something(2, "Henri"), new Something(3, "Patrick"), new Something(4, "Robert"), new Something(5, "Maniax"));
    int[] counts = b.insertChunked(3, things);
    assertThat(counts).hasSize(5).containsOnly(1);
}
Also used : Something(org.jdbi.v3.core.Something) 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