Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.Broker


            endEm(em1);
        }
    }

    public void testEmptyResultsAreCached() {
        Broker broker = JPAFacadeHelper.toBrokerFactory(factory).newBroker();
        org.apache.openjpa.kernel.Query q = broker.newQuery(
            JPQLParser.LANG_JPQL, "Select a FROM "
            + CacheObjectAChild1.class.getSimpleName()
            + " a where a.name = 'testEmptyResultsAreCached'");
        Collection c = (Collection) q.execute();
        assertEquals(0, c.size());
        assertInCache(q, Boolean.TRUE);
        broker.close();
    }
View Full Code Here


     */
    void ignorePreparedQuery() {
        PreparedQuery cached = _em.getPreparedQuery(_id);
        if (cached == null)
            return;
        Broker broker = _em.getBroker();
        // Critical assumption: Only JPQL queries are cached and more
        // importantly, the identifier of the prepared query is the original
        // JPQL String
        String JPQL = JPQLParser.LANG_JPQL;
        String jpql = _id;
       
        org.apache.openjpa.kernel.Query newQuery = broker.newQuery(JPQL, jpql);
        newQuery.getFetchConfiguration().copy(_query.getFetchConfiguration());
        newQuery.compile();
        _query = new DelegatingQuery(newQuery, _em.getExceptionTranslator());
    }
View Full Code Here

                AbstractBrokerFactory.getPooledFactoryForKey(factoryKey);
            byte[] brokerBytes = (byte[]) in.readObject();
            ObjectInputStream innerIn = new BrokerBytesInputStream(brokerBytes,
                factory.getConfiguration());

            Broker broker = (Broker) innerIn.readObject();
            EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl)
                JPAFacadeHelper.toEntityManagerFactory(
                    broker.getBrokerFactory());
            broker.putUserObject(JPAFacadeHelper.EM_KEY, this);
            initialize(emf, broker);
        } catch (RuntimeException re) {
            try {
                re = _ret.translate(re);
            } catch (Exception e) {
View Full Code Here

            long q1p1;
            long q1p2;
            long q2p1;
            long q2p2;

            Broker broker = JPAFacadeHelper.toBroker(em);
            org.apache.openjpa.kernel.Query q = broker.newQuery(
                JPQLParser.LANG_JPQL, "Select a FROM "
                + CacheObjectA.class.getSimpleName() + " a");
            q.setCandidateExtent(broker.newExtent(CacheObjectA.class, false));
            start = System.currentTimeMillis();
            assertInCache(q, inCache);
            List l = (List) q.execute();
            iterate(l);
            q1p1 = System.currentTimeMillis() - start;

            assertEquals(allSize, l.size());

            start = System.currentTimeMillis();
            List l2 = (List) q.execute();
            iterate(l2);
            q1p2 = System.currentTimeMillis() - start;
            assertEquals(allSize, l2.size());

            q = broker.newQuery(JPQLParser.LANG_JPQL,
                "select a.name,a.age from "
                    + CacheObjectA.class.getSimpleName()
                    + " a where a.name = :n AND a.age = :a");
            q.setCandidateExtent(broker.newExtent(CacheObjectA.class, false));
            start = System.currentTimeMillis();
            assertInCache(q, inCache, new Object[]{ ORIG_NAME,
                new Integer(ORIG_AGE) });
            l = (List) q.execute(new Object[]{ ORIG_NAME,
                new Integer(ORIG_AGE) });
View Full Code Here

            endEm(em);
        }
    }

    public void testNonCacheableClass() {
        Broker broker = JPAFacadeHelper.toBrokerFactory(factory).newBroker();
        try {
            org.apache.openjpa.kernel.Query q = broker.newQuery(
                JPQLParser.LANG_JPQL, "Select a FROM "
                + CacheObjectB.class.getSimpleName() + " a");

            Collection c = (Collection) q.execute();
            iterate(c);
View Full Code Here

        propsMap.put("openjpa.RemoteCommitProvider", "sjvm");
        propsMap.put("openjpa.BrokerImpl", CacheTestBroker.class.getName());

        EntityManagerFactory emf = getEmf(propsMap);
        _factory = JPAFacadeHelper.toBrokerFactory(emf);
        Broker broker = _factory.newBroker();
        try {
            broker.begin();
        } catch (Exception e) {
            fail("Set up failed due to exception : \n" +
                getStackTrace(e));
        }
        int j = 0;
        for (int i = 0; i < 6; i++) {
            CacheObjectE e;
            if (i < 3)
                e = new CacheObjectE(i + "");
            else
                e = null;

            // make some common names so that GROUP BY is useful.
            if (i % 2 == 0)
                j++;
            broker.persist(new CacheObjectJ("projections-" + j, e), null);
        }

        broker.persist(new SelfReferencingCacheTestObject("foo",
            new SelfReferencingCacheTestObject("bar", null)), null);

        broker.commit();
        broker.close();

        CacheTestHelper.cacheManager(_factory).getSystemQueryCache().clear();
    }
View Full Code Here

        _factory = null;
        super.tearDown();
    }

    public void testNullRelatedPCIsCached() {
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL, "select a.e FROM " +
            CacheObjectJ.class.getSimpleName() + " a where a.e is null");

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

        c = (Collection) q.execute();
        assertNull(c.iterator().next());
    }

    public void testNullRelatedPCAndProjectionIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select a.str,a.e FROM " +
                CacheObjectJ.class.getSimpleName() + " a where a.e is null");

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

        assertEquals(String.class, result[0].getClass());
        assertNull(result[1]);
    }

    public void testNonNullRelatedPCIsCached() {
        Broker broker = _factory.newBroker();
        Query q = broker.newQuery(JPQLParser.LANG_JPQL, "select a.e FROM " +
            CacheObjectJ.class.getSimpleName() + " a where a.e  is not null");

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

        c = (Collection) q.execute();
        assertEquals(CacheObjectE.class, c.iterator().next().getClass());
    }

    public void testNonNullRelatedPCAndProjectionIsCached() {
        Broker broker = _factory.newBroker();
        Query q =
            broker.newQuery(JPQLParser.LANG_JPQL, "select a.str,a.e FROM " +
                CacheObjectJ.class.getSimpleName() +
                " a where a.e is not null");

        Collection c = (Collection) q.execute();
        CacheTestHelper.iterate(c);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.Broker

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.