mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Brought EHCache configuration loading in line with Hibernate
JBPM test was not configuring an L2 cache, which is now mandatory git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5357 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,7 +36,9 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.hibernate.cache.Cache;
|
import org.hibernate.cache.Cache;
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.cache.CacheProvider;
|
import org.hibernate.cache.CacheProvider;
|
||||||
|
import org.hibernate.cache.EhCache;
|
||||||
import org.hibernate.cache.EhCacheProvider;
|
import org.hibernate.cache.EhCacheProvider;
|
||||||
|
import org.hibernate.cache.Timestamper;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
@@ -74,6 +76,8 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
|
|
||||||
/** keep track of the singleton status to avoid work */
|
/** keep track of the singleton status to avoid work */
|
||||||
private static boolean initialized;
|
private static boolean initialized;
|
||||||
|
/** the <code>CacheManager</code> */
|
||||||
|
private static CacheManager cacheManager;
|
||||||
/** used to ensure that the existing Hibernate logic is maintained */
|
/** used to ensure that the existing Hibernate logic is maintained */
|
||||||
private static EhCacheProvider hibernateEhCacheProvider = new EhCacheProvider();
|
private static EhCacheProvider hibernateEhCacheProvider = new EhCacheProvider();
|
||||||
|
|
||||||
@@ -101,13 +105,17 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL configUrl = ResourceUtils.getURL(CUSTOM_CONFIGURATION_FILE);
|
URL configUrl = ResourceUtils.getURL(CUSTOM_CONFIGURATION_FILE);
|
||||||
CacheManager.create(configUrl);
|
InternalEhCacheManagerFactoryBean.cacheManager = new CacheManager(configUrl);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
// try the alfresco default
|
// try the alfresco default
|
||||||
URL configUrl = ResourceUtils.getURL(DEFAULT_CONFIGURATION_FILE);
|
URL configUrl = ResourceUtils.getURL(DEFAULT_CONFIGURATION_FILE);
|
||||||
CacheManager.create(configUrl); // this file MUST be present
|
if (configUrl == null)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Missing default cache config: " + DEFAULT_CONFIGURATION_FILE);
|
||||||
|
}
|
||||||
|
InternalEhCacheManagerFactoryBean.cacheManager = new CacheManager(configUrl);
|
||||||
defaultLocation = true;
|
defaultLocation = true;
|
||||||
}
|
}
|
||||||
// done
|
// done
|
||||||
@@ -131,17 +139,32 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
*/
|
*/
|
||||||
public static CacheManager getInstance()
|
public static CacheManager getInstance()
|
||||||
{
|
{
|
||||||
initCacheManager();
|
if (!InternalEhCacheManagerFactoryBean.initialized)
|
||||||
return CacheManager.getInstance();
|
{
|
||||||
|
InternalEhCacheManagerFactoryBean.initCacheManager();
|
||||||
|
}
|
||||||
|
return InternalEhCacheManagerFactoryBean.cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #hibernateEhCacheProvider
|
|
||||||
*/
|
|
||||||
public Cache buildCache(String regionName, Properties properties) throws CacheException
|
public Cache buildCache(String regionName, Properties properties) throws CacheException
|
||||||
{
|
{
|
||||||
initCacheManager();
|
CacheManager manager = InternalEhCacheManagerFactoryBean.getInstance();
|
||||||
return hibernateEhCacheProvider.buildCache(regionName, properties);
|
try
|
||||||
|
{
|
||||||
|
net.sf.ehcache.Cache cache = manager.getCache(regionName);
|
||||||
|
if (cache == null)
|
||||||
|
{
|
||||||
|
logger.info("Using default cache configuration: " + regionName);
|
||||||
|
manager.addCache(regionName);
|
||||||
|
cache = manager.getCache(regionName);
|
||||||
|
logger.debug("Started EHCache region: " + regionName);
|
||||||
|
}
|
||||||
|
return new EhCache(cache);
|
||||||
|
}
|
||||||
|
catch (net.sf.ehcache.CacheException e)
|
||||||
|
{
|
||||||
|
throw new CacheException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +172,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
*/
|
*/
|
||||||
public boolean isMinimalPutsEnabledByDefault()
|
public boolean isMinimalPutsEnabledByDefault()
|
||||||
{
|
{
|
||||||
return hibernateEhCacheProvider.isMinimalPutsEnabledByDefault();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,27 +180,23 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
*/
|
*/
|
||||||
public long nextTimestamp()
|
public long nextTimestamp()
|
||||||
{
|
{
|
||||||
return hibernateEhCacheProvider.nextTimestamp();
|
return Timestamper.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #initCacheManager()
|
* @see #initCacheManager()
|
||||||
* @see #hibernateEhCacheProvider
|
|
||||||
*/
|
*/
|
||||||
public void start(Properties properties) throws CacheException
|
public void start(Properties properties) throws CacheException
|
||||||
{
|
{
|
||||||
initCacheManager();
|
InternalEhCacheManagerFactoryBean.initCacheManager();
|
||||||
hibernateEhCacheProvider.start(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #initCacheManager()
|
* @see #initCacheManager()
|
||||||
* @see #hibernateEhCacheProvider
|
|
||||||
*/
|
*/
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
initCacheManager();
|
InternalEhCacheManagerFactoryBean.getInstance().shutdown();
|
||||||
hibernateEhCacheProvider.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,8 +206,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
*/
|
*/
|
||||||
public Object getObject() throws Exception
|
public Object getObject() throws Exception
|
||||||
{
|
{
|
||||||
initCacheManager();
|
return InternalEhCacheManagerFactoryBean.getInstance();
|
||||||
return CacheManager.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
<session-factory>
|
<session-factory>
|
||||||
|
|
||||||
<!-- jdbc connection properties -->
|
<!-- jdbc connection properties -->
|
||||||
|
<property name="hibernate.cache.provider_class">org.alfresco.repo.cache.InternalEhCacheManagerFactoryBean</property>
|
||||||
|
<property name="hibernate.cache.use_second_level_cache">true</property>
|
||||||
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
|
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
|
||||||
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
|
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
|
||||||
<property name="hibernate.connection.url">jdbc:hsqldb:mem:.;sql.enforce_strict_size=true</property>
|
<property name="hibernate.connection.url">jdbc:hsqldb:mem:.;sql.enforce_strict_size=true</property>
|
||||||
|
Reference in New Issue
Block a user