本文整理汇总了Java中javax.persistence.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于javax.persistence包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evictSecondLevelCache
import javax.persistence.Cache; //导入依赖的package包/类
/**
* 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());
}
}
}
示例2: test
import javax.persistence.Cache; //导入依赖的package包/类
@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());
}
示例3: createQueryCacheAndEvictAllThenRetry
import javax.persistence.Cache; //导入依赖的package包/类
@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("#####################################################################");
}
示例4: getCache
import javax.persistence.Cache; //导入依赖的package包/类
public Cache getCache() {
// TODO : cache the cache reference?
if ( ! isOpen() ) {
throw new IllegalStateException("EntityManagerFactory is closed");
}
return new JPACache( sessionFactory );
}
示例5: testRoomsAreCached
import javax.persistence.Cache; //导入依赖的package包/类
@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()));
}
示例6: testTransientRoomsAreNotCached
import javax.persistence.Cache; //导入依赖的package包/类
@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()));
}
示例7: destroy
import javax.persistence.Cache; //导入依赖的package包/类
public static void destroy() {
if (emf == null) {
return;
}
Cache cache = emf.getCache();
log.debug("###### EVICT ALL ######");
cache.evictAll();
emf.close();
}
示例8: evict
import javax.persistence.Cache; //导入依赖的package包/类
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);
}
}
示例9: invoke
import javax.persistence.Cache; //导入依赖的package包/类
@Override
public Object invoke(Object... args) {
Cache secondLevelCache = getEntityManagerFactory(args).getCache();
if (secondLevelCache != null) {
secondLevelCache.evictAll();
}
return null;
}
示例10: getCache
import javax.persistence.Cache; //导入依赖的package包/类
@Override
public Cache getCache() {
return nativeEntityManagerFactory.getCache();
}
示例11: getCache
import javax.persistence.Cache; //导入依赖的package包/类
@Override
public Cache getCache() {
return null;
}
示例12: getCache
import javax.persistence.Cache; //导入依赖的package包/类
public Cache getCache() {
return delegate.getCache();
}
示例13: getCache
import javax.persistence.Cache; //导入依赖的package包/类
public Cache getCache() {
return null;
}
示例14: getCache
import javax.persistence.Cache; //导入依赖的package包/类
public Cache getCache() {
throw new UnsupportedOperationException("Not supported.");
}
示例15: getCache
import javax.persistence.Cache; //导入依赖的package包/类
@Override
public Cache getCache() {
return null;
}