Package org.apache.openjpa.datacache

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


            "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

        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

        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

            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

                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

                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

            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");
                /*
                 * I don't think this is a bug, nor should this exception
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.