Examples of DataCache


Examples of org.apache.openjpa.datacache.DataCache

            long diff = (currentTime.getTime() - startTime.getTime());
            long diff2 = (currentTime.getTime() - persistTime.getTime());
            long sleep = 0;
           
            getLog().info("CacheTest.timeoutsHelper() testing all are still in the cache, elapsed time="+diff);
            DataCache cache = cacheManager(factory).getDataCache(
                DataCache.NAME_DEFAULT, false);
            diff = Math.max(diff, diff2);
            if (diff < 450) {
                // all should still be in the cache
                checkCache(cache, ids, new boolean[]{ true, true, true, true });
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

            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);
            }

            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

Examples of org.apache.openjpa.datacache.DataCache

        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

Examples of org.apache.openjpa.datacache.DataCache

            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

Examples of org.apache.openjpa.datacache.DataCache

        }
       
        String cacheName = opts.getProperty("name",null);
        OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration();
        DataCacheManager dcm = conf.getDataCacheManagerInstance();
        DataCache dc = null;
        if (cacheName == null || cacheName.trim().length() == 0) {
            dc = dcm.getSystemDataCache();
        } else {
            dc = dcm.getDataCache(cacheName);
        }
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

                if (num == null)
                    return q.getContext().deleteInMemory(q, this, params);
                return num;
            } finally {
                for (ClassMetaData cmd : getAccessPathMetaDatas(q)) {
                    DataCache cache = cmd.getDataCache();
                    if (cache != null && cache.getEvictOnBulkUpdate()) {
                        cache.removeAll(cmd.getDescribedType(), true);
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

                if (num == null)
                    return q.getContext().updateInMemory(q, this, params);
                return num;
            } finally {
                for (ClassMetaData cmd : getAccessPathMetaDatas(q)) {
                    DataCache cache = cmd.getDataCache();
                    if (cache != null && cache.getEvictOnBulkUpdate()) {
                        cache.removeAll(cmd.getDescribedType(), true);
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

            "Port=5636, Addresses=127.0.0.1:6636");
        OpenJPAEntityManagerFactory pmfReceiver = createDistinctFactory(
            TCPRemoteCommitProvider.class,
            "Port=6636, Addresses=127.0.0.1:5636");
        // Get the datacaches from each pmf
        DataCache dcSender =
            ((OpenJPAEntityManagerFactorySPI) pmfSender).getConfiguration()
                .getDataCacheManagerInstance().getSystemDataCache();
        DataCache dcReceiver =
            ((OpenJPAEntityManagerFactorySPI) pmfReceiver).getConfiguration()
                .getDataCacheManagerInstance().getSystemDataCache();

        deleteAll(RuntimeTest1.class);
        deleteAll(RuntimeTest2.class);

        _runtime1sOids = null;
        _runtime2sOids = null;

        String transType = "normal";
        String rcpType = "OIDs";
        if (asLargeTransaction) {
            transType = "large";
            rcpType = "classes";
        }
        System.out.println("-------------------");
        System.out.println(
            "2 PMFs created, acting as a cluster using ports 5636 and 6636");
        System.out.println("Testing scenario:");
        System.out
            .println("  1 Seed datastore with instances of RuntimeTest1 AND "
                + "RuntimeTest2 objs.\n"
                + "  2 pmf2 fills its cache with both sets of objs.\n"
                + "  3 pmf1 does a "
                + transType
                + " tx that invokes an operation of "
                + changeOperation.getName()
                + " to affect a single Runtime1 \n"
                + "    assert that both pmf1 and pmf2's data caches dropped all"
                + "Runtime1s");
        System.out.println("Remote commit event is transmiting " + rcpType);

        // Create runtimes1s and 2s.
        // Noraml transaction
        OpenJPAEntityManager pmSender = (OpenJPAEntityManager) pmfSender
            .createEntityManager();
        seedDataStore(pmSender, NUM_OBJECTS);
        endEm(pmSender);

        // wait a bit so they get stored
        pause(1);

        OpenJPAEntityManager pm2;
        pm2 = (OpenJPAEntityManager) pmfReceiver.createEntityManager();
        performLoadAll(pm2);
        endEm(pm2);

        pmSender = (OpenJPAEntityManager) pmfSender.createEntityManager();
        performLoadAll(pmSender);
        endEm(pmSender);

        // assert that pmf2's data cache now has all the Runtime1 and 2s.
        for (int i = 0; i < _runtime1sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }

        // Modify or delete exactly 1 RuntimeTest1 object during a
        // largeTransaction
        changeOperation.operation(pmfSender, asLargeTransaction);

        // assert that pmf1's data cache now only has Runtime2 objects
        if (asLargeTransaction) {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                assertFalse(dcSender.contains(
                    Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
            }
        } else {
            // Normal transaction
            for (int i = 0; i < _runtime1sOids.length; i++) {
                if (isDelete && i == 0) {
                    assertFalse(dcSender.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                } else {
                    // modified the first elemnt, which just updated it.
                    // (for Kodo's data cache).
                    assertTrue(dcSender.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                }
            }
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcSender.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }
        // wait a tiny bit so the rce propagates
        pause(2);
        // assert the pmf2's data cache also now only has Runtime2 objects
        if (asLargeTransaction) {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                assertFalse(dcReceiver.contains(Id.newInstance(
                    RuntimeTest1.class, _runtime1sOids[i]))); //failing here
            }
        } else {
            for (int i = 0; i < _runtime1sOids.length; i++) {
                if (i == 0) {
                    assertFalse(dcReceiver.contains(Id.newInstance(
                        RuntimeTest1.class,
                        _runtime1sOids[i])))//failing here
                } else {
                    assertTrue(dcReceiver.contains(
                        Id.newInstance(RuntimeTest1.class, _runtime1sOids[i])));
                }
            }
        }
        for (int i = 0; i < _runtime2sOids.length; i++) {
            assertTrue(dcReceiver.contains(
                Id.newInstance(RuntimeTest2.class, _runtime2sOids[i])));
        }

        // shutdown
        pmfSender.close();
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

        public Number executeDelete(StoreQuery q, Object[] params) {
            try {
                return q.getContext().deleteInMemory(q, this, params);
            } finally {
                for (ClassMetaData cmd : getAccessPathMetaDatas(q)) {
                    DataCache cache = cmd.getDataCache();
                    if (cache != null && cache.getEvictOnBulkUpdate()) {
                        cache.removeAll(cmd.getDescribedType(), true);
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.openjpa.datacache.DataCache

        public Number executeUpdate(StoreQuery q, Object[] params) {
            try {
                return q.getContext().updateInMemory(q, this, params);
            } finally {
                for (ClassMetaData cmd : getAccessPathMetaDatas(q)) {
                    DataCache cache = cmd.getDataCache();
                    if (cache != null && cache.getEvictOnBulkUpdate()) {
                        cache.removeAll(cmd.getDescribedType(), true);
                    }
                }
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.