Package org.skife.jdbi.v2

Examples of org.skife.jdbi.v2.VoidTransactionCallback


        assertEquals("select * from something\n where id = ?", rws.getSql());
    }

    public void testOddCharacters() throws Exception
    {
        RewrittenStatement rws = rw.rewrite(":boo ':nope' _%&^& *@ :id", new Binding(),
                                            new StatementContext(new HashMap<String, Object>()));
        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }
View Full Code Here


        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }

    public void testNumbers() throws Exception
    {
        RewrittenStatement rws = rw.rewrite(":bo0 ':nope' _%&^& *@ :id", new Binding(),
                                            new StatementContext(new HashMap<String, Object>()));
        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }
View Full Code Here

    public void setUp() throws Exception
    {
        super.setUp();
        h = openHandle();
        logged = new ArrayList<String>();
        log = new SQLLog()
        {
            public void logBeginTransaction(Handle h)
            {
                logged.add("begin");
            }
View Full Code Here

    }

    public void testFoo() throws Exception
    {
        Handle h = openHandle();
        h.setStatementLocator(new StatementLocator() {

            public String locate(String name, StatementContext ctx) throws Exception
            {
                return name.replaceAll("<table>", String.valueOf(ctx.getAttribute("table")));
            }
View Full Code Here

        return h;
    }

    protected TransactionHandler getTransactionHandler()
    {
        return new LocalTransactionHandler();
    }
View Full Code Here

                return super.prepareStatement(s);
            }
        };
        CachingStatementBuilder builder = new CachingStatementBuilder(new DefaultStatementBuilder());

        BasicHandle h = new BasicHandle(new LocalTransactionHandler(),
                                        new ClasspathStatementLocator(),
                                        builder,
                                        new ColonPrefixNamedParamStatementRewriter(),
                                        c,
                                        new HashMap<String, Object>(),
View Full Code Here

        h.begin();

        h.insert("insert into something (id, name) values (:id, :name)", 1, "Tom");
        h.checkpoint("first");
        h.insert("insert into something (id, name) values (:id, :name)", 1, "Martin");
        assertEquals(Integer.valueOf(2), h.createQuery("select count(*) from something").map(new IntegerMapper()).first());
        h.rollback("first");
        assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").map(new IntegerMapper()).first());
        h.commit();
        assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").map(new IntegerMapper()).first());
    }
View Full Code Here

            fail("unexpected exception");
        }

        final Handle h = DBI.open(derby);

        int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();

        assertEquals(0, count);
        h.close();
    }
View Full Code Here

                            public void call(IDBI inner)
                            {
                                final Handle h = DBIUtil.getHandle(inner);
                                h.insert("insert into something (id, name) values (8, 'ignored again')");

                                int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
                                assertEquals(2, count);
                                throw new ForceRollback();
                            }
                        });
                        fail("should have thrown an exception");
                    }
                    catch (ForceRollback e) {
                        assertTrue(true);
                    }
                    int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
                    assertEquals(1, count);
                    throw new ForceRollback();
                }
            });
            fail("should have thrown an exception");
        }
        catch (ForceRollback e) {
            assertTrue(true);
        }

        service.inPropagationRequired(new Callback()
        {
            public void call(IDBI dbi)
            {
                final Handle h = DBIUtil.getHandle(dbi);
                int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
                assertEquals(0, count);
            }
        });
    }
View Full Code Here

                    service.inRequiresNewReadUncommitted(new Callback()
                    {
                        public void call(IDBI inner)
                        {
                            final Handle h = DBIUtil.getHandle(inner);
                            int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
                            assertEquals(1, count);
                            h.insert("insert into something (id, name) values (8, 'ignored again')");
                            throw new ForceRollback();
                        }
                    });
                }
                catch (ForceRollback e) {
                    assertTrue(true);
                }

                int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
                assertEquals(1, count);
            }
        });
    }
View Full Code Here

TOP

Related Classes of org.skife.jdbi.v2.VoidTransactionCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.