Example usage for org.hibernate Cache evictEntity

List of usage examples for org.hibernate Cache evictEntity

Introduction

In this page you can find the example usage for org.hibernate Cache evictEntity.

Prototype

@Deprecated
default void evictEntity(String entityName, Serializable identifier) 

Source Link

Document

Evicts the entity data for a particular entity "instance".

Usage

From source file:com.daphne.es.monitor.web.controller.HibernateCacheMonitorController.java

License:Apache License

@RequestMapping(value = "/evictEntity")
@ResponseBody/*w  ww . j  a  v a 2 s  . c o m*/
public String evictEntity(@RequestParam(value = "entityNames", required = false) String[] entityNames,
        @RequestParam(value = "entityIds", required = false) Serializable[] entityIds) {

    boolean entityNamesEmpty = ArrayUtils.isEmpty(entityNames);
    boolean entityIdsEmpty = ArrayUtils.isEmpty(entityIds);

    Cache cache = HibernateUtils.getCache(em);

    if (entityNamesEmpty && entityIdsEmpty) {
        cache.evictEntityRegions();
    } else if (entityIdsEmpty) {
        for (String entityName : entityNames) {
            cache.evictEntityRegion(entityName);
        }
    } else {
        for (String entityName : entityNames) {
            for (Serializable entityId : entityIds) {
                cache.evictEntity(entityName, entityId);
            }
        }
    }

    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);
                }//from   ww  w.  j a va  2 s.  com
                // 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/*from   ww  w .ja  v  a  2  s.c  o  m*/
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);
}