@Override public Object getFromCache(Object key, SharedSessionContractImplementor session) { try { final Element element = getCache().get( key ); if ( element == null ) { return null; } else { return element.getObjectValue(); } } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); return null; } else { throw new CacheException( e ); } } }
@Override public void putIntoCache(Object key, Object value, SharedSessionContractImplementor session) { try { final Element element = new Element( key, value ); getCache().put( element ); } catch (IllegalArgumentException | IllegalStateException e) { throw new CacheException( e ); } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); } else { throw new CacheException( e ); } } }
@Override public void evictData(Object key) { try { getCache().remove( key ); } catch (ClassCastException | IllegalStateException e) { throw new CacheException( e ); } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); } else { throw new CacheException( e ); } } }
@Override public void evictData() { try { getCache().removeAll(); } catch (IllegalStateException e) { throw new CacheException( e ); } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); } else { throw new CacheException( e ); } } }
@Override public void release() { try { getCache().getCacheManager().removeCache( getCache().getName() ); } catch (IllegalStateException e) { //When Spring and Hibernate are both involved this will happen in normal shutdown operation. //Do not throw an exception, simply log this one. LOG.debug( "This can happen if multiple frameworks both try to shutdown ehcache", e ); } catch (net.sf.ehcache.CacheException e) { if ( e instanceof NonStopCacheException ) { HibernateNonstopCacheExceptionHandler.getInstance() .handleNonstopCacheException( (NonStopCacheException) e ); } else { throw new CacheException( e ); } } } }
/** * {@inheritDoc} */ public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(EhcacheCollectionRegion collectionRegion, AccessType accessType) { return new NonstopAwareCollectionRegionAccessStrategy(actualFactory.createCollectionRegionAccessStrategy(collectionRegion, accessType), HibernateNonstopCacheExceptionHandler.getInstance()); }
/** * {@inheritDoc} */ public EntityRegionAccessStrategy createEntityRegionAccessStrategy(EhcacheEntityRegion entityRegion, AccessType accessType) { return new NonstopAwareEntityRegionAccessStrategy(actualFactory.createEntityRegionAccessStrategy(entityRegion, accessType), HibernateNonstopCacheExceptionHandler.getInstance()); }
/** * Get the value mapped to this key, or null if no value is mapped to this key. */ public final Object get(Object key) { try { Element element = cache.get(key); if (element == null) { return null; } else { return element.getObjectValue(); } } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); return null; } else { throw new CacheException(e); } } }
/** * {@inheritDoc} */ public long getElementCountInMemory() { try { return cache.getSize(); } catch (net.sf.ehcache.CacheException ce) { if (ce instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) ce); return -1; } else { throw new CacheException(ce); } } }
/** * {@inheritDoc} */ public void put(Object key, Object value) throws CacheException { LOG.debug("key: {} value: {}", key, value); try { Element element = new Element(key, value); cache.put(element); } catch (IllegalArgumentException e) { throw new CacheException(e); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Attempts to write lock the mapping for the given key. */ public final void writeLock(Object key) { try { lockProvider.getSyncForKey(key).lock(LockType.WRITE); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Attempts to write unlock the mapping for the given key. */ public final void writeUnlock(Object key) { try { lockProvider.getSyncForKey(key).unlock(LockType.WRITE); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Attempts to read unlock the mapping for the given key. */ public final void readUnlock(Object key) { try { lockProvider.getSyncForKey(key).unlock(LockType.READ); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Attempts to read lock the mapping for the given key. */ public final void readLock(Object key) { try { lockProvider.getSyncForKey(key).lock(LockType.READ); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * {@inheritDoc} */ public void destroy() throws CacheException { try { cache.getCacheManager().removeCache(cache.getName()); } catch (IllegalStateException e) { //When Spring and Hibernate are both involved this will happen in normal shutdown operation. //Do not throw an exception, simply log this one. LOG.debug("This can happen if multiple frameworks both try to shutdown ehcache", e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Remove all mapping from this cache region. */ public final void clear() throws CacheException { try { cache.removeAll(); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * {@inheritDoc} */ public void evictAll() throws CacheException { try { cache.removeAll(); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } } }
private void put(Object key, Object value, boolean eternal) throws CacheException { try { Element element = new Element(key, value); element.setEternal(eternal); cache.put(element); } catch (IllegalArgumentException e) { throw new CacheException(e); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * {@inheritDoc} */ public void evict(Object key) throws CacheException { try { cache.remove(key); } catch (ClassCastException e) { throw new CacheException(e); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }
/** * Remove the mapping for this key (if any exists). */ public final void remove(Object key) throws CacheException { try { cache.remove(key); } catch (ClassCastException e) { throw new CacheException(e); } catch (IllegalStateException e) { throw new CacheException(e); } catch (net.sf.ehcache.CacheException e) { if (e instanceof NonStopCacheException) { HibernateNonstopCacheExceptionHandler.getInstance().handleNonstopCacheException((NonStopCacheException) e); } else { throw new CacheException(e); } } }