Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.Query


        assertEquals(Long.class, o.getClass());
    }

    public void testProjectionResultIsCached() {
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL, "select a.age FROM " +
            CacheObjectAChild1.class.getSimpleName() + " a");
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        Object o = c.iterator().next();
        assertEquals(Long.class, o.getClass());
    }
View Full Code Here


    }

    public void testProjectionOfThisIsCached() {
        // ##### need to test single projection
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL, "select a FROM " +
            CacheObjectAChild1.class.getSimpleName() + " a");
        //CacheObjectAChild1.class, "select this");
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        Object o = c.iterator().next();
        assertEquals(CacheObjectAChild1.class, o.getClass());
        assertNotNull(broker.getObjectId(o));
    }
View Full Code Here

        assertNotNull(broker.getObjectId(o));
    }

    public void testProjectionResultWithThisIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select a.name,a FROM " +
                CacheObjectAChild1.class.getSimpleName() + " a");
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        Object[] result = (Object[]) c.iterator().next();
        assertEquals(2, result.length);
        assertEquals(String.class, result[0].getClass());
        assertEquals(CacheObjectAChild1.class, result[1].getClass());
        assertNotNull(broker.getObjectId(result[1]));
View Full Code Here

        assertNotNull(broker.getObjectId(result[1]));
    }

    public void testNullProjectionValues() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select a.locale FROM " +
                CacheObjectAChild1.class.getSimpleName() + " a");
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        assertNull(c.iterator().next());
    }
View Full Code Here

        assertNull(c.iterator().next());
    }

    public void testNullAndNotNullProjectionValues() {
        Broker broker = _factory.newBroker();
        Query q =
            broker
                .newQuery(JPQLParser.LANG_JPQL, "select a.name,a.locale FROM " +
                    CacheObjectAChild1.class.getSimpleName() + " a");

        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        Object[] result = (Object[]) c.iterator().next();
        assertEquals(2, result.length);
        assertEquals(String.class, result[0].getClass());
        assertNull(result[1]);
    }
View Full Code Here

        // ???
    }

    public void testMultipleAggregateResultIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL,
                "select max(a.age), avg(a.age), count(a.age) FROM " +
                    CacheObjectAChild1.class.getSimpleName() + " a");

        Object o = q.execute();
        assertEquals(Object[].class, o.getClass());
        assertEquals(3, ((Object[]) o).length);
        assertEquals(Long.class, ((Object[]) o)[0].getClass());

        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        o = q.execute();
        assertEquals(Object[].class, o.getClass());
        assertEquals(3, ((Object[]) o).length);
        assertEquals(Long.class, ((Object[]) o)[0].getClass());
    }
View Full Code Here

    public void testFieldUsedTwice() {
        // Postgres bug
        Broker broker = _factory.newBroker();
        // group avoids postgres bug
        Query q = broker
            .newQuery(JPQLParser.LANG_JPQL, "select a.age, avg(a.age) FROM " +
                CacheObjectAChild1.class.getSimpleName() +
                " a  group by a.age");
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);
    }
View Full Code Here

    public void testAggregateAndProjection() {
        // Postgres bug
        Broker broker = _factory.newBroker();
        // group avoids postgres bug
        Query q = broker
            .newQuery(JPQLParser.LANG_JPQL, "select a.name, avg(a.age) FROM " +
                CacheObjectAChild1.class.getSimpleName() +
                " a  group by a.name");

        List l = (List) q.execute();
        CacheTestHelper.iterate(l);
        assertEquals(Object[].class, l.get(0).getClass());
        assertEquals(2, ((Object[]) l.get(0)).length);
        assertEquals(String.class, ((Object[]) l.get(0))[0].getClass());

        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        l = (List) q.execute();
        assertEquals(Object[].class, l.get(0).getClass());
        assertEquals(2, ((Object[]) l.get(0)).length);
        assertEquals(String.class, ((Object[]) l.get(0))[0].getClass());
    }
View Full Code Here

        n = (Number) q.execute();
    }*/

    public void testResultClassIsCached() {
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL, "Select a FROM " +
            CacheObjectAChild1.class.getSimpleName() + " a");
        q.setResultType(Object.class);
        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);
    }
View Full Code Here

        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);
    }

    public void testGroupingIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select max(a.age) FROM " +
                CacheObjectAChild1.class.getSimpleName() +
                " a  group by a.name");

        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        c = (Collection) q.execute();
        Object o = c.iterator().next();
        assertEquals(Long.class, o.getClass());
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.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.