Package org.jruby.compiler.util

Examples of org.jruby.compiler.util.HandleFactory$Handle


        return new StringTemplateStatementLocator(loader);
    }

    public void testSimpleTemplate() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.insert("tests:insert_one");
        assertEquals(1, count);
    }
View Full Code Here


        assertEquals(1, count);
    }

    public void testParameterizedInsert() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.createStatement("tests:parameterized_insert")
                .define("table", "something")
                .define("column_one", "id")
                .define("column_two", "name")
                .bind("column_one", 7)
                .bind("column_two", "Rebecca")
                .execute();
        assertEquals(1, count);

        final String name = h.createQuery("select name from something where id = 7")
                .map(StringMapper.FIRST)
                .first();
        assertEquals(name, "Rebecca");
    }
View Full Code Here

        assertEquals(name, "Rebecca");
    }

    public void testExtraDefinesDontBreakThings() throws Exception
    {
        final Handle h = openHandle();
        final int count = h.createStatement("tests:insert_one")
                .define("name", "Nicole")
                .execute();
        assertEquals(1, count);
    }
View Full Code Here

*/
public class TestQueryObjectGenerator extends DBITestCase
{
    public void testApiWhichTakesConnection() throws Exception
    {
        Handle h = openHandle();
        MyQueries qo = QueryObjectFactory.createQueryObject(MyQueries.class, h.getConnection());
        assertNotNull(qo);
    }
View Full Code Here

        assertNotNull(qo);
    }

    public void testApiWhichTakesDatasource() throws Exception
    {
        final Handle h = openHandle();
        MyQueries qo = QueryObjectFactory.createQueryObject(MyQueries.class, Tools.getDataSource());
        assertNotNull(qo);
    }
View Full Code Here

        try {
            service.inPropagationRequired(new Callback()
            {
                public void call(IDBI dbi)
                {
                    Handle h = DBIUtil.getHandle(dbi);
                    final int count = h.insert("insert into something (id, name) values (7, 'ignored')");
                    if (count == 1) {
                        throw new ForceRollback();
                    }
                    else {
                        throw new RuntimeException("!ZABAK");
                    }
                }
            });
        }
        catch (ForceRollback e) {
            assertTrue(true);
        }
        catch (RuntimeException e) {
            e.printStackTrace();
            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

        try {
            service.inPropagationRequired(new Callback()
            {
                public void call(IDBI outer)
                {
                    final Handle h = DBIUtil.getHandle(outer);
                    h.insert("insert into something (id, name) values (7, 'ignored')");

                    try {
                        service.inNested(new Callback()
                        {
                            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.inPropagationRequired(new Callback()
        {
            public void call(IDBI outer)
            {
                final Handle h = DBIUtil.getHandle(outer);
                h.insert("insert into something (id, name) values (7, 'ignored')");

                try {
                    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

     * or a new one otherwise.
     * @param dbi the IDBI instance from which to obtain the handle
     */
    public static Handle getHandle(IDBI dbi)
    {
        Handle bound = (Handle) TransactionSynchronizationManager.getResource(dbi);
        if (bound == null) {
            bound = dbi.open();
            if (TransactionSynchronizationManager.isSynchronizationActive()) {
                TransactionSynchronizationManager.bindResource(dbi, bound);
                TransactionSynchronizationManager.registerSynchronization(new Adapter(dbi, bound));
View Full Code Here

        this.dbi = null;
    }

    @Test
    public void createsAValidDBI() throws Exception {
        final Handle handle = dbi.open();

        final Query<String> names = handle.createQuery("SELECT name FROM people WHERE age < ?")
                                          .bind(0, 50)
                                          .map(StringMapper.FIRST);
        assertThat(ImmutableList.copyOf(names))
                .containsOnly("Coda Hale", "Kris Gale");
    }
View Full Code Here

TOP

Related Classes of org.jruby.compiler.util.HandleFactory$Handle

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.