Skip to content

Commit

Permalink
HHH-8732 Upgraded Ehcache to 2.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps authored and brmeyer committed Mar 19, 2014
1 parent 8c8304a commit 27a53af
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 112 deletions.
4 changes: 4 additions & 0 deletions hibernate-ehcache/hibernate-ehcache.gradle
Expand Up @@ -16,3 +16,7 @@ def pomDescription() {
def osgiDescription() {
return pomDescription()
}

test {
forkEvery 1
}
Expand Up @@ -41,7 +41,6 @@
import org.hibernate.cache.ehcache.internal.regions.EhcacheTimestampsRegion;
import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactory;
import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactoryImpl;
import org.hibernate.cache.ehcache.internal.util.HibernateEhcacheUtils;
import org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CollectionRegion;
Expand Down Expand Up @@ -181,7 +180,6 @@ private Ehcache getCache(String name) throws CacheException {
cache = manager.getEhcache( name );
LOG.debug( "started EHCache region: " + name );
}
HibernateEhcacheUtils.validateEhcache( cache );
return cache;
}
catch (net.sf.ehcache.CacheException e) {
Expand Down
Expand Up @@ -25,20 +25,15 @@

import java.net.URL;

import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.ConfigurationFactory;
import net.sf.ehcache.config.NonstopConfiguration;
import net.sf.ehcache.config.TerracottaConfiguration;
import net.sf.ehcache.config.TerracottaConfiguration.ValueMode;
import net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType;
import org.jboss.logging.Logger;

import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.EhCacheMessageLogger;

import org.jboss.logging.Logger;


/**
* Copy of Ehcache utils into Hibernate code base
Expand Down Expand Up @@ -73,16 +68,9 @@ public static Configuration loadAndCorrectConfiguration(URL url) {
if ( config == null ) {
return null;
}

if ( config.getDefaultCacheConfiguration() != null
&& config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
if ( ValueMode.IDENTITY
.equals( config.getDefaultCacheConfiguration().getTerracottaConfiguration().getValueMode() ) ) {
LOG.incompatibleCacheValueMode();
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.setValueMode( ValueMode.SERIALIZATION.name() );
}
setupHibernateTimeoutBehavior(
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
Expand All @@ -92,10 +80,6 @@ public static Configuration loadAndCorrectConfiguration(URL url) {

for ( CacheConfiguration cacheConfig : config.getCacheConfigurations().values() ) {
if ( cacheConfig.isTerracottaClustered() ) {
if ( ValueMode.IDENTITY.equals( cacheConfig.getTerracottaConfiguration().getValueMode() ) ) {
LOG.incompatibleCacheValueModePerCache( cacheConfig.getName() );
cacheConfig.getTerracottaConfiguration().setValueMode( ValueMode.SERIALIZATION.name() );
}
setupHibernateTimeoutBehavior( cacheConfig.getTerracottaConfiguration().getNonstopConfiguration() );
}
}
Expand All @@ -105,32 +89,4 @@ public static Configuration loadAndCorrectConfiguration(URL url) {
private static void setupHibernateTimeoutBehavior(NonstopConfiguration nonstopConfig) {
nonstopConfig.getTimeoutBehavior().setType( TimeoutBehaviorType.EXCEPTION.getTypeName() );
}

/**
* Validates that the supplied Ehcache instance is valid for use as a Hibernate cache.
*
* @param cache The cache instance
*
* @throws CacheException If any explicit settings on the cache are not validate
*/
public static void validateEhcache(Ehcache cache) throws CacheException {
final CacheConfiguration cacheConfig = cache.getCacheConfiguration();

if ( cacheConfig.isTerracottaClustered() ) {
final TerracottaConfiguration tcConfig = cacheConfig.getTerracottaConfiguration();
switch ( tcConfig.getValueMode() ) {
case IDENTITY: {
throw new CacheException(
"The clustered Hibernate cache " + cache.getName() + " is using IDENTITY value mode.\n"
+ "Identity value mode cannot be used with Hibernate cache regions."
);
}
case SERIALIZATION:
default: {
// this is the recommended valueMode
break;
}
}
}
}
}
Expand Up @@ -97,11 +97,9 @@ public boolean isHibernateStatisticsSupported() {
@Override
public void setStatisticsEnabled(boolean flag) {
if ( flag ) {
ehcacheStats.enableStats();
hibernateStats.enableStats();
}
else {
ehcacheStats.disableStats();
hibernateStats.disableStats();
}
statsEnabled.set( flag );
Expand All @@ -121,7 +119,6 @@ public boolean isStatisticsEnabled() {
*/
@Override
public void clearStats() {
ehcacheStats.clearStats();
hibernateStats.clearStats();
}

Expand Down

0 comments on commit 27a53af

Please sign in to comment.