@@ -0,0 +1,2610 @@
+package org.skife.jdbi.v2.sqlobject;%0A%0Aimport junit.framework.TestCase;%0Aimport org.h2.jdbcx.JdbcDataSource;%0Aimport org.junit.Test;%0Aimport org.skife.jdbi.v2.DBI;%0Aimport org.skife.jdbi.v2.Handle;%0Aimport org.skife.jdbi.v2.Something;%0Aimport org.skife.jdbi.v2.TransactionCallback;%0Aimport org.skife.jdbi.v2.TransactionStatus;%0Aimport org.skife.jdbi.v2.sqlobject.mixins.GetHandle;%0Aimport org.skife.jdbi.v2.tweak.HandleCallback;%0Aimport java.util.Random;%0A%0Apublic class TestReentrancy extends TestCase%0A%7B%0A    private DBI    dbi;%0A    private Handle handle;%0A%0A    interface TheBasics extends GetHandle%0A    %7B%0A        @SqlUpdate(%22insert into something (id, name) values (:id, :name)%22)%0A        int insert(@BindBean Something something);%0A    %7D%0A%0A    @Test%0A    public void testHandleReentrant() throws Exception%0A    %7B%0A        final TheBasics dao = dbi.onDemand(TheBasics.class);%0A%0A        dao.withHandle(new HandleCallback%3CVoid%3E() %7B%0A            @Override%0A            public Void withHandle(Handle handle) throws Exception%0A            %7B%0A                dao.insert(new Something(7, %22Martin%22));%0A%0A                handle.createQuery(%22SELECT 1%22).list();%0A%0A                return null;%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @Test%0A    public void testTxnReentrant() throws Exception%0A    %7B%0A        final TheBasics dao = dbi.onDemand(TheBasics.class);%0A%0A        dao.withHandle(new HandleCallback%3CVoid%3E() %7B%0A            @Override%0A            public Void withHandle(Handle handle) throws Exception%0A            %7B%0A                handle.inTransaction(new TransactionCallback%3CVoid%3E() %7B%0A                    @Override%0A                    public Void inTransaction(Handle conn, TransactionStatus status) throws Exception%0A                    %7B%0A                        dao.insert(new Something(1, %22x%22));%0A%0A                        conn.createQuery(%22SELECT 1%22).list();%0A                        return null;%0A                    %7D%0A                %7D);%0A%0A                return null;%0A            %7D%0A        %7D);%0A    %7D%0A%0A%0A    @Override%0A    public void setUp() throws Exception%0A    %7B%0A        JdbcDataSource ds = new JdbcDataSource();%0A        // in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name%0A        ds.setURL(%22jdbc:h2:mem:test%22 + new Random().nextInt() +%22;MVCC=TRUE%22);%0A%0A        dbi = new DBI(ds);%0A%0A        dbi.registerMapper(new SomethingMapper());%0A%0A        handle = dbi.open();%0A%0A        handle.execute(%22create table something (id int primary key, name varchar(100))%22);%0A    %7D%0A%0A    @Override%0A    public void tearDown() throws Exception%0A    %7B%0A        handle.execute(%22drop table something%22);%0A        handle.close();%0A    %7D%0A%7D%0A

Add a (failing) test to demonstrate confusing behavior when mixing SqlObject and GetHandle