Package org.apache.openjpa.datacache

Examples of org.apache.openjpa.datacache.DataCache


            if (sm == null)
                return;

            sm.evict();
            if (_evictDataCache && sm.getObjectId() != null) {
                DataCache cache = sm.getMetaData().getDataCache();
                if (cache != null)
                    cache.remove(sm.getObjectId());
            }
        }
        catch (OpenJPAException ke) {
            throw ke;
        } catch (RuntimeException re) {
View Full Code Here


            if (sm == null)
                return;

            sm.evict();
            if (_evictDataCache && sm.getObjectId() != null) {
                DataCache cache = _conf.getDataCacheManagerInstance().selectCache(sm);
                if (cache != null)
                    cache.remove(sm.getObjectId());
            }
        }
        catch (OpenJPAException ke) {
            throw ke;
        } catch (RuntimeException re) {
View Full Code Here

            endEm(em2);
        }
    }

    public void testCanCacheExtension() throws Exception {
        DataCache cache = cacheManager(factory).getSystemDataCache();

        // first, test caching of newly created objects.
        OpenJPAEntityManager em = (OpenJPAEntityManager) factory
            .createEntityManager();
        Object o;
        Object oid;
        try {
            startTx(em);
            o = new CacheObjectB("foo");
            em.persist(o);
            endTx(em);
            oid = em.getObjectId(o);
            assertNotNull(oid);
            assertNull(cache.get(oid));
        }
        finally {
            endEm(em);
        }

        // now, test caching of data loaded from the data store.
        em = factory.createEntityManager();
        try {
            o = em.find(CacheObjectB.class, oid);
            assertNotNull(o);
            assertNull(cache.get(oid));
        }
        finally {
            endEm(em);
        }
    }
View Full Code Here

        }
    }

    public void testGetCache() {
        // first, test caching of newly created objects.
        DataCache defaultCache = cacheManager(factory).getDataCache(
            DataCache.NAME_DEFAULT, false);
        assertNotNull(defaultCache);

        DataCache cache = cacheManager(factory).getSystemDataCache();
        assertEquals(defaultCache, cache);

        ClassMetaData aMeta = repos.getMetaData(CacheObjectA.class, null, true);
        ClassMetaData aChild1Meta = repos.getMetaData(CacheObjectAChild1.class,
            null, true);
View Full Code Here

        em.refresh(a);
        Object relationOid = em.getObjectId(a.getRelatedObject());
        relationOid = new Id(CacheObjectA.class, relationOid.toString());

        ClassMetaData meta = repos.getMetaData(CacheObjectA.class, null, true);
        DataCache cache = meta.getDataCache();

        // drop the related data from the cache
        cache.remove(relationOid);

        OpenJPAEntityManager em2 = (OpenJPAEntityManager) factory
            .createEntityManager();
        try {
            assertTrue(cache.contains(oidwithclass));
            a = (CacheObjectA) em2.find(CacheObjectA.class, oid);

            try {
                assertFalse(cache.contains(relationOid));
            }
            catch (AssertionFailedError e) {
                // bug(467, "data cache can over-eagerly load relation data");
                e.printStackTrace();
            }
View Full Code Here

    public void testCache2() {
        OpenJPAEntityManager em1 =
            (OpenJPAEntityManager) factory.createEntityManager();
        OpenJPAEntityManager em2 = null;
        DataCache cache;

        try {
            CacheObjectA a1 = (CacheObjectA) em1.find(CacheObjectA.class, oid);

            em2 = (OpenJPAEntityManager) factory2.createEntityManager();
            CacheObjectA a2 = (CacheObjectA) em2.find(CacheObjectA.class, oid);

            // assert that the oid is in factory2's cache
            //MetaDataRepository repos2 = factory2.getConfiguration().getMetaDataRepositoryInstance();
            MetaDataRepository repos2 =
                ((((OpenJPAEntityManagerFactorySPI) factory2)).getConfiguration())
                    .getMetaDataRepositoryInstance();
            ClassMetaData meta = repos2
                .getMetaData(CacheObjectA.class, em2.getClassLoader(), true);
            cache = meta.getDataCache();
            assertTrue(cache.contains(oidwithclass));

            // modify the object.
            startTx(em1);
            a1.setName(a1.getName() + " changed");
            endTx(em1);
        }
        finally {
            if (em2 != null)
                endEm(em2);
            endEm(em1);
        }

        // if the cache is a coherent one, then the changes should be
        // seen. Otherwise, they should not.
        if (isCacheCoherent() || factory == factory2)
            assertTrue("key " + oid + " was not in cache; should have been",
                cache.contains(oidwithclass));
        else
            assertFalse("key " + oid + " was in cache; should not have been",
                cache.contains(oidwithclass));
    }
View Full Code Here

                JPQLParser.LANG_JPQL, "Select a FROM "
                + CacheObjectF.class.getSimpleName() + " a");
            iterate((Collection) q2.execute());
            assertInCache(q2, Boolean.TRUE);

            DataCache cache = cacheManager(factory).getDataCache(
                DataCache.NAME_DEFAULT, false);
            checkCache(cache, ids, new boolean[]{ true, true, true, true });

            // should cause h to be dropped.
            Thread.currentThread().sleep(551);
View Full Code Here

            em.persist(helperObjs[2]);
            em.persist(helperObjs[3]);
            em.persist(helperObjs[4]);
            endTx(em);

            DataCache cache = cacheManager(factory).getDataCache(
                DataCache.NAME_DEFAULT, false);

            if (!isOpenJPACache(cache)) {
                bug(627, "Tangosol cache impl needs modernization");
                return;
            }

            if (cache instanceof DelegatingDataCache)
                cache = ((DelegatingDataCache) cache).getInnermostDelegate();
            if (cache instanceof ConcurrentDataCache) {
                CacheMap map = ((ConcurrentDataCache) cache).getCacheMap();
                map.setCacheSize(3);
                map.setSoftReferenceSize(0);
            } else if (cache instanceof ConcurrentDataCache) {
                CacheMap map = ((ConcurrentDataCache) cache).getCacheMap();
                map.setCacheSize(3);
                map.setSoftReferenceSize(0);
            }

            startTx(em);
            CacheObjectH h = new CacheObjectH("h");
            em.persist(h);
            CacheObjectJ j = new CacheObjectJ("j", h);
            em.persist(j);
            endTx(em);
            Object hoid = em.getObjectId(h);
            Object joid = em.getObjectId(j);

            Object hoidwithclass = new Id(CacheObjectH.class, hoid.toString());
            Object joidwithclass = new Id(CacheObjectJ.class, joid.toString());
            endEm(em);

            // make sure j and h are in cache; may not be if not LRU
            int attempts = 0;
            for (; attempts < 100 && !cache.contains(joidwithclass); attempts++)
            {
                em = factory.createEntityManager();
                if (!cache.contains(hoidwithclass))
                    em.find(CacheObjectH.class, hoid);
                if (!cache.contains(joidwithclass))
                    em.find(CacheObjectJ.class, joid);
                endEm(em);
            }
            assertTrue("Could not get queried objects into cache",
                attempts < 100);

            // build up a query that uses H in its access path...
            em = factory.createEntityManager();
            Broker broker = JPAFacadeHelper.toBroker(em);
            org.apache.openjpa.kernel.Query q = broker.newQuery(
                JPQLParser.LANG_JPQL, "Select a FROM "
                + CacheObjectJ.class.getSimpleName()
                + " a where a.str = 'h'");
            iterate((Collection) q.execute());
            assertInCache(q, Boolean.TRUE);
            endEm(em);

            // force h out of the cache. we might have to try multiple times
            // if the cache is not LRU
            attempts = 0;
            for (; attempts < 100 && cache.contains(joidwithclass); attempts++)
            {
                em = factory.createEntityManager();
                for (int i = 0; i < 5; i++)
                    em.find(RuntimeTest1.class, em.getObjectId(helperObjs[i]));
                endEm(em);
View Full Code Here

        Date d = new Date();
        a.setDate(d);

        endTx(em0);
        DataCache cache = cacheManager(factory).getDataCache(
            DataCache.NAME_DEFAULT, false);
        assertTrue(cache.contains(oidwithclass));
        cache.remove(oidwithclass);

        a = (CacheObjectA) em1.find(CacheObjectA.class, oid);
        assertTrue(cache.contains(oidwithclass));

        try {
            PCData data = cache.get(oidwithclass);
            ClassMetaData meta =
                ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence
                    .cast(factory)).getConfiguration()
                    .getMetaDataRepositoryInstance().getMetaData(a.getClass(),
                    null, false);
View Full Code Here

            if (sm == null)
                return;

            sm.evict();
            if (_evictDataCache && sm.getObjectId() != null) {
                DataCache cache = sm.getMetaData().getDataCache();
                if (cache != null)
                    cache.remove(sm.getObjectId());
            }
        }
        catch (OpenJPAException ke) {
            throw ke;
        } catch (RuntimeException re) {
View Full Code Here

TOP

Related Classes of org.apache.openjpa.datacache.DataCache

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.