org.hibernate.cache.Cache Java Examples

The following examples show how to use org.hibernate.cache.Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringEhCacheProvider.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public final Cache buildCache(String name, Properties properties)
		throws CacheException {
	try {
		net.sf.ehcache.Ehcache cache = manager.getEhcache(name);
		if (cache == null) {
			String s = "Could not find a specific ehcache configuration for cache named [{}]; using defaults.";
			log.warn(s, name);
			manager.addCache(name);
			cache = manager.getEhcache(name);
			log.debug("started EHCache region: " + name);
		}
		return new net.sf.ehcache.hibernate.EhCache(cache);
	} catch (net.sf.ehcache.CacheException e) {
		throw new CacheException(e);
	}
}
 
Example #2
Source File: StatisticsImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Second level cache statistics per region
 * 
 * @param regionName region name
 * @return SecondLevelCacheStatistics
 */
public synchronized SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName) {
	SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) secondLevelCacheStatistics.get(regionName);
	if (slcs==null) {
		if (sessionFactory == null) return null;
		Cache cache = sessionFactory.getSecondLevelCacheRegion(regionName);
		if (cache==null) return null;
		slcs = new SecondLevelCacheStatistics(cache);
		secondLevelCacheStatistics.put(regionName, slcs);
	}
	return slcs;
}
 
Example #3
Source File: HibernateCacheonixCacheProvider.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Configure the cache
 *
 * @param regionName the name of the cache region
 * @param properties configuration settings
 * @throws CacheException
 * @noinspection UnusedCatchParameter
 */
public Cache buildCache(final String regionName,
                        final Properties properties) throws CacheException {

   int lockTimeoutMillis;
   try {
      lockTimeoutMillis = Integer.parseInt(properties.getProperty(PROPERTY_CACHEONIX_LOCK_TIMEOUT, Integer.toString(DEFAULT_LOCK_TIMEOUT_SECS))) * MILLIS_IN_SECOND;
   } catch (final NumberFormatException e) {
      lockTimeoutMillis = DEFAULT_LOCK_TIMEOUT_SECS * MILLIS_IN_SECOND;
   }
   return new HibernateCacheonixCache(cacheonix, cacheonix.getCache(regionName), lockTimeoutMillis);
}
 
Example #4
Source File: HibernateCacheonixCacheProviderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests {@link HibernateCacheonixCacheProvider#buildCache(String, Properties)}
 */
public void testBuildCache() {

   final Properties properties = new Properties();
   final Cache cache = provider.buildCache(TEST_REGION_NAME, properties);
   assertNotNull(cache);
   assertEquals(TEST_REGION_NAME, cache.getRegionName());
   assertEquals(LONG_ZERO, cache.getElementCountInMemory());
   assertEquals(LONG_ZERO, cache.getElementCountOnDisk());
   // -1 stands for "not impmeneted"
   assertEquals(LONG_MINUS_ONE, cache.getSizeInMemory());
   assertEquals(DEFAULR_LOC_TIMEOUT_MILLIS, cache.getTimeout());
}
 
Example #5
Source File: HibernateCacheonixCacheProviderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests {@link HibernateCacheonixCacheProvider#buildCache(String, Properties)}
 */
public void testBuildCacheSetsDefaultTimeout() {

   final Properties properties = new Properties();
   properties.setProperty(HibernateCacheonixCacheProvider.PROPERTY_CACHEONIX_LOCK_TIMEOUT, NOT_INTEGER);
   final Cache cache = provider.buildCache(TEST_REGION_NAME, properties);
   assertEquals(DEFAULR_LOC_TIMEOUT_MILLIS, cache.getTimeout());
}
 
Example #6
Source File: J2CacheProvider.java    From J2Cache with Apache License 2.0 4 votes vote down vote up
@Override
public Cache buildCache(String regionName, Properties properties)
        throws CacheException {
    return new J2HibernateCache(regionName, J2Cache.getChannel());
}
 
Example #7
Source File: SecondLevelCacheStatistics.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
SecondLevelCacheStatistics(Cache cache) {
	super( cache.getRegionName() );
	this.cache = cache;
}
 
Example #8
Source File: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Cache getSecondLevelCacheRegion(String regionName) {
	synchronized (allCacheRegions) {
		return (Cache) allCacheRegions.get(regionName);
	}
}
 
Example #9
Source File: HibernateCacheonixCache.java    From cacheonix-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructor.
 *
 * @param cacheonix         Cacheonix instance.
 * @param delegate          to be used by this implementation of Hibernate's abstraction for caches.
 * @param lockTimeoutMillis timeout in milliseconds for obtaining a lock.
 * @noinspection AssignmentToCollectionOrArrayFieldFromParameter
 */
public HibernateCacheonixCache(final Cacheonix cacheonix, final org.cacheonix.cache.Cache delegate,
                               final int lockTimeoutMillis) {

   this.cacheonix = cacheonix;
   this.delegate = delegate;
   this.lockTimeoutMillis = lockTimeoutMillis;
}
 
Example #10
Source File: SessionFactoryImplementor.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Get a named second-level cache region
 */
public Cache getSecondLevelCacheRegion(String regionName);