java类javax.persistence.Cache的实例源码

BaseDAOImpl.java 文件源码 项目:OpenCyclos 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Evicts all second-level cache elements which could get stale on entity updates
 */
protected void evictSecondLevelCache() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();

    // If this DAO is cached, evict the collection regions, as we don't know which ones will point out to it
    if (hasCache) {
        synchronized (cache) {
            // We must invalidate all collection regions, as we don't know which other entities have many-to-many relationships with this one
            cache.evict(getEntityType());
        }
    }

    // Evict the query cache region
    if (queryCacheRegion != null) {
        synchronized (cache) {
            cache.evict(getEntityType());
        }
    }
}
SecondLevelCacheTest.java 文件源码 项目:saos 阅读 30 收藏 0 点赞 0 评论 0
@Test
public void test() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evictAll();
    Statistics statistics = ((Session)(entityManager.getDelegate())).getSessionFactory().getStatistics();
    statistics.clear();

    CommonCourt commonCourt = testPersistenceObjectFactory.createCcCourt(CommonCourtType.APPEAL);

    commonCourtRepository.findOne(commonCourt.getId());
    commonCourtRepository.findOne(commonCourt.getId());

    Assert.assertTrue(cache.contains(CommonCourt.class, commonCourt.getId()));
    Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
    Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));
    cache.evict(CommonCourt.class);
    cache.evict(CommonCourtDivision.class);
    Assert.assertFalse(cache.contains(CommonCourt.class, commonCourt.getId()));
    Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
    Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));

    Assert.assertEquals(5, statistics.getSecondLevelCachePutCount()); // 1 commonCourt + 2 ccDivision + 2 ccDivisionType
    Assert.assertEquals(2, statistics.getSecondLevelCacheHitCount());
    Assert.assertEquals(0, statistics.getSecondLevelCacheMissCount());

}
QueryCacheTest.java 文件源码 项目:hibernate4-memcached 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void createQueryCacheAndEvictAllThenRetry() throws Exception {
    List<Author> beforeResults = getAuthorsWithQuery("Author query", "어느나라");

    log.warn("#####################################################################");

    HibernateEntityManagerFactory entityManagerFactory = (HibernateEntityManagerFactory) EntityTestUtils.getEntityManagerFactory();
    org.hibernate.Cache cache = entityManagerFactory.getSessionFactory().getCache();
    cache.evictEntityRegions();
    cache.evictQueryRegions();
    cache.evictDefaultQueryRegion();
    cache.evictCollectionRegions();

    log.warn("just eviected all.");
    List<Author> againResults = getAuthorsWithQuery("Author query again after evict all", "어느나라");

    assertThat(againResults).isEqualTo(beforeResults);
    log.warn("#####################################################################");
}
EntityManagerFactoryImpl.java 文件源码 项目:helium 阅读 37 收藏 0 点赞 0 评论 0
public Cache getCache() {
    // TODO : cache the cache reference?
    if ( ! isOpen() ) {
        throw new IllegalStateException("EntityManagerFactory is closed");
    }
    return new JPACache( sessionFactory );
}
BaseDAOImpl.java 文件源码 项目:OpenCyclos 阅读 43 收藏 0 点赞 0 评论 0
/**
 * Evicts all second-level cache elements which could get stale on entity updates
 */
protected void evictSecondLevelCache(E entity) {
    if (hasCache) {
        Cache cache = entityManager.getEntityManagerFactory().getCache();
        synchronized (cache) {
            // We must invalidate all collection regions, as we don't know which other entities have many-to-many relationships with this one
            cache.evict(getEntityType(), entity.getId());
        }
    }
}
RoomCacheTest.java 文件源码 项目:Hotel-Reservation-Tool 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testRoomsAreCached() {
    Room room = getEntityManager().find(Room.class, WELL_KNOWN_ROOM_ID);

    assertThat(room, is(not(nullValue())));

    Cache cache = getEntityManager().getEntityManagerFactory().getCache();
    assertTrue("Rooms should be cached ", cache.contains(Room.class, room.getId()));
}
RoomCacheTest.java 文件源码 项目:Hotel-Reservation-Tool 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void testTransientRoomsAreNotCached() {
    Room room = new Room("", RoomEquipment.BUDGET);

    Cache cache = getEntityManager().getEntityManagerFactory().getCache();
    assertFalse("Rooms should be cached ", cache.contains(Room.class, room.getId()));
}
EntityTestUtils.java 文件源码 项目:hibernate4-memcached 阅读 28 收藏 0 点赞 0 评论 0
public static void destroy() {
    if (emf == null) {
        return;
    }

    Cache cache = emf.getCache();
    log.debug("###### EVICT ALL ######");
    cache.evictAll();
    emf.close();
}
JPACacheProvider.java 文件源码 项目:vars 阅读 21 收藏 0 点赞 0 评论 0
private void evict(Cache cache, VARSObject entity) {
    try {
        cache.evict(entity.getClass(), entity.getPrimaryKey());
    }
    catch (Exception e) {
        log.info("Failed to evict " + entity + " from cache", e);
    }
}
HibernateStatistics.java 文件源码 项目:jipijapa 阅读 27 收藏 0 点赞 0 评论 0
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}
HibernateStatistics.java 文件源码 项目:jipijapa 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}
CibetEntityManagerFactory.java 文件源码 项目:cibet 阅读 30 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
   return nativeEntityManagerFactory.getCache();
}
JdbcBridgeEntityManagerFactory.java 文件源码 项目:cibet 阅读 36 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
   return null;
}
DelegatingEntityManagerFactory.java 文件源码 项目:jpasecurity 阅读 26 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return delegate.getCache();
}
MockitoPersistenceProvider.java 文件源码 项目:jpasecurity 阅读 30 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return null;
}
MockStockPriceEntityManagerFactory.java 文件源码 项目:training 阅读 34 收藏 0 点赞 0 评论 0
public Cache getCache() {
    throw new UnsupportedOperationException("Not supported.");
}
NoopEntityManagerFactory.java 文件源码 项目:switchyard 阅读 33 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
    return null;
}
JefEntityManagerFactory.java 文件源码 项目:ef-orm 阅读 39 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return CacheDummy.getInstance();
}
JPQLBuilderFactoryTest.java 文件源码 项目:olingo-odata2 阅读 37 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
  return null;
}
RichEntityManagerFactory.java 文件源码 项目:functional-jpa 阅读 25 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return emf.getCache();
}
EntityManagerFactoryWrapper.java 文件源码 项目:spearal-jpa2 阅读 47 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return entityManagerFactory.getCache();
}
DAO.java 文件源码 项目:query 阅读 32 收藏 0 点赞 0 评论 0
public DAO<T> clearCache() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evict(entityClass);
    return this;
}
DAO.java 文件源码 项目:query 阅读 31 收藏 0 点赞 0 评论 0
public DAO<T> clearAllCache() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evictAll();
    return this;
}
EntityManagerFactoryImpl.java 文件源码 项目:hexa.tools 阅读 38 收藏 0 点赞 0 评论 0
@Override
public Cache getCache()
{
    assert false;
    return null;
}
NoopEntityManagerFactory.java 文件源码 项目:fuse-bxms-integ 阅读 30 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
    return null;
}
RaidenEntityManagerFactory.java 文件源码 项目:raidenjpa 阅读 28 收藏 0 点赞 0 评论 0
public Cache getCache() {
    throw new NoPlansToImplementException();
}
DelegatedEntityManagerFactory.java 文件源码 项目:bundles 阅读 30 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
    return emf.getCache();
}
ReloadableEntityManagerFactory.java 文件源码 项目:tomee 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Cache getCache() {
    return delegate().getCache();
}
NullEntityManagerFactory.java 文件源码 项目:kuali_rice 阅读 27 收藏 0 点赞 0 评论 0
/**
 * @see javax.persistence.EntityManagerFactory#getCache()
 */
public Cache getCache() {
    throw new UnsupportedOperationException("JPA is not enabled, this should not be called.");
}
EntityManagerFactoryWrapper.java 文件源码 项目:osgi-hibernate 阅读 30 收藏 0 点赞 0 评论 0
public Cache getCache() {
    return wrapped.getCache();
}


问题


面经


文章

微信
公众号

扫码关注公众号