Refine search
@Override public EmbeddedCacheManager getEmbeddedCacheManager(Properties properties) { Properties settings = new Properties(); String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER); settings.setProperty(HibernateSecondLevelCache.CONTAINER, container); if (!Boolean.parseBoolean(properties.getProperty(SHARED, DEFAULT_SHARED))) { HibernateSecondLevelCache.addSecondLevelCacheDependencies(properties, null); settings.setProperty(HibernateSecondLevelCache.CACHE_TYPE, HibernateSecondLevelCache.CACHE_PRIVATE); // Find a suitable service name to represent this session factory instance String name = properties.getProperty(AvailableSettings.SESSION_FACTORY_NAME); if (name != null) { settings.setProperty(HibernateSecondLevelCache.NAME, name); } settings.setProperty(HibernateSecondLevelCache.CACHES, String.join(" ", HibernateSecondLevelCache.findCaches(properties))); } try { return new JipiJapaCacheManager(Notification.startCache(Classification.INFINISPAN, settings)); } catch (CacheException e) { throw e; } catch (Exception e) { throw new CacheException(e); } }
@Override protected EmbeddedCacheManager createCacheManager(Properties properties) { String container = properties.getProperty(CACHE_CONTAINER, DEFAULT_CACHE_CONTAINER); Properties cacheSettings = new Properties(); cacheSettings.put(HibernateSecondLevelCache.CONTAINER, container); try { // Get the (shared) cache manager for JPA application use wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings); return (EmbeddedCacheManager)wrapper.getValue(); } catch (Exception e) { throw new CacheException(e); } }
@SuppressWarnings({"unchecked", "WeakerAccess"}) protected RegionFactory resolveRegionFactory(Map configurationValues, ServiceRegistryImplementor registry) { final Properties p = new Properties(); p.putAll( configurationValues ); throw new CacheException( "Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory" );
/** * Callback to perform any necessary initialization of the underlying cache implementation during SessionFactory * construction. * * @param properties current configuration settings. */ public final void start(Properties properties) throws CacheException { String jndiNamespace = properties.getProperty( Environment.CACHE_NAMESPACE ); if ( StringHelper.isEmpty( jndiNamespace ) ) { throw new CacheException( "No JNDI namespace specified for cache" ); } cache = locateCache( jndiNamespace, NamingHelper.getJndiProperties( properties ) ); prepare( properties ); }
String configurationResourceName = null; if (properties != null) { configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME); manager = new CacheManager(configuration); } else { URL url; manager = new CacheManager(HibernateUtil.overwriteCacheManagerIfConfigured(configuration, properties)); if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) { throw new CacheException("Attempt to restart an already started EhCacheRegionFactory. " + "Use sessionFactory.close() between repeated calls to buildSessionFactory. " + "Consider using SingletonEhCacheRegionFactory. Error from ehcache was: " + e.getMessage()); } else { throw new CacheException(e);
protected RedissonClient createRedissonClient(Properties properties) { Config config = null; if (!properties.containsKey(REDISSON_CONFIG_PATH)) { config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.json"); if (config == null) { config = loadConfig(RedissonRegionFactory.class.getClassLoader(), "redisson.yaml"); } } else { String configPath = ConfigurationHelper.getString(REDISSON_CONFIG_PATH, properties); config = loadConfig(RedissonRegionFactory.class.getClassLoader(), configPath); if (config == null) { config = loadConfig(configPath); } } if (config == null) { throw new CacheException("Unable to locate Redisson configuration"); } return Redisson.create(config); }
String configurationResourceName = null; if (properties != null) { configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME); manager = CacheManager.create(); REFERENCE_COUNT.incrementAndGet(); } else { manager = CacheManager.create(HibernateUtil.overwriteCacheManagerIfConfigured(configuration, properties)); REFERENCE_COUNT.incrementAndGet(); throw new CacheException(e);
public static IHazelcastInstanceLoader createInstanceLoader(Properties props) throws CacheException { try { IHazelcastInstanceLoader instanceLoader = (IHazelcastInstanceLoader) props. get("com.hazelcast.hibernate.instance.loader"); if (instanceLoader != null) { return instanceLoader; } Class loaderClass = getInstanceLoaderClass(props); instanceLoader = (IHazelcastInstanceLoader) loaderClass.newInstance(); instanceLoader.configure(props); return instanceLoader; } catch (Exception e) { throw new CacheException(e); } }
@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 ); } } }
/** * {@inheritDoc} */ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { try { if (minimalPutOverride && ehcache.get(key) != null) { return false; } //OptimisticCache? versioning? ehcache.put(new Element(key, value)); return true; } catch (net.sf.ehcache.CacheException e) { throw new CacheException(e); } }
protected Ehcache createCache(String regionName) { switch ( missingCacheStrategy ) { case CREATE_WARN: SecondLevelCacheLogger.INSTANCE.missingCacheCreated( regionName, ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation() ); cacheManager.addCache( regionName ); return cacheManager.getEhcache( regionName ); case CREATE: cacheManager.addCache( regionName ); return cacheManager.getEhcache( regionName ); case FAIL: throw new CacheException( "On-the-fly creation of Ehcache Cache objects is not supported [" + regionName + "]" ); default: throw new IllegalStateException( "Unsupported missing cache strategy: " + missingCacheStrategy ); } }
/** * @return a copy of the cache Elements as a Map */ public final Map toMap() { try { Map result = new HashMap(); for (Object key : cache.getKeys()) { Element e = cache.get(key); if (e != null) { result.put(key, e.getObjectValue()); } } return result; } catch (Exception e) { 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 stop() { try { if (manager != null) { if (REFERENCE_COUNT.decrementAndGet() == 0) { manager.shutdown(); } manager = null; } } catch (net.sf.ehcache.CacheException e) { 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 ); } } } }
@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 boolean contains(Object key) { try { return mapCache.containsKey(key); } catch (Exception e) { throw new CacheException(e); } }
@Override public final CacheException pendingPutsMustHaveMaxIdle() { final CacheException result = new CacheException(String.format(getLoggingLocale(), pendingPutsMustHaveMaxIdle$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } @Override
@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 ); } } }