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