List of usage examples for org.hibernate Cache evictEntityRegions
@Deprecated default void evictEntityRegions()
From source file:cn.guoyukun.spring.jpa.repository.hibernate.HibernateUtils.java
License:Apache License
/** * ?jpa EntityManagerFactory /* w w w . j av a 2 s.c o m*/ * 1? * 2?? * 3? * ? * jpa Cache api ?evict ? * * @param emf * @see org.hibernate.ejb.EntityManagerFactoryImpl.JPACache#evictAll() */ public static void evictLevel2Cache(EntityManagerFactory emf) { Cache cache = HibernateUtils.getCache(emf); cache.evictEntityRegions(); cache.evictCollectionRegions(); cache.evictDefaultQueryRegion(); cache.evictQueryRegions(); cache.evictNaturalIdRegions(); }
From source file:com.daphne.es.monitor.web.controller.HibernateCacheMonitorController.java
License:Apache License
@RequestMapping(value = "/evictEntity") @ResponseBody/*from w w w.j av a 2 s . co 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.daphne.es.monitor.web.controller.HibernateCacheMonitorController.java
License:Apache License
@RequestMapping(value = "/evictCollection") @ResponseBody//from w w w. j a v a 2 s . c o m 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.topsem.common.repository.jpa.hibernate.Hibernates.java
License:Apache License
/** * ?jpa EntityManagerFactory /*from w w w .j a v a 2 s .c o m*/ * 1? * 2?? * 3? * ? * jpa Cache api ?evict ? * * @param emf * @see org.hibernate.jpa.internal.EntityManagerFactoryImpl.JPACache#evictAll() */ public static void evictLevel2Cache(EntityManagerFactory emf) { Cache cache = Hibernates.getCache(emf); cache.evictEntityRegions(); cache.evictCollectionRegions(); cache.evictDefaultQueryRegion(); cache.evictQueryRegions(); cache.evictNaturalIdRegions(); }
From source file:de.iteratec.iteraplan.presentation.dialog.Configuration.ConfigurationController.java
License:Open Source License
/** * Clears the Hibernate second-level cache. * //w w w . jav a 2 s . c o m * @return the init page */ @RequestMapping public String clearHibernateCache() { Settings settings = sessionFactory.getSettings(); if (settings.isSecondLevelCacheEnabled()) { Cache cache = sessionFactory.getCache(); cache.evictEntityRegions(); cache.evictCollectionRegions(); } if (settings.isQueryCacheEnabled()) { Cache cache = sessionFactory.getCache(); cache.evictDefaultQueryRegion(); cache.evictQueryRegions(); } return initPage; }
From source file:org.apereo.portal.events.aggr.PortalRawEventsAggregatorImpl.java
License:Apache License
private EventProcessingResult doAggregateRawEventsInternal() { if (!this.clusterLockService.isLockOwner(AGGREGATION_LOCK_NAME)) { throw new IllegalStateException("The cluster lock " + AGGREGATION_LOCK_NAME + " must be owned by the current thread and server"); }/*from w ww. ja va2s . co m*/ if (!this.portalEventDimensionPopulator.isCheckedDimensions()) { //First time aggregation has happened, run populateDimensions to ensure enough dimension data exists final boolean populatedDimensions = this.portalEventAggregationManager.populateDimensions(); if (!populatedDimensions) { this.logger.warn( "Aborting raw event aggregation, populateDimensions returned false so the state of date/time dimensions is unknown"); return null; } } //Flush any dimension creation before aggregation final EntityManager entityManager = this.getEntityManager(); entityManager.flush(); entityManager.setFlushMode(FlushModeType.COMMIT); final IEventAggregatorStatus eventAggregatorStatus = eventAggregationManagementDao .getEventAggregatorStatus(IEventAggregatorStatus.ProcessingType.AGGREGATION, true); //Update status with current server name final String serverName = this.portalInfoProvider.getUniqueServerName(); final String previousServerName = eventAggregatorStatus.getServerName(); if (previousServerName != null && !serverName.equals(previousServerName)) { this.logger.debug("Last aggregation run on {} clearing all aggregation caches", previousServerName); final Session session = getEntityManager().unwrap(Session.class); final Cache cache = session.getSessionFactory().getCache(); cache.evictEntityRegions(); } eventAggregatorStatus.setServerName(serverName); //Calculate date range for aggregation DateTime lastAggregated = eventAggregatorStatus.getLastEventDate(); if (lastAggregated == null) { lastAggregated = portalEventDao.getOldestPortalEventTimestamp(); //No portal events to aggregate, skip aggregation if (lastAggregated == null) { return new EventProcessingResult(0, null, null, true); } //First time aggregation has run, initialize the CLEAN_UNCLOSED status to save catch-up time final IEventAggregatorStatus cleanUnclosedStatus = eventAggregationManagementDao .getEventAggregatorStatus(IEventAggregatorStatus.ProcessingType.CLEAN_UNCLOSED, true); AggregationIntervalInfo oldestMinuteInterval = this.intervalHelper .getIntervalInfo(AggregationInterval.MINUTE, lastAggregated); cleanUnclosedStatus.setLastEventDate(oldestMinuteInterval.getStart().minusMinutes(1)); eventAggregationManagementDao.updateEventAggregatorStatus(cleanUnclosedStatus); } final DateTime newestEventTime = DateTime.now().minus(this.aggregationDelay).secondOfMinute() .roundFloorCopy(); final Thread currentThread = Thread.currentThread(); final String currentName = currentThread.getName(); final MutableInt events = new MutableInt(); final MutableObject lastEventDate = new MutableObject(newestEventTime); boolean complete; try { currentThread.setName(currentName + "-" + lastAggregated + "_" + newestEventTime); logger.debug("Starting aggregation of events between {} (inc) and {} (exc)", lastAggregated, newestEventTime); //Do aggregation, capturing the start and end dates eventAggregatorStatus.setLastStart(DateTime.now()); complete = portalEventDao.aggregatePortalEvents(lastAggregated, newestEventTime, this.eventAggregationBatchSize, new AggregateEventsHandler(events, lastEventDate, eventAggregatorStatus)); eventAggregatorStatus.setLastEventDate((DateTime) lastEventDate.getValue()); eventAggregatorStatus.setLastEnd(DateTime.now()); } finally { currentThread.setName(currentName); } //Store the results of the aggregation eventAggregationManagementDao.updateEventAggregatorStatus(eventAggregatorStatus); complete = complete && (this.eventAggregationBatchSize <= 0 || events.intValue() < this.eventAggregationBatchSize); return new EventProcessingResult(events.intValue(), lastAggregated, eventAggregatorStatus.getLastEventDate(), complete); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadWriteTest.java
License:LGPL
@Test public void testEntityCacheContentsAfterEvictAll() throws Exception { final List<Citizen> citizens = saveSomeCitizens(); withTxSession(s -> {/*from w w w . j a v a 2 s . c o m*/ Cache cache = s.getSessionFactory().getCache(); Statistics stats = sessionFactory().getStatistics(); SecondLevelCacheStatistics slcStats = stats.getSecondLevelCacheStatistics(Citizen.class.getName()); assertTrue("2lc entity cache is expected to contain Citizen id = " + citizens.get(0).getId(), cache.containsEntity(Citizen.class, citizens.get(0).getId())); assertTrue("2lc entity cache is expected to contain Citizen id = " + citizens.get(1).getId(), cache.containsEntity(Citizen.class, citizens.get(1).getId())); assertEquals(2, slcStats.getPutCount()); cache.evictEntityRegions(); TIME_SERVICE.advance(1); assertEquals(0, slcStats.getElementCountInMemory()); assertFalse("2lc entity cache is expected to not contain Citizen id = " + citizens.get(0).getId(), cache.containsEntity(Citizen.class, citizens.get(0).getId())); assertFalse("2lc entity cache is expected to not contain Citizen id = " + citizens.get(1).getId(), cache.containsEntity(Citizen.class, citizens.get(1).getId())); Citizen citizen = s.load(Citizen.class, citizens.get(0).getId()); assertNotNull(citizen); assertNotNull(citizen.getFirstname()); // proxy gets resolved assertEquals(1, slcStats.getMissCount()); // cleanup markRollbackOnly(s); }); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadWriteTest.java
License:LGPL
@Test public void testMultipleEvictAll() throws Exception { final List<Citizen> citizens = saveSomeCitizens(); withTxSession(s -> {/*from ww w.j av a2s . c o m*/ Cache cache = s.getSessionFactory().getCache(); cache.evictEntityRegions(); cache.evictEntityRegions(); }); withTxSession(s -> { Cache cache = s.getSessionFactory().getCache(); cache.evictEntityRegions(); s.delete(s.load(Citizen.class, citizens.get(0).getId())); s.delete(s.load(Citizen.class, citizens.get(1).getId())); }); }
From source file:org.jasig.portal.events.aggr.PortalRawEventsAggregatorImpl.java
License:Apache License
private EventProcessingResult doAggregateRawEventsInternal() { if (!this.clusterLockService.isLockOwner(AGGREGATION_LOCK_NAME)) { throw new IllegalStateException("The cluster lock " + AGGREGATION_LOCK_NAME + " must be owned by the current thread and server"); }//from w w w .ja v a 2s . c om if (!this.portalEventDimensionPopulator.isCheckedDimensions()) { //First time aggregation has happened, run populateDimensions to ensure enough dimension data exists final boolean populatedDimensions = this.portalEventAggregationManager.populateDimensions(); if (!populatedDimensions) { this.logger.warn( "Aborting raw event aggregation, populateDimensions returned false so the state of date/time dimensions is unknown"); return null; } } //Flush any dimension creation before aggregation final EntityManager entityManager = this.getEntityManager(); entityManager.flush(); entityManager.setFlushMode(FlushModeType.COMMIT); final IEventAggregatorStatus eventAggregatorStatus = eventAggregationManagementDao .getEventAggregatorStatus(ProcessingType.AGGREGATION, true); //Update status with current server name final String serverName = this.portalInfoProvider.getUniqueServerName(); final String previousServerName = eventAggregatorStatus.getServerName(); if (previousServerName != null && !serverName.equals(previousServerName)) { this.logger.debug("Last aggregation run on {} clearing all aggregation caches", previousServerName); final Session session = getEntityManager().unwrap(Session.class); final Cache cache = session.getSessionFactory().getCache(); cache.evictEntityRegions(); } eventAggregatorStatus.setServerName(serverName); //Calculate date range for aggregation DateTime lastAggregated = eventAggregatorStatus.getLastEventDate(); if (lastAggregated == null) { lastAggregated = portalEventDao.getOldestPortalEventTimestamp(); //No portal events to aggregate, skip aggregation if (lastAggregated == null) { return new EventProcessingResult(0, null, null, true); } //First time aggregation has run, initialize the CLEAN_UNCLOSED status to save catch-up time final IEventAggregatorStatus cleanUnclosedStatus = eventAggregationManagementDao .getEventAggregatorStatus(ProcessingType.CLEAN_UNCLOSED, true); AggregationIntervalInfo oldestMinuteInterval = this.intervalHelper .getIntervalInfo(AggregationInterval.MINUTE, lastAggregated); cleanUnclosedStatus.setLastEventDate(oldestMinuteInterval.getStart().minusMinutes(1)); eventAggregationManagementDao.updateEventAggregatorStatus(cleanUnclosedStatus); } final DateTime newestEventTime = DateTime.now().minus(this.aggregationDelay).secondOfMinute() .roundFloorCopy(); final Thread currentThread = Thread.currentThread(); final String currentName = currentThread.getName(); final MutableInt events = new MutableInt(); final MutableObject lastEventDate = new MutableObject(newestEventTime); boolean complete; try { currentThread.setName(currentName + "-" + lastAggregated + "_" + newestEventTime); logger.debug("Starting aggregation of events between {} (inc) and {} (exc)", lastAggregated, newestEventTime); //Do aggregation, capturing the start and end dates eventAggregatorStatus.setLastStart(DateTime.now()); complete = portalEventDao.aggregatePortalEvents(lastAggregated, newestEventTime, this.eventAggregationBatchSize, new AggregateEventsHandler(events, lastEventDate, eventAggregatorStatus)); eventAggregatorStatus.setLastEventDate((DateTime) lastEventDate.getValue()); eventAggregatorStatus.setLastEnd(DateTime.now()); } finally { currentThread.setName(currentName); } //Store the results of the aggregation eventAggregationManagementDao.updateEventAggregatorStatus(eventAggregatorStatus); complete = complete && (this.eventAggregationBatchSize <= 0 || events.intValue() < this.eventAggregationBatchSize); return new EventProcessingResult(events.intValue(), lastAggregated, eventAggregatorStatus.getLastEventDate(), complete); }
From source file:org.jboss.dashboard.database.hibernate.HibernateInitializer.java
License:Apache License
/** * Evict all cache information.//from w ww . ja v a 2 s . c om */ public synchronized void evictAllCaches() { Cache cache = getSessionFactory().getCache(); cache.evictQueryRegions(); cache.evictEntityRegions(); cache.evictCollectionRegions(); }