Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.Query


   
    public void testQuery() {
        EntityManager pm = _pmf.createEntityManager();
        //FIXME jthomas - partly commented
        //Query q = pm.newQuery(ByteArrayPKPC.class, "pk == bytes");
        Query q =null;//= pm.newQuery(ByteArrayPKPC.class, "pk == bytes");
        q.declareParameters("byte[] bytes");
        //FIXME jthomas - no execute for byte
        //Collection results = (Collection) q.execute(new byte[]{ 1, 2 });
        Collection results =null;//= (Collection) q.execute(new byte[]{ 1, 2 });
        assertEquals(1, results.size());
        ByteArrayPKPC2 child = (ByteArrayPKPC2) results.iterator().next();
        assertEquals("child", child.getStringField());
        q.closeAll();
        pm.close();
    }
View Full Code Here


        String query = "SELECT e.name as name, " +
                " COALESCE (e.address.country, 'Unknown')" +
                " FROM CompUser e ORDER BY name";
        org.apache.openjpa.persistence.QueryImpl q1 =
            (org.apache.openjpa.persistence.QueryImpl) em.createQuery(query);
        Query q2 = q1.getDelegate();
        Query qi = (QueryImpl) q2;
        qi.setCandidateCollection(rsall);
        List rs = q1.getResultList();
        Object[] result = (Object[]) rs.get(0);
        assertEquals("the name is not famzy", "Famzy", result[0]);       
        assertEquals("Unknown", result[1]);
View Full Code Here

            " e.address.country as res " +
            " FROM CompUser e ORDER BY res";

        org.apache.openjpa.persistence.QueryImpl q1 =
            (org.apache.openjpa.persistence.QueryImpl) em.createQuery(query);
        Query q2 = q1.getDelegate();
        Query qi = (QueryImpl) q2;
        qi.setCandidateCollection(rsall);
        List rs = q1.getResultList();
        Object[] result = (Object[]) rs.get(2);
        assertEquals("the name is not shannon ", expectedShannonName, result[0]);       
        assertNull("is not null", result[1]);
       
View Full Code Here

            " e.address.country " +
            " FROM CompUser e order by d2";

        org.apache.openjpa.persistence.QueryImpl q1 =
            (org.apache.openjpa.persistence.QueryImpl) em.createQuery(query);
        Query q2 = q1.getDelegate();
        Query qi = (QueryImpl) q2;
        qi.setCandidateCollection(rsall);
        List rs = q1.getResultList();
        Object[] result = (Object[]) rs.get(5);
        assertEquals("the name is not shannon ", expectedShannonName, result[0]);       
        assertEquals("is not 'us'", "us", result[1]);
       
View Full Code Here

            " e.age " +
            " FROM CompUser e ORDER BY name";
       
        org.apache.openjpa.persistence.QueryImpl q1 =
            (org.apache.openjpa.persistence.QueryImpl) em.createQuery(query);
        Query q2 = q1.getDelegate();
        Query qi = (QueryImpl) q2;
        qi.setCandidateCollection(rsall);
        List rs = q1.getResultList();
        Object[] result = (Object[]) rs.get(3);
        assertEquals("the name is not shannon ", expectedShannonName, result[0]);
        assertEquals("not 30", "30", result[1].toString());
View Full Code Here

        return em.createQuery(QueryLanguages.LANG_METHODQL, methodName);
    }
   
    public void testMethodQLWithParameters() {
        OpenJPAQuery q = createMethodQuery("echo");
        Query kernelQ = q.unwrap(Query.class);
        kernelQ.declareParameters("String firstName, String lastName");
        q.setParameter("firstName", "Fred").setParameter("lastName", "Lucas");
        Object result = q.getResultList().get(0);
        assertTrue(result instanceof Map);
        Map params = (Map)result;
        assertEquals("Fred", params.get("firstName"));
View Full Code Here

        }
    }

    private void loadQuery(Broker broker, QueryMetaData qmd) {
        try {
            Query q = broker.newQuery(qmd.getLanguage(), null);
            qmd.setInto(q);
            q.compile();
        } catch (Exception e) {
            if (log.isTraceEnabled()) {
                log.warn("Skipping named query " + qmd.getName() + ": "
                    + e.getMessage(), e);
            } else {
View Full Code Here

        super.tearDown();
    }

    public void testMutatedDateParameter() {
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL,
            "select a from " +
                CacheObjectAChild1.class.getSimpleName() +
                " a where a.date < :p_date");
        Date d = new Date();
        Collection c = (Collection) q.execute(new Object[]{ d });
        CacheTestHelper.iterate(c);
        int initialSize = c.size();
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE,
            new Object[]{ d });
        d.setTime(_startDate.getTime());
        CacheTestHelper.assertInCache(this, q, Boolean.FALSE,
            new Object[]{ d });
        c = (Collection) q.execute(new Object[]{ d });

        assertFalse(new Integer(initialSize).equals(new Integer(c.size())));
    }
View Full Code Here

        super.tearDown();
    }

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

        Object o = q.execute();
        assertEquals(Long.class, o.getClass());
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        o = q.execute();
        assertEquals(Long.class, o.getClass());
    }
View Full Code Here

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

    public void testAggregateNonUniqueResultIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select max(a.age) FROM " +
                CacheObjectAChild1.class.getSimpleName() + " a");
        q.setUnique(false);
        List res = (List) q.execute();
        assertEquals(1, res.size());
        Object o = res.get(0);
        assertEquals(Long.class, o.getClass());
        CacheTestHelper.assertInCache(this, q, Boolean.TRUE);

        res = (List) q.execute();
        assertEquals(1, res.size());
        o = res.get(0);
        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.