org.hibernate.SessionFactory.getCache()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.hibernate.SessionFactory.getCache()方法的一些代码示例,展示了SessionFactory.getCache()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SessionFactory.getCache()方法的具体详情如下:
包路径:org.hibernate.SessionFactory
类名称:SessionFactory
方法名:getCache

SessionFactory.getCache介绍

[英]Obtain direct access to the underlying cache regions.
[中]获取对底层缓存区域的直接访问。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 *
 * @param em
 * @param entityType
 * @param ids
 */
public static void executeTargetedCacheInvalidation(EntityManager em, Class<?> entityType, List<Long> ids) {
  Session session = em.unwrap(Session.class);
  for (Long id : ids) {
    session.getSessionFactory().getCache().evictEntity(entityType, id);
  }
  //update the timestamp cache for the table so that queries will be refreshed
  ClassMetadata metadata = session.getSessionFactory().getClassMetadata(entityType);
  String tableName = ((AbstractEntityPersister) metadata).getTableName();
  UpdateTimestampsCache timestampsCache = em.unwrap(SessionImplementor.class).getFactory().getUpdateTimestampsCache();
  if (timestampsCache != null) {
    timestampsCache.invalidate(new Serializable[]{tableName});
  }
}

代码示例来源:origin: hibernate/hibernate-orm

s.flush();
s.clear();
s.getSessionFactory().getCache().evictEntityRegion( Chaos.class );

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testEntitySQLOverriding() {
  Session s;
  Transaction tx;
  s = openSession();
  tx = s.beginTransaction();
  Chaos chaos = new Chaos();
  chaos.setSize( 123l );
  chaos.setId( 1l );
  String lowerName = "hello";
  String upperName = lowerName.toUpperCase(Locale.ROOT);
  assertFalse( lowerName.equals( upperName ) );
  chaos.setName( "hello" );
  chaos.setNickname( "NickName" );
  s.persist( chaos );
  s.flush();
  s.clear();
  s.getSessionFactory().getCache().evictEntityRegion( Chaos.class );
  Chaos resultChaos = s.load( Chaos.class, chaos.getId() );
  assertEquals( upperName, resultChaos.getName() );
  assertEquals( "nickname", resultChaos.getNickname() );
  tx.rollback();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

s.setCacheMode( CacheMode.IGNORE);
sessionFactory = s.getSessionFactory();
sessionFactory.getCache().evictAllRegions();
statistics = sessionFactory.getStatistics();
statistics.clear();
assertEquals(0L, statistics.getSecondLevelCacheMissCount());
assertEquals(0L, statistics.getSecondLevelCachePutCount());
assertFalse(sessionFactory.getCache().containsEntity(PurchaseOrder.class, 1L));
s.setCacheMode(CacheMode.IGNORE);
sessionFactory = s.getSessionFactory();
sessionFactory.getCache().evictAllRegions();
statistics = sessionFactory.getStatistics();
statistics.clear();

代码示例来源:origin: sanluan/PublicCMS

/**
 * 
 */
public void clear() {
  sessionFactory.getCache().evictAllRegions();
}

代码示例来源:origin: sanluan/PublicCMS

/**
 * 
 */
public void clear() {
  sessionFactory.getCache().evictAllRegions();
}

代码示例来源:origin: hibernate/hibernate-orm

Session session = entityManager.unwrap( Session.class );
session.getSessionFactory().getCache().evictQueryRegion( "query.cache.person" );
session.getSessionFactory().getCache().evictQueryRegion( "query.cache.person" );

代码示例来源:origin: hibernate/hibernate-orm

s.close();
s.getSessionFactory().getCache().evictNaturalIdRegions();
Statistics stats = sessionFactory().getStatistics();
stats.setStatisticsEnabled( true );

代码示例来源:origin: hibernate/hibernate-orm

Statistics statistics = sessionFactory.getStatistics();
sessionFactory.getCache().evictAll();
statistics.clear();
sqlStatementInterceptor.clear();

代码示例来源:origin: openmrs/openmrs-core

/**
 * Method to clear the hibernate cache
 */
@Before
public void clearHibernateCache() {
  SessionFactory sf = (SessionFactory) applicationContext.getBean("sessionFactory");
  sf.getCache().evictCollectionRegions();
  sf.getCache().evictEntityRegions();
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

public void evictAll() {
      sessionFactory.getCache().evictEntityRegions();
// TODO : if we want to allow an optional clearing of all cache data, the additional calls would be:
//            sessionFactory.getCache().evictCollectionRegions();
//            sessionFactory.getCache().evictQueryRegions();
    }
  }

代码示例来源:origin: com.intoverflow.booster/booster-core

/**
 * 根据jpa EntityManagerFactory 获取 hibernate Cache API
 *
 * @param emf
 * @return
 */
public static Cache getCache(EntityManagerFactory emf) {
  return getSessionFactory(emf).getCache();
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public void clearObjectCache()
{
  sessionFactory.getCache().evictEntityRegions();
  sessionFactory.getCache().evictCollectionRegions();
 }

代码示例来源:origin: pl.edu.icm.sedno/sedno-tools

@Override
public void clearSecondLevelCache() {
  sessionFactory.getCache().evictEntityRegions();
  sessionFactory.getCache().evictQueryRegions();
  sessionFactory.getCache().evictCollectionRegions();
}

代码示例来源:origin: dhis2/dhis2-core

@Override
public void clearQueryCache()
{
  sessionFactory.getCache().evictDefaultQueryRegion();
  sessionFactory.getCache().evictQueryRegions();
}

代码示例来源:origin: pl.edu.icm.sedno/sedno-tools

@Override
public void evictCollectionFromSecondLevelCache(Class ownerClass, int ownerId, String collectionProperty) {
  String role = ownerClass.getName() + "." + collectionProperty;
  if (sessionFactory.getCache().containsCollection(role, ownerId)) {
    sessionFactory.getCache().evictCollection(role, ownerId);
  }
}

代码示例来源:origin: stackoverflow.com

SessionFactory sf = ...;
Cache cache = sf.getCache();
cache.evictEntityRegions();
cache.evictCollectionRegions();
cache.evictQueryRegions();

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

@Override
 public Void call() throws Exception {
   sessionFactory.getCache().evictEntityRegion(Age.class);
   return null;
 }
});

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

@Override
 public void run() throws Exception {
   log.trace("Invalidating all caches");
   int node = threadNode.get();
   sessionFactory(node).getCache().evictAllRegions();
 }
}

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

@Override
 public void run() throws Exception {
   withRandomFamily((s, f) -> {
      if (evict) {
       sessionFactory(threadNode.get()).getCache().evictEntity(Family.class, f.getId());
      }
    }, Ref.empty(), Ref.empty(), null);
 }
}

相关文章