Package org.skife.jdbi.v2

Examples of org.skife.jdbi.v2.Query


     * 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


        ParameterizedType returnType = (ParameterizedType) t;
        final Type[] h = returnType.getActualTypeArguments();
        assert(h.length == 1);
        assert(h[0] instanceof Class);
        Class c = (Class) h[0];
        Query q = handle.createQuery(s.value()).map(c);
        if (args != null) bindArguments(method.isAnnotationPresent(BindBy.class) ?
                                        method.getAnnotation(BindBy.class).value() :
                                        BindType.Position, q, args);
        return f.doit(q);
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private Object handleInstance(Select s, Method method, Object[] args)
    {
        Query q = handle.createQuery(s.value()).map(method.getReturnType());
        if (args != null) bindArguments(method.isAnnotationPresent(BindBy.class) ?
                                        method.getAnnotation(BindBy.class).value() :
                                        BindType.Position, q, args);
        if (args != null) bindArguments(method.isAnnotationPresent(BindBy.class) ?
                                        method.getAnnotation(BindBy.class).value() :
                                        BindType.Position, q, args);
        q.setMaxRows(1);
        return q.first();
    }
View Full Code Here

            return new SqlStatementCustomizer()
            {
                @Override
                public void apply(SQLStatement s) throws SQLException
                {
                   Query q = (Query) s;
                   NamingStrategy dbNamingStrategy = ((MapResultForSnakeCaseAsBean) annotation).dbNamingStrategy();
                   NamingStrategy fieldNamingStrategy = ((MapResultForSnakeCaseAsBean) annotation).fieldNamingStrategy();
                   q.registerMapper(new FormatterAwareBeanMapperFactory(dbNamingStrategy,fieldNamingStrategy));
                }
            };
        }
View Full Code Here

        @Override
        public SqlStatementCustomizer createForMethod(final Annotation annotation, Class sqlObjectType, Method method) {
            return new SqlStatementCustomizer() {
                @Override
                public void apply(SQLStatement s) throws SQLException {
                    Query q = (Query) s;
                    q.registerMapper(new TranslationAwareBeanMapperFactory());
                }
            };
        }
View Full Code Here

        @Override
        public SqlStatementCustomizer createForMethod(final Annotation annotation, Class sqlObjectType, Method method) {
            return new SqlStatementCustomizer() {
                @Override
                public void apply(SQLStatement s) throws SQLException {
                    Query q = (Query) s;
                    Class<? extends TranslatingStrategyAware> translater = ((MapResultForSnakeCaseAsBean) annotation).translaterClass();
                    q.registerMapper(new TranslationAwareBeanMapperFactory(translater));
                }
            };
        }
View Full Code Here

        List<Something> ds = q.getAllSomethings();

        assertNotNull(ds);
        Iterator<Something> i = ds.iterator();
        assertTrue(i.hasNext());
        Something s = i.next();
        assertEquals("Keith", s.getName());
    }
View Full Code Here

        List<Something> ds = q.findByName("Keith");

        assertNotNull(ds);
        Iterator<Something> i = ds.iterator();
        assertTrue(i.hasNext());
        Something s = i.next();
        assertEquals("Keith", s.getName());
    }
View Full Code Here

    {
        handle.insert("insert into something (id, name) values (?, ?)", 1, "Keith");
        Iterator<Something> i = q.ittyAll();

        assertTrue(i.hasNext());
        Something s = i.next();
        assertEquals("Keith", s.getName());
        assertFalse(i.hasNext());
    }
View Full Code Here

    }

    public void testSingle() throws Exception
    {
        handle.insert("insert into something (id, name) values (?, ?)", 1, "Keith");
        Something s = q.findById(1);
        assertEquals("Keith", s.getName());
    }
View Full Code Here

TOP

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

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.