List of usage examples for org.hibernate Cache evictCollection
@Deprecated default void evictCollection(String role, Serializable ownerIdentifier)
From source file:com.daphne.es.monitor.web.controller.HibernateCacheMonitorController.java
License:Apache License
@RequestMapping(value = "/evictCollection") @ResponseBody/*www . j av a 2s . com*/ public String evictCollection( @RequestParam(value = "collectionRoleNames", required = false) String[] collectionRoleNames, @RequestParam(value = "collectionEntityIds", required = false) Serializable[] collectionEntityIds) { boolean collectionRoleNamesEmpty = ArrayUtils.isEmpty(collectionRoleNames); boolean collectionEntityIdsEmpty = ArrayUtils.isEmpty(collectionEntityIds); Cache cache = HibernateUtils.getCache(em); if (collectionRoleNamesEmpty && collectionEntityIdsEmpty) { cache.evictEntityRegions(); } else if (collectionEntityIdsEmpty) { for (String collectionRoleName : collectionRoleNames) { cache.evictCollectionRegion(collectionRoleName); } } else { for (String collectionRoleName : collectionRoleNames) { for (Serializable collectionEntityId : collectionEntityIds) { cache.evictCollection(collectionRoleName, collectionEntityIds); } } } return "??"; }
From source file:com.github.shyiko.rook.target.hibernate4.cache.SecondLevelCacheSynchronizer.java
License:Apache License
protected void processTX(Collection<RowsMutationReplicationEvent> txEvents) { for (RowsMutationReplicationEvent event : txEvents) { Cache cache = synchronizationContext.getSessionFactory().getCache(); String qualifiedName = event.getSchema().toLowerCase() + "." + event.getTable().toLowerCase(); for (EvictionTarget evictionTarget : synchronizationContext.getEvictionTargets(qualifiedName)) { for (Serializable[] row : resolveAffectedRows(event)) { Serializable key = evictionTarget.getPrimaryKey().getIdentifier(row); if (logger.isDebugEnabled()) { logger.debug("Evicting " + evictionTarget.getName() + "#" + key); }// www . j a va2s . c om // todo(shyiko): do we need a lock here? if (evictionTarget.isCollection()) { if (key == null) { continue; // that's ok, there is no mapped collection for this row } cache.evictCollection(evictionTarget.getName(), key); } else { if (key == null) { throw new IllegalStateException("Failed to extract primary key from " + evictionTarget); } cache.evictEntity(evictionTarget.getName(), key); } } } } }
From source file:org.apereo.portal.events.aggr.PortalRawEventsAggregatorImpl.java
License:Apache License
@AggrEventsTransactional @Override/* ww w. j a v a 2 s .com*/ public void evictAggregates(Map<Class<?>, Collection<Serializable>> entitiesToEvict) { int evictedEntities = 0; int evictedCollections = 0; final Session session = getEntityManager().unwrap(Session.class); final SessionFactory sessionFactory = session.getSessionFactory(); final Cache cache = sessionFactory.getCache(); for (final Entry<Class<?>, Collection<Serializable>> evictedEntityEntry : entitiesToEvict.entrySet()) { final Class<?> entityClass = evictedEntityEntry.getKey(); final List<String> collectionRoles = getCollectionRoles(sessionFactory, entityClass); for (final Serializable id : evictedEntityEntry.getValue()) { cache.evictEntity(entityClass, id); evictedEntities++; for (final String collectionRole : collectionRoles) { cache.evictCollection(collectionRole, id); evictedCollections++; } } } logger.debug("Evicted {} entities and {} collections from hibernate caches", evictedEntities, evictedCollections); }