HHH-13146 - Hibernate Ehcache no longer supports the `net.sf.ehcache.hibernate.cache_lock_timeout` configuration property
This commit is contained in:
parent
478f6d0e11
commit
77cdaa0824
|
@ -35,4 +35,6 @@ public interface ConfigSettings {
|
|||
String EHCACHE_CONFIGURATION_RESOURCE_NAME = "net.sf.ehcache.configurationResourceName";
|
||||
|
||||
String EHCACHE_CONFIGURATION_CACHE_MANAGER_NAME = "net.sf.ehcache.cacheManagerName";
|
||||
|
||||
String EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT = "net.sf.ehcache.hibernate.cache_lock_timeout";
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.net.URL;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.ConfigurationFactory;
|
||||
|
||||
|
@ -27,11 +27,12 @@ import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
|||
import org.hibernate.cache.spi.CacheKeysFactory;
|
||||
import org.hibernate.cache.spi.DomainDataRegion;
|
||||
import org.hibernate.cache.spi.SecondLevelCacheLogger;
|
||||
import org.hibernate.cache.spi.support.DomainDataRegionImpl;
|
||||
import org.hibernate.cache.spi.support.DomainDataStorageAccess;
|
||||
import org.hibernate.cache.spi.support.RegionFactoryTemplate;
|
||||
import org.hibernate.cache.spi.support.RegionNameQualifier;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cache.spi.support.StorageAccess;
|
||||
import org.hibernate.cache.spi.support.DomainDataRegionImpl;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
import static org.hibernate.cache.ehcache.ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME;
|
||||
|
@ -48,6 +49,7 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
|||
|
||||
private volatile CacheManager cacheManager;
|
||||
private volatile MissingCacheStrategy missingCacheStrategy;
|
||||
private volatile long cacheLockTimeout;
|
||||
|
||||
public EhcacheRegionFactory() {
|
||||
this( DefaultCacheKeysFactory.INSTANCE );
|
||||
|
@ -193,6 +195,25 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
|||
this.missingCacheStrategy = MissingCacheStrategy.interpretSetting(
|
||||
configValues.get( ConfigSettings.MISSING_CACHE_STRATEGY )
|
||||
);
|
||||
|
||||
Object cacheLockTimeoutConfigValue = configValues.get(
|
||||
ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT
|
||||
);
|
||||
if ( cacheLockTimeoutConfigValue != null ) {
|
||||
Integer lockTimeoutInMillis = null;
|
||||
if ( cacheLockTimeoutConfigValue instanceof String ) {
|
||||
lockTimeoutInMillis = Integer.decode( (String) cacheLockTimeoutConfigValue );
|
||||
}
|
||||
else if ( cacheLockTimeoutConfigValue instanceof Number ) {
|
||||
lockTimeoutInMillis = ( (Number) cacheLockTimeoutConfigValue ).intValue();
|
||||
}
|
||||
if ( lockTimeoutInMillis != null ) {
|
||||
this.cacheLockTimeout = SimpleTimestamper.ONE_MS * lockTimeoutInMillis;
|
||||
}
|
||||
else {
|
||||
this.cacheLockTimeout = super.getTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,4 +348,9 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
|
|||
cacheManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeout() {
|
||||
return cacheLockTimeout;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.CacheImplementor;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EhcacheLockTimeoutIntegerConfigurationTest
|
||||
extends EhcacheLockTimeoutStringConfigurationTest {
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
super.addSettings( settings );
|
||||
settings.put( ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT, 1000 );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.cache.ehcache.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cache.ehcache.ConfigSettings;
|
||||
import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory;
|
||||
import org.hibernate.cache.spi.CacheImplementor;
|
||||
import org.hibernate.cache.spi.support.SimpleTimestamper;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EhcacheLockTimeoutStringConfigurationTest
|
||||
extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( Environment.CACHE_REGION_FACTORY, "ehcache" );
|
||||
settings.put( ConfigSettings.EHCACHE_CONFIGURATION_CACHE_LOCK_TIMEOUT, "1000" );
|
||||
}
|
||||
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Event.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public static class Event {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
CacheImplementor cacheImplementor = sessionFactory().getCache();
|
||||
EhcacheRegionFactory regionFactory = (EhcacheRegionFactory) cacheImplementor.getRegion( Event.class.getName() ).getRegionFactory();
|
||||
assertEquals( TimeUnit.SECONDS.toMillis( 1 ) * SimpleTimestamper.ONE_MS, regionFactory.getTimeout() );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue