Java 类javax.persistence.Cache 实例源码

项目:OpenCyclos    文件:BaseDAOImpl.java   
/**
 * 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());
        }
    }
}
项目:saos    文件:SecondLevelCacheTest.java   
@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());

}
项目:hibernate4-memcached    文件:QueryCacheTest.java   
@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("#####################################################################");
}
项目:helium    文件:EntityManagerFactoryImpl.java   
public Cache getCache() {
    // TODO : cache the cache reference?
    if ( ! isOpen() ) {
        throw new IllegalStateException("EntityManagerFactory is closed");
    }
    return new JPACache( sessionFactory );
}
项目:OpenCyclos    文件:BaseDAOImpl.java   
/**
 * 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());
        }
    }
}
项目:Hotel-Reservation-Tool    文件:RoomCacheTest.java   
@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()));
}
项目:Hotel-Reservation-Tool    文件:RoomCacheTest.java   
@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()));
}
项目:hibernate4-memcached    文件:EntityTestUtils.java   
public static void destroy() {
    if (emf == null) {
        return;
    }

    Cache cache = emf.getCache();
    log.debug("###### EVICT ALL ######");
    cache.evictAll();
    emf.close();
}
项目:vars    文件:JPACacheProvider.java   
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);
    }
}
项目:jipijapa    文件:HibernateStatistics.java   
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}
项目:jipijapa    文件:HibernateStatistics.java   
@Override
public Object invoke(Object... args) {
    Cache secondLevelCache = getEntityManagerFactory(args).getCache();
    if (secondLevelCache != null) {
        secondLevelCache.evictAll();
    }
    return null;
}
项目:cibet    文件:CibetEntityManagerFactory.java   
@Override
public Cache getCache() {
   return nativeEntityManagerFactory.getCache();
}
项目:cibet    文件:JdbcBridgeEntityManagerFactory.java   
@Override
public Cache getCache() {
   return null;
}
项目:jpasecurity    文件:DelegatingEntityManagerFactory.java   
public Cache getCache() {
    return delegate.getCache();
}
项目:jpasecurity    文件:MockitoPersistenceProvider.java   
public Cache getCache() {
    return null;
}
项目:training    文件:MockStockPriceEntityManagerFactory.java   
public Cache getCache() {
    throw new UnsupportedOperationException("Not supported.");
}
项目:switchyard    文件:NoopEntityManagerFactory.java   
@Override
public Cache getCache() {
    return null;
}
项目:ef-orm    文件:JefEntityManagerFactory.java   
public Cache getCache() {
    return CacheDummy.getInstance();
}
项目:olingo-odata2    文件:JPQLBuilderFactoryTest.java   
@Override
public Cache getCache() {
  return null;
}
项目:functional-jpa    文件:RichEntityManagerFactory.java   
public Cache getCache() {
    return emf.getCache();
}
项目:spearal-jpa2    文件:EntityManagerFactoryWrapper.java   
public Cache getCache() {
    return entityManagerFactory.getCache();
}
项目:query    文件:DAO.java   
public DAO<T> clearCache() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evict(entityClass);
    return this;
}
项目:query    文件:DAO.java   
public DAO<T> clearAllCache() {
    Cache cache = entityManager.getEntityManagerFactory().getCache();
    cache.evictAll();
    return this;
}
项目:hexa.tools    文件:EntityManagerFactoryImpl.java   
@Override
public Cache getCache()
{
    assert false;
    return null;
}
项目:fuse-bxms-integ    文件:NoopEntityManagerFactory.java   
@Override
public Cache getCache() {
    return null;
}
项目:raidenjpa    文件:RaidenEntityManagerFactory.java   
public Cache getCache() {
    throw new NoPlansToImplementException();
}
项目:bundles    文件:DelegatedEntityManagerFactory.java   
@Override
public Cache getCache() {
    return emf.getCache();
}
项目:tomee    文件:ReloadableEntityManagerFactory.java   
@Override
public Cache getCache() {
    return delegate().getCache();
}
项目:kuali_rice    文件:NullEntityManagerFactory.java   
/**
 * @see javax.persistence.EntityManagerFactory#getCache()
 */
public Cache getCache() {
    throw new UnsupportedOperationException("JPA is not enabled, this should not be called.");
}
项目:osgi-hibernate    文件:EntityManagerFactoryWrapper.java   
public Cache getCache() {
    return wrapped.getCache();
}
项目:cloud-odata-java    文件:JPQLBuilderFactoryTest.java   
@Test
public void testOdataJpaAccessFactory() {

  ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
  ODataJPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl
      .getODataJPAAccessFactory();
  ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();

  EntityManagerFactory emf = new EntityManagerFactory() {

    @Override
    public boolean isOpen() {
      // TODO Auto-generated method stub
      return false;
    }

    @Override
    public Map<String, Object> getProperties() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public PersistenceUnitUtil getPersistenceUnitUtil() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public Metamodel getMetamodel() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public CriteriaBuilder getCriteriaBuilder() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public Cache getCache() {
      // TODO Auto-generated method stub
      return null;
    }

    @SuppressWarnings("rawtypes")
    @Override
    public EntityManager createEntityManager(final Map arg0) {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public EntityManager createEntityManager() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void close() {
      // TODO Auto-generated method stub

    }
  };
  oDataJPAContextImpl.setEntityManagerFactory(emf);
  oDataJPAContextImpl.setPersistenceUnitName("pUnit");

  assertNotNull(jpaAccessFactory.getODataJPAMessageService(new Locale(
      "en")));
  assertNotNull(jpaAccessFactory.createODataJPAContext());
  assertNotNull(jpaAccessFactory
      .createJPAEdmProvider(oDataJPAContextImpl));
  assertNotNull(jpaAccessFactory
      .createODataProcessor(oDataJPAContextImpl));

}
项目:deltaspike    文件:TestPersistenceProviderResolver.java   
@Override
public Cache getCache()
{
    return null;  
}
项目:vars    文件:JPACacheProvider.java   
/**
 * Clear the second level cache
 */
public void clear() {

    Cache cache = kbEmf.getCache();
    cache.evictAll();

    cache = annoEmf.getCache();
    cache.evictAll();

    cache = miscEmf.getCache();
    cache.evictAll();

}
项目:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application    文件:SecurityServiceImpl.java   
/**
 * Setter method for property <tt>cache</tt>.
 * @param cache value to be assigned to property cache
 */
public void setCache(Cache cache) {
    this.cache = cache;
}
项目:hexa.tools    文件:EntityManagerFactory.java   
Cache getCache();