HHH-8159 - Apply fixups indicated by analysis tools

This commit is contained in:
Steve Ebersole 2013-04-30 13:27:38 -05:00
parent 09a54fdc54
commit 97e28200f0
54 changed files with 2312 additions and 2399 deletions

View File

@ -29,8 +29,10 @@ import java.util.Properties;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache; import net.sf.ehcache.Ehcache;
import net.sf.ehcache.util.ClassLoaderUtil; import net.sf.ehcache.util.ClassLoaderUtil;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.internal.nonstop.NonstopAccessStrategyFactory; import org.hibernate.cache.ehcache.internal.nonstop.NonstopAccessStrategyFactory;
import org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion; import org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion;
@ -40,7 +42,7 @@ import org.hibernate.cache.ehcache.internal.regions.EhcacheQueryResultsRegion;
import org.hibernate.cache.ehcache.internal.regions.EhcacheTimestampsRegion; import org.hibernate.cache.ehcache.internal.regions.EhcacheTimestampsRegion;
import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactory; import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactory;
import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactoryImpl; import org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactoryImpl;
import org.hibernate.cache.ehcache.internal.util.HibernateUtil; import org.hibernate.cache.ehcache.internal.util.HibernateEhcacheUtils;
import org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper; import org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper;
import org.hibernate.cache.spi.CacheDataDescription; import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.CollectionRegion;
@ -51,7 +53,6 @@ import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TimestampsRegion; import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.Settings; import org.hibernate.cfg.Settings;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.service.spi.InjectService; import org.hibernate.service.spi.InjectService;
/** /**
@ -101,32 +102,25 @@ abstract class AbstractEhcacheRegionFactory implements RegionFactory {
new NonstopAccessStrategyFactory( new EhcacheAccessStrategyFactoryImpl() ); new NonstopAccessStrategyFactory( new EhcacheAccessStrategyFactoryImpl() );
/** /**
* Whether to optimize for minimals puts or minimal gets. * {@inheritDoc}
* <p/> * <p/>
* Indicates whether when operating in non-strict read/write or read-only mode
* Hibernate should optimize the access patterns for minimal puts or minimal gets.
* In Ehcache we default to minimal puts since this should have minimal to no * In Ehcache we default to minimal puts since this should have minimal to no
* affect on unclustered users, and has great benefit for clustered users. * affect on unclustered users, and has great benefit for clustered users.
* <p/>
* This setting can be overridden by setting the "hibernate.cache.use_minimal_puts"
* property in the Hibernate configuration.
* *
* @return true, optimize for minimal puts * @return true, optimize for minimal puts
*/ */
@Override
public boolean isMinimalPutsEnabledByDefault() { public boolean isMinimalPutsEnabledByDefault() {
return true; return true;
} }
/** @Override
* {@inheritDoc}
*/
public long nextTimestamp() { public long nextTimestamp() {
return net.sf.ehcache.util.Timestamper.next(); return net.sf.ehcache.util.Timestamper.next();
} }
/** @Override
* {@inheritDoc}
*/
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata)
throws CacheException { throws CacheException {
return new EhcacheEntityRegion( accessStrategyFactory, getCache( regionName ), settings, metadata, properties ); return new EhcacheEntityRegion( accessStrategyFactory, getCache( regionName ), settings, metadata, properties );
@ -135,13 +129,20 @@ abstract class AbstractEhcacheRegionFactory implements RegionFactory {
@Override @Override
public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata)
throws CacheException { throws CacheException {
return new EhcacheNaturalIdRegion( accessStrategyFactory, getCache( regionName ), settings, metadata, properties ); return new EhcacheNaturalIdRegion(
accessStrategyFactory,
getCache( regionName ),
settings,
metadata,
properties
);
} }
/** @Override
* {@inheritDoc} public CollectionRegion buildCollectionRegion(
*/ String regionName,
public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) Properties properties,
CacheDataDescription metadata)
throws CacheException { throws CacheException {
return new EhcacheCollectionRegion( return new EhcacheCollectionRegion(
accessStrategyFactory, accessStrategyFactory,
@ -152,23 +153,20 @@ abstract class AbstractEhcacheRegionFactory implements RegionFactory {
); );
} }
/** @Override
* {@inheritDoc}
*/
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException { public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException {
return new EhcacheQueryResultsRegion( accessStrategyFactory, getCache( regionName ), properties ); return new EhcacheQueryResultsRegion( accessStrategyFactory, getCache( regionName ), properties );
} }
@InjectService @InjectService
@SuppressWarnings("UnusedDeclaration")
public void setClassLoaderService(ClassLoaderService classLoaderService) { public void setClassLoaderService(ClassLoaderService classLoaderService) {
this.classLoaderService = classLoaderService; this.classLoaderService = classLoaderService;
} }
private ClassLoaderService classLoaderService; private ClassLoaderService classLoaderService;
/** @Override
* {@inheritDoc}
*/
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException { public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException {
return new EhcacheTimestampsRegion( accessStrategyFactory, getCache( regionName ), properties ); return new EhcacheTimestampsRegion( accessStrategyFactory, getCache( regionName ), properties );
} }
@ -182,7 +180,7 @@ abstract class AbstractEhcacheRegionFactory implements RegionFactory {
cache = manager.getEhcache( name ); cache = manager.getEhcache( name );
LOG.debug( "started EHCache region: " + name ); LOG.debug( "started EHCache region: " + name );
} }
HibernateUtil.validateEhcache( cache ); HibernateEhcacheUtils.validateEhcache( cache );
return cache; return cache;
} }
catch (net.sf.ehcache.CacheException e) { catch (net.sf.ehcache.CacheException e) {
@ -200,7 +198,7 @@ abstract class AbstractEhcacheRegionFactory implements RegionFactory {
url = classLoaderService.locateResource( configurationResourceName ); url = classLoaderService.locateResource( configurationResourceName );
} }
if ( url == null ) { if ( url == null ) {
ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader(); final ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader();
if ( standardClassloader != null ) { if ( standardClassloader != null ) {
url = standardClassloader.getResource( configurationResourceName ); url = standardClassloader.getResource( configurationResourceName );
} }

View File

@ -40,42 +40,96 @@ import static org.jboss.logging.Logger.Level.WARN;
@MessageLogger(projectCode = "HHH") @MessageLogger(projectCode = "HHH")
public interface EhCacheMessageLogger extends CoreMessageLogger { public interface EhCacheMessageLogger extends CoreMessageLogger {
/**
* Log a message (WARN) about attempt to start an already started Ehcache region factory
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message( value = "Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to " @Message(
+ "buildSessionFactory. Using previously created EhCacheProvider. If this behaviour is required, consider " value = "Attempt to restart an already started EhCacheRegionFactory. Use sessionFactory.close() between " +
+ "using net.sf.ehcache.hibernate.SingletonEhCacheProvider.", id = 20001 ) "repeated calls to buildSessionFactory. Using previously created EhCacheRegionFactory. If this " +
"behaviour is required, consider using org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory.",
id = 20001
)
void attemptToRestartAlreadyStartedEhCacheProvider(); void attemptToRestartAlreadyStartedEhCacheProvider();
/**
* Log a message (WARN) about inability to find configuration file
*
* @param name The name of the configuration file
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Could not find configuration [%s]; using defaults.", id = 20002) @Message(value = "Could not find configuration [%s]; using defaults.", id = 20002)
void unableToFindConfiguration(String name); void unableToFindConfiguration(String name);
/**
* Log a message (WARN) about inability to find named cache configuration
*
* @param name The name of the cache configuration
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "Could not find a specific ehcache configuration for cache named [%s]; using defaults.", id = 20003) @Message(value = "Could not find a specific ehcache configuration for cache named [%s]; using defaults.", id = 20003)
void unableToFindEhCacheConfiguration(String name); void unableToFindEhCacheConfiguration(String name);
/**
* Logs a message about not being able to resolve the configuration by resource name.
*
* @param configurationResourceName The resource name we attempted to resolve
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message( value = "A configurationResourceName was set to %s but the resource could not be loaded from the classpath. Ehcache will configure itself using defaults.", id = 20004 ) @Message(
value = "A configurationResourceName was set to %s but the resource could not be loaded from the classpath. " +
"Ehcache will configure itself using defaults.",
id = 20004
)
void unableToLoadConfiguration(String configurationResourceName); void unableToLoadConfiguration(String configurationResourceName);
/**
* Logs a message (WARN) about attempt to use an incompatible
* {@link net.sf.ehcache.config.TerracottaConfiguration.ValueMode}.
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message( value = "The default cache value mode for this Ehcache configuration is \"identity\". This is incompatible with clustered " @Message(
+ "Hibernate caching - the value mode has therefore been switched to \"serialization\"", id = 20005 ) value = "The default cache value mode for this Ehcache configuration is \"identity\". " +
"This is incompatible with clustered Hibernate caching - the value mode has therefore been " +
"switched to \"serialization\"",
id = 20005
)
void incompatibleCacheValueMode(); void incompatibleCacheValueMode();
/**
* Logs a message (WARN) about attempt to use an incompatible
* {@link net.sf.ehcache.config.TerracottaConfiguration.ValueMode}.
*
* @param cacheName The name of the cache whose config attempted to specify value mode.
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - " @Message(value = "The value mode for the cache[%s] is \"identity\". This is incompatible with clustered Hibernate caching - "
+ "the value mode has therefore been switched to \"serialization\"", id = 20006) + "the value mode has therefore been switched to \"serialization\"", id = 20006)
void incompatibleCacheValueModePerCache(String cacheName); void incompatibleCacheValueModePerCache(String cacheName);
/**
* Log a message (WARN) about an attempt to specify read-only caching for a mutable entity
*
* @param entityName The name of the entity
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "read-only cache configured for mutable entity [%s]", id = 20007) @Message(value = "read-only cache configured for mutable entity [%s]", id = 20007)
void readOnlyCacheConfiguredForMutableEntity(String entityName); void readOnlyCacheConfiguredForMutableEntity(String entityName);
/**
* Log a message (WARN) about expiry of soft-locked region.
*
* @param regionName The region name
* @param key The cache key
* @param lock The lock
*/
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message( value = "Cache[%s] Key[%s] Lockable[%s]\n" @Message(
+ "A soft-locked cache entry was expired by the underlying Ehcache. " value = "Cache[%s] Key[%s] Lockable[%s]\n" +
+ "If this happens regularly you should consider increasing the cache timeouts and/or capacity limits", id = 20008 ) "A soft-locked cache entry was expired by the underlying Ehcache. If this happens regularly you " +
"should consider increasing the cache timeouts and/or capacity limits",
id = 20008
)
void softLockedCacheExpired(String regionName, Object key, String lock); void softLockedCacheExpired(String regionName, Object key, String lock);
} }

View File

@ -30,10 +30,11 @@ import java.util.Properties;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.Configuration; import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.ConfigurationFactory; import net.sf.ehcache.config.ConfigurationFactory;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.internal.util.HibernateUtil; import org.hibernate.cache.ehcache.internal.util.HibernateEhcacheUtils;
import org.hibernate.cfg.Settings; import org.hibernate.cfg.Settings;
/** /**
@ -53,19 +54,24 @@ public class EhCacheRegionFactory extends AbstractEhcacheRegionFactory {
); );
/**
* Creates a non-singleton EhCacheRegionFactory
*/
@SuppressWarnings("UnusedDeclaration")
public EhCacheRegionFactory() { public EhCacheRegionFactory() {
} }
/** /**
* Creates a non-singleton EhCacheRegionFactory * Creates a non-singleton EhCacheRegionFactory
*
* @param prop Not used
*/ */
@SuppressWarnings("UnusedDeclaration")
public EhCacheRegionFactory(Properties prop) { public EhCacheRegionFactory(Properties prop) {
super(); super();
} }
/** @Override
* {@inheritDoc}
*/
public void start(Settings settings, Properties properties) throws CacheException { public void start(Settings settings, Properties properties) throws CacheException {
this.settings = settings; this.settings = settings;
if ( manager != null ) { if ( manager != null ) {
@ -79,7 +85,7 @@ public class EhCacheRegionFactory extends AbstractEhcacheRegionFactory {
configurationResourceName = (String) properties.get( NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME ); configurationResourceName = (String) properties.get( NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME );
} }
if ( configurationResourceName == null || configurationResourceName.length() == 0 ) { if ( configurationResourceName == null || configurationResourceName.length() == 0 ) {
Configuration configuration = ConfigurationFactory.parseConfiguration(); final Configuration configuration = ConfigurationFactory.parseConfiguration();
manager = new CacheManager( configuration ); manager = new CacheManager( configuration );
} }
else { else {
@ -90,7 +96,7 @@ public class EhCacheRegionFactory extends AbstractEhcacheRegionFactory {
catch (MalformedURLException e) { catch (MalformedURLException e) {
url = loadResource( configurationResourceName ); url = loadResource( configurationResourceName );
} }
Configuration configuration = HibernateUtil.loadAndCorrectConfiguration( url ); final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration( url );
manager = new CacheManager( configuration ); manager = new CacheManager( configuration );
} }
mbeanRegistrationHelper.registerMBean( manager, properties ); mbeanRegistrationHelper.registerMBean( manager, properties );
@ -112,9 +118,7 @@ public class EhCacheRegionFactory extends AbstractEhcacheRegionFactory {
} }
} }
/** @Override
* {@inheritDoc}
*/
public void stop() { public void stop() {
try { try {
if ( manager != null ) { if ( manager != null ) {

View File

@ -30,10 +30,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.Configuration; import net.sf.ehcache.config.Configuration;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.internal.util.HibernateUtil; import org.hibernate.cache.ehcache.internal.util.HibernateEhcacheUtils;
import org.hibernate.cfg.Settings; import org.hibernate.cfg.Settings;
/** /**
@ -45,23 +46,31 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory { public class SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger( private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class, EhCacheMessageLogger.class,
SingletonEhCacheRegionFactory.class.getName() SingletonEhCacheRegionFactory.class.getName()
); );
private static final AtomicInteger REFERENCE_COUNT = new AtomicInteger(); private static final AtomicInteger REFERENCE_COUNT = new AtomicInteger();
/** /**
* Returns a representation of the singleton EhCacheRegionFactory * Constructs a SingletonEhCacheRegionFactory
*/ */
@SuppressWarnings("UnusedDeclaration")
public SingletonEhCacheRegionFactory() {
}
/**
* Constructs a SingletonEhCacheRegionFactory
*
* @param prop Not used
*/
@SuppressWarnings("UnusedDeclaration")
public SingletonEhCacheRegionFactory(Properties prop) { public SingletonEhCacheRegionFactory(Properties prop) {
super(); super();
} }
/** @Override
* {@inheritDoc}
*/
public void start(Settings settings, Properties properties) throws CacheException { public void start(Settings settings, Properties properties) throws CacheException {
this.settings = settings; this.settings = settings;
try { try {
@ -88,7 +97,7 @@ public class SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory
} }
url = loadResource( configurationResourceName ); url = loadResource( configurationResourceName );
} }
Configuration configuration = HibernateUtil.loadAndCorrectConfiguration( url ); final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration( url );
manager = CacheManager.create( configuration ); manager = CacheManager.create( configuration );
REFERENCE_COUNT.incrementAndGet(); REFERENCE_COUNT.incrementAndGet();
} }
@ -99,9 +108,7 @@ public class SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory
} }
} }
/** @Override
* {@inheritDoc}
*/
public void stop() { public void stop() {
try { try {
if ( manager != null ) { if ( manager != null ) {
@ -115,5 +122,4 @@ public class SingletonEhCacheRegionFactory extends AbstractEhcacheRegionFactory
throw new CacheException( e ); throw new CacheException( e );
} }
} }
} }

View File

@ -26,9 +26,9 @@ package org.hibernate.cache.ehcache;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
/** /**
@ -49,7 +49,8 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
EhCacheRegionFactory.class, EhCacheRegionFactory.class,
"ehcache", "ehcache",
EhCacheRegionFactory.class.getSimpleName(), EhCacheRegionFactory.class.getSimpleName(),
"org.hibernate.cache.EhCacheRegionFactory" // legacy impl class name // legacy impl class name
"org.hibernate.cache.EhCacheRegionFactory"
) )
); );
@ -59,7 +60,8 @@ public class StrategyRegistrationProviderImpl implements StrategyRegistrationPro
SingletonEhCacheRegionFactory.class, SingletonEhCacheRegionFactory.class,
"ehcache-singleton", "ehcache-singleton",
SingletonEhCacheRegionFactory.class.getSimpleName(), SingletonEhCacheRegionFactory.class.getSimpleName(),
"org.hibernate.cache.SingletonEhCacheRegionFactory" // legacy impl class name // legacy impl class name
"org.hibernate.cache.SingletonEhCacheRegionFactory"
) )
); );

View File

@ -24,6 +24,7 @@
package org.hibernate.cache.ehcache.internal.nonstop; package org.hibernate.cache.ehcache.internal.nonstop;
import net.sf.ehcache.constructs.nonstop.NonStopCacheException; import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.cache.ehcache.EhCacheMessageLogger; import org.hibernate.cache.ehcache.EhCacheMessageLogger;
@ -74,7 +75,7 @@ public final class HibernateNonstopCacheExceptionHandler {
* {@link HibernateNonstopCacheExceptionHandler#HIBERNATE_LOG_EXCEPTION_STACK_TRACE_PROPERTY} is set to true, logs the exception stack * {@link HibernateNonstopCacheExceptionHandler#HIBERNATE_LOG_EXCEPTION_STACK_TRACE_PROPERTY} is set to true, logs the exception stack
* trace too, otherwise logs the exception message only * trace too, otherwise logs the exception message only
* *
* @param nonStopCacheException * @param nonStopCacheException The exception to handle
*/ */
public void handleNonstopCacheException(NonStopCacheException nonStopCacheException) { public void handleNonstopCacheException(NonStopCacheException nonStopCacheException) {
if ( Boolean.getBoolean( HIBERNATE_THROW_EXCEPTION_ON_TIMEOUT_PROPERTY ) ) { if ( Boolean.getBoolean( HIBERNATE_THROW_EXCEPTION_ON_TIMEOUT_PROPERTY ) ) {

View File

@ -46,16 +46,16 @@ public class NonstopAccessStrategyFactory implements EhcacheAccessStrategyFactor
/** /**
* Constructor accepting the actual factory * Constructor accepting the actual factory
* *
* @param actualFactory * @param actualFactory The wrapped RegionAccessStrategy factory
*/ */
public NonstopAccessStrategyFactory(EhcacheAccessStrategyFactory actualFactory) { public NonstopAccessStrategyFactory(EhcacheAccessStrategyFactory actualFactory) {
this.actualFactory = actualFactory; this.actualFactory = actualFactory;
} }
/** @Override
* {@inheritDoc} public EntityRegionAccessStrategy createEntityRegionAccessStrategy(
*/ EhcacheEntityRegion entityRegion,
public EntityRegionAccessStrategy createEntityRegionAccessStrategy(EhcacheEntityRegion entityRegion, AccessType accessType) { AccessType accessType) {
return new NonstopAwareEntityRegionAccessStrategy( return new NonstopAwareEntityRegionAccessStrategy(
actualFactory.createEntityRegionAccessStrategy( entityRegion, accessType ), actualFactory.createEntityRegionAccessStrategy( entityRegion, accessType ),
HibernateNonstopCacheExceptionHandler.getInstance() HibernateNonstopCacheExceptionHandler.getInstance()
@ -63,7 +63,8 @@ public class NonstopAccessStrategyFactory implements EhcacheAccessStrategyFactor
} }
@Override @Override
public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion naturalIdRegion, public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(
EhcacheNaturalIdRegion naturalIdRegion,
AccessType accessType) { AccessType accessType) {
return new NonstopAwareNaturalIdRegionAccessStrategy( return new NonstopAwareNaturalIdRegionAccessStrategy(
actualFactory.createNaturalIdRegionAccessStrategy( actualFactory.createNaturalIdRegionAccessStrategy(
@ -73,10 +74,9 @@ public class NonstopAccessStrategyFactory implements EhcacheAccessStrategyFactor
); );
} }
/** @Override
* {@inheritDoc} public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(
*/ EhcacheCollectionRegion collectionRegion,
public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(EhcacheCollectionRegion collectionRegion,
AccessType accessType) { AccessType accessType) {
return new NonstopAwareCollectionRegionAccessStrategy( return new NonstopAwareCollectionRegionAccessStrategy(
actualFactory.createCollectionRegionAccessStrategy( actualFactory.createCollectionRegionAccessStrategy(

View File

@ -38,36 +38,28 @@ import org.hibernate.cache.spi.access.SoftLock;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class NonstopAwareCollectionRegionAccessStrategy implements CollectionRegionAccessStrategy { public class NonstopAwareCollectionRegionAccessStrategy implements CollectionRegionAccessStrategy {
private final CollectionRegionAccessStrategy actualStrategy; private final CollectionRegionAccessStrategy actualStrategy;
private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler;
/** /**
* Constructor accepting the actual {@link CollectionRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler} * Constructor accepting the actual {@link CollectionRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler}
* *
* @param actualStrategy * @param actualStrategy The wrapped strategy
* @param hibernateNonstopExceptionHandler * @param hibernateNonstopExceptionHandler The exception handler
*/ */
public NonstopAwareCollectionRegionAccessStrategy(CollectionRegionAccessStrategy actualStrategy, public NonstopAwareCollectionRegionAccessStrategy(
CollectionRegionAccessStrategy actualStrategy,
HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) {
this.actualStrategy = actualStrategy; this.actualStrategy = actualStrategy;
this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler;
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#getRegion()
*/
public CollectionRegion getRegion() { public CollectionRegion getRegion() {
return actualStrategy.getRegion(); return actualStrategy.getRegion();
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evict(java.lang.Object)
*/
public void evict(Object key) throws CacheException { public void evict(Object key) throws CacheException {
try { try {
actualStrategy.evict( key ); actualStrategy.evict( key );
@ -77,11 +69,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evictAll()
*/
public void evictAll() throws CacheException { public void evictAll() throws CacheException {
try { try {
actualStrategy.evictAll(); actualStrategy.evictAll();
@ -91,11 +79,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#get(java.lang.Object, long)
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
return actualStrategy.get( key, txTimestamp ); return actualStrategy.get( key, txTimestamp );
@ -106,11 +90,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
try { try {
return actualStrategy.lockItem( key, version ); return actualStrategy.lockItem( key, version );
@ -121,11 +101,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion()
*/
public SoftLock lockRegion() throws CacheException { public SoftLock lockRegion() throws CacheException {
try { try {
return actualStrategy.lockRegion(); return actualStrategy.lockRegion();
@ -136,12 +112,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object,
* boolean)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
try { try {
@ -153,11 +124,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException {
try { try {
return actualStrategy.putFromLoad( key, value, txTimestamp, version ); return actualStrategy.putFromLoad( key, value, txTimestamp, version );
@ -168,11 +135,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#remove(java.lang.Object)
*/
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
actualStrategy.remove( key ); actualStrategy.remove( key );
@ -182,11 +145,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll()
*/
public void removeAll() throws CacheException { public void removeAll() throws CacheException {
try { try {
actualStrategy.removeAll(); actualStrategy.removeAll();
@ -196,11 +155,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockItem( key, lock ); actualStrategy.unlockItem( key, lock );
@ -210,11 +165,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockRegion(SoftLock lock) throws CacheException { public void unlockRegion(SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockRegion( lock ); actualStrategy.unlockRegion( lock );

View File

@ -38,36 +38,28 @@ import org.hibernate.cache.spi.access.SoftLock;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAccessStrategy { public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAccessStrategy {
private final EntityRegionAccessStrategy actualStrategy; private final EntityRegionAccessStrategy actualStrategy;
private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler;
/** /**
* Constructor accepting the actual {@link EntityRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler} * Constructor accepting the actual {@link EntityRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler}
* *
* @param actualStrategy * @param actualStrategy The wrapped EntityRegionAccessStrategy
* @param hibernateNonstopExceptionHandler * @param hibernateNonstopExceptionHandler The exception handler
*/ */
public NonstopAwareEntityRegionAccessStrategy(EntityRegionAccessStrategy actualStrategy, public NonstopAwareEntityRegionAccessStrategy(
EntityRegionAccessStrategy actualStrategy,
HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) {
this.actualStrategy = actualStrategy; this.actualStrategy = actualStrategy;
this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler;
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#getRegion()
*/
public EntityRegion getRegion() { public EntityRegion getRegion() {
return actualStrategy.getRegion(); return actualStrategy.getRegion();
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#afterInsert(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public boolean afterInsert(Object key, Object value, Object version) throws CacheException { public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
try { try {
return actualStrategy.afterInsert( key, value, version ); return actualStrategy.afterInsert( key, value, version );
@ -78,12 +70,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#afterUpdate(java.lang.Object, java.lang.Object, java.lang.Object,
* java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException { throws CacheException {
try { try {
@ -95,11 +82,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evict(java.lang.Object)
*/
public void evict(Object key) throws CacheException { public void evict(Object key) throws CacheException {
try { try {
actualStrategy.evict( key ); actualStrategy.evict( key );
@ -109,11 +92,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evictAll()
*/
public void evictAll() throws CacheException { public void evictAll() throws CacheException {
try { try {
actualStrategy.evictAll(); actualStrategy.evictAll();
@ -123,11 +102,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#get(java.lang.Object, long)
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
return actualStrategy.get( key, txTimestamp ); return actualStrategy.get( key, txTimestamp );
@ -138,11 +113,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#insert(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public boolean insert(Object key, Object value, Object version) throws CacheException { public boolean insert(Object key, Object value, Object version) throws CacheException {
try { try {
return actualStrategy.insert( key, value, version ); return actualStrategy.insert( key, value, version );
@ -153,11 +124,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
try { try {
return actualStrategy.lockItem( key, version ); return actualStrategy.lockItem( key, version );
@ -168,11 +135,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion()
*/
public SoftLock lockRegion() throws CacheException { public SoftLock lockRegion() throws CacheException {
try { try {
return actualStrategy.lockRegion(); return actualStrategy.lockRegion();
@ -183,12 +146,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object,
* boolean)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
try { try {
@ -200,11 +158,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException {
try { try {
return actualStrategy.putFromLoad( key, value, txTimestamp, version ); return actualStrategy.putFromLoad( key, value, txTimestamp, version );
@ -215,11 +169,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#remove(java.lang.Object)
*/
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
actualStrategy.remove( key ); actualStrategy.remove( key );
@ -229,11 +179,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll()
*/
public void removeAll() throws CacheException { public void removeAll() throws CacheException {
try { try {
actualStrategy.removeAll(); actualStrategy.removeAll();
@ -243,11 +189,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockItem( key, lock ); actualStrategy.unlockItem( key, lock );
@ -257,11 +199,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockRegion(SoftLock lock) throws CacheException { public void unlockRegion(SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockRegion( lock ); actualStrategy.unlockRegion( lock );
@ -271,12 +209,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#update(java.lang.Object, java.lang.Object, java.lang.Object,
* java.lang.Object)
*/
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException { throws CacheException {
try { try {

View File

@ -38,17 +38,17 @@ import org.hibernate.cache.spi.access.SoftLock;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegionAccessStrategy { public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegionAccessStrategy {
private final NaturalIdRegionAccessStrategy actualStrategy; private final NaturalIdRegionAccessStrategy actualStrategy;
private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler; private final HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler;
/** /**
* Constructor accepting the actual {@link NaturalIdRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler} * Constructor accepting the actual {@link NaturalIdRegionAccessStrategy} and the {@link HibernateNonstopCacheExceptionHandler}
* *
* @param actualStrategy * @param actualStrategy The wrapped NaturalIdRegionAccessStrategy
* @param hibernateNonstopExceptionHandler * @param hibernateNonstopExceptionHandler The exception handler
*/ */
public NonstopAwareNaturalIdRegionAccessStrategy(NaturalIdRegionAccessStrategy actualStrategy, public NonstopAwareNaturalIdRegionAccessStrategy(
NaturalIdRegionAccessStrategy actualStrategy,
HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) { HibernateNonstopCacheExceptionHandler hibernateNonstopExceptionHandler) {
this.actualStrategy = actualStrategy; this.actualStrategy = actualStrategy;
this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler; this.hibernateNonstopExceptionHandler = hibernateNonstopExceptionHandler;
@ -98,20 +98,12 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#getRegion()
*/
public NaturalIdRegion getRegion() { public NaturalIdRegion getRegion() {
return actualStrategy.getRegion(); return actualStrategy.getRegion();
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evict(java.lang.Object)
*/
public void evict(Object key) throws CacheException { public void evict(Object key) throws CacheException {
try { try {
actualStrategy.evict( key ); actualStrategy.evict( key );
@ -121,11 +113,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evictAll()
*/
public void evictAll() throws CacheException { public void evictAll() throws CacheException {
try { try {
actualStrategy.evictAll(); actualStrategy.evictAll();
@ -135,11 +123,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#get(java.lang.Object, long)
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
return actualStrategy.get( key, txTimestamp ); return actualStrategy.get( key, txTimestamp );
@ -150,11 +134,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
try { try {
return actualStrategy.lockItem( key, version ); return actualStrategy.lockItem( key, version );
@ -165,11 +145,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion()
*/
public SoftLock lockRegion() throws CacheException { public SoftLock lockRegion() throws CacheException {
try { try {
return actualStrategy.lockRegion(); return actualStrategy.lockRegion();
@ -180,12 +156,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object,
* boolean)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
try { try {
@ -197,11 +168,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException {
try { try {
return actualStrategy.putFromLoad( key, value, txTimestamp, version ); return actualStrategy.putFromLoad( key, value, txTimestamp, version );
@ -212,11 +179,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#remove(java.lang.Object)
*/
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
actualStrategy.remove( key ); actualStrategy.remove( key );
@ -226,11 +189,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll()
*/
public void removeAll() throws CacheException { public void removeAll() throws CacheException {
try { try {
actualStrategy.removeAll(); actualStrategy.removeAll();
@ -240,11 +199,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockItem( key, lock ); actualStrategy.unlockItem( key, lock );
@ -254,11 +209,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio
} }
} }
/** @Override
* {@inheritDoc}
*
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
*/
public void unlockRegion(SoftLock lock) throws CacheException { public void unlockRegion(SoftLock lock) throws CacheException {
try { try {
actualStrategy.unlockRegion( lock ); actualStrategy.unlockRegion( lock );

View File

@ -0,0 +1,5 @@
/**
* Support for handling non-stop caches. Really no idea. The Ehcache guys added this and tbh I really do not
* understand the intent
*/
package org.hibernate.cache.ehcache.internal.nonstop;

View File

@ -47,22 +47,26 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheCollectionRegion extends EhcacheTransactionalDataRegion implements CollectionRegion { public class EhcacheCollectionRegion extends EhcacheTransactionalDataRegion implements CollectionRegion {
/** /**
* Constructs an EhcacheCollectionRegion around the given underlying cache. * Constructs an EhcacheCollectionRegion around the given underlying cache.
* *
* @param accessStrategyFactory * @param accessStrategyFactory The factory for building needed CollectionRegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param settings The Hibernate settings
* @param metadata Metadata about the data to be cached in this region
* @param properties Any additional[ properties
*/ */
public EhcacheCollectionRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache underlyingCache, Settings settings, public EhcacheCollectionRegion(
CacheDataDescription metadata, Properties properties) { EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Settings settings,
CacheDataDescription metadata,
Properties properties) {
super( accessStrategyFactory, underlyingCache, settings, metadata, properties ); super( accessStrategyFactory, underlyingCache, settings, metadata, properties );
} }
/** @Override
* {@inheritDoc}
*/
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
return accessStrategyFactory.createCollectionRegionAccessStrategy( this, accessType ); return getAccessStrategyFactory().createCollectionRegionAccessStrategy( this, accessType );
} }
} }

View File

@ -32,6 +32,7 @@ import java.util.Properties;
import net.sf.ehcache.Ehcache; import net.sf.ehcache.Ehcache;
import net.sf.ehcache.constructs.nonstop.NonStopCacheException; import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
import net.sf.ehcache.util.Timestamper; import net.sf.ehcache.util.Timestamper;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
@ -52,7 +53,6 @@ import org.hibernate.cache.spi.Region;
* @author Alex Snaps * @author Alex Snaps
*/ */
public abstract class EhcacheDataRegion implements Region { public abstract class EhcacheDataRegion implements Region {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger( private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class, EhCacheMessageLogger.class,
EhcacheDataRegion.class.getName() EhcacheDataRegion.class.getName()
@ -60,16 +60,8 @@ public abstract class EhcacheDataRegion implements Region {
private static final String CACHE_LOCK_TIMEOUT_PROPERTY = "net.sf.ehcache.hibernate.cache_lock_timeout"; private static final String CACHE_LOCK_TIMEOUT_PROPERTY = "net.sf.ehcache.hibernate.cache_lock_timeout";
private static final int DEFAULT_CACHE_LOCK_TIMEOUT = 60000; private static final int DEFAULT_CACHE_LOCK_TIMEOUT = 60000;
/** private final Ehcache cache;
* Ehcache instance backing this Hibernate data region. private final EhcacheAccessStrategyFactory accessStrategyFactory;
*/
protected final Ehcache cache;
/**
* The {@link EhcacheAccessStrategyFactory} used for creating various access strategies
*/
protected final EhcacheAccessStrategyFactory accessStrategyFactory;
private final int cacheLockTimeout; private final int cacheLockTimeout;
@ -79,7 +71,7 @@ public abstract class EhcacheDataRegion implements Region {
EhcacheDataRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache cache, Properties properties) { EhcacheDataRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache cache, Properties properties) {
this.accessStrategyFactory = accessStrategyFactory; this.accessStrategyFactory = accessStrategyFactory;
this.cache = cache; this.cache = cache;
String timeout = properties.getProperty( final String timeout = properties.getProperty(
CACHE_LOCK_TIMEOUT_PROPERTY, CACHE_LOCK_TIMEOUT_PROPERTY,
Integer.toString( DEFAULT_CACHE_LOCK_TIMEOUT ) Integer.toString( DEFAULT_CACHE_LOCK_TIMEOUT )
); );
@ -87,18 +79,38 @@ public abstract class EhcacheDataRegion implements Region {
} }
/** /**
* {@inheritDoc} * Ehcache instance backing this Hibernate data region.
*/ */
public String getName() { protected Ehcache getCache() {
return cache.getName(); return cache;
} }
/** /**
* {@inheritDoc} * The {@link org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactory} used for creating
* various access strategies
*/ */
protected EhcacheAccessStrategyFactory getAccessStrategyFactory() {
return accessStrategyFactory;
}
/**
* Return the Ehcache instance backing this Hibernate data region.
*
* @return The underlying ehcache cache
*/
public Ehcache getEhcache() {
return getCache();
}
@Override
public String getName() {
return getCache().getName();
}
@Override
public void destroy() throws CacheException { public void destroy() throws CacheException {
try { try {
cache.getCacheManager().removeCache( cache.getName() ); getCache().getCacheManager().removeCache( getCache().getName() );
} }
catch (IllegalStateException e) { catch (IllegalStateException e) {
//When Spring and Hibernate are both involved this will happen in normal shutdown operation. //When Spring and Hibernate are both involved this will happen in normal shutdown operation.
@ -116,12 +128,10 @@ public abstract class EhcacheDataRegion implements Region {
} }
} }
/** @Override
* {@inheritDoc}
*/
public long getSizeInMemory() { public long getSizeInMemory() {
try { try {
return cache.calculateInMemorySize(); return getCache().calculateInMemorySize();
} }
catch (Throwable t) { catch (Throwable t) {
if ( t instanceof NonStopCacheException ) { if ( t instanceof NonStopCacheException ) {
@ -132,12 +142,10 @@ public abstract class EhcacheDataRegion implements Region {
} }
} }
/** @Override
* {@inheritDoc}
*/
public long getElementCountInMemory() { public long getElementCountInMemory() {
try { try {
return cache.getMemoryStoreSize(); return getCache().getMemoryStoreSize();
} }
catch (net.sf.ehcache.CacheException ce) { catch (net.sf.ehcache.CacheException ce) {
if ( ce instanceof NonStopCacheException ) { if ( ce instanceof NonStopCacheException ) {
@ -151,12 +159,10 @@ public abstract class EhcacheDataRegion implements Region {
} }
} }
/** @Override
* {@inheritDoc}
*/
public long getElementCountOnDisk() { public long getElementCountOnDisk() {
try { try {
return cache.getDiskStoreSize(); return getCache().getDiskStoreSize();
} }
catch (net.sf.ehcache.CacheException ce) { catch (net.sf.ehcache.CacheException ce) {
if ( ce instanceof NonStopCacheException ) { if ( ce instanceof NonStopCacheException ) {
@ -170,14 +176,12 @@ public abstract class EhcacheDataRegion implements Region {
} }
} }
/** @Override
* {@inheritDoc}
*/
public Map toMap() { public Map toMap() {
try { try {
Map<Object, Object> result = new HashMap<Object, Object>(); final Map<Object, Object> result = new HashMap<Object, Object>();
for ( Object key : cache.getKeys() ) { for ( Object key : getCache().getKeys() ) {
result.put( key, cache.get( key ).getObjectValue() ); result.put( key, getCache().get( key ).getObjectValue() );
} }
return result; return result;
} }
@ -193,33 +197,19 @@ public abstract class EhcacheDataRegion implements Region {
} }
} }
/** @Override
* {@inheritDoc}
*/
public long nextTimestamp() { public long nextTimestamp() {
return Timestamper.next(); return Timestamper.next();
} }
/** @Override
* {@inheritDoc}
*/
public int getTimeout() { public int getTimeout() {
return cacheLockTimeout; return cacheLockTimeout;
} }
/** @Override
* Return the Ehcache instance backing this Hibernate data region. public boolean contains(Object key) {
*/ return getCache().isKeyInCache( key );
public Ehcache getEhcache() {
return cache;
} }
/**
* Returns <code>true</code> if this region contains data for the given key.
* <p/>
* This is a Hibernate 3.5 method.
*/
public boolean contains(Object key) {
return cache.isKeyInCache( key );
}
} }

View File

@ -46,22 +46,26 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheEntityRegion extends EhcacheTransactionalDataRegion implements EntityRegion { public class EhcacheEntityRegion extends EhcacheTransactionalDataRegion implements EntityRegion {
/** /**
* Constructs an EhcacheEntityRegion around the given underlying cache. * Constructs an EhcacheCollectionRegion around the given underlying cache.
* *
* @param accessStrategyFactory * @param accessStrategyFactory The factory for building needed EntityRegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param settings The Hibernate settings
* @param metadata Metadata about the data to be cached in this region
* @param properties Any additional[ properties
*/ */
public EhcacheEntityRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache underlyingCache, Settings settings, public EhcacheEntityRegion(
CacheDataDescription metadata, Properties properties) { EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Settings settings,
CacheDataDescription metadata,
Properties properties) {
super( accessStrategyFactory, underlyingCache, settings, metadata, properties ); super( accessStrategyFactory, underlyingCache, settings, metadata, properties );
} }
/** @Override
* {@inheritDoc}
*/
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
return accessStrategyFactory.createEntityRegionAccessStrategy( this, accessType ); return getAccessStrategyFactory().createEntityRegionAccessStrategy( this, accessType );
} }
} }

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import net.sf.ehcache.Ehcache; import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element; import net.sf.ehcache.Element;
import net.sf.ehcache.constructs.nonstop.NonStopCacheException; import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.cache.CacheException; import org.hibernate.cache.CacheException;
@ -48,22 +49,26 @@ import org.hibernate.cache.spi.GeneralDataRegion;
* @author Alex Snaps * @author Alex Snaps
*/ */
abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements GeneralDataRegion { abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements GeneralDataRegion {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger( private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class, EhCacheMessageLogger.class,
EhcacheGeneralDataRegion.class.getName() EhcacheGeneralDataRegion.class.getName()
); );
/** /**
* Creates an EhcacheGeneralDataRegion using the given Ehcache instance as a backing. * Constructs an EhcacheGeneralDataRegion around the given underlying cache.
*
* @param accessStrategyFactory The factory for building needed RegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param properties Any additional[ properties
*/ */
public EhcacheGeneralDataRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache cache, Properties properties) { public EhcacheGeneralDataRegion(
super( accessStrategyFactory, cache, properties ); EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Properties properties) {
super( accessStrategyFactory, underlyingCache, properties );
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key) throws CacheException { public Object get(Object key) throws CacheException {
try { try {
LOG.debugf( "key: %s", key ); LOG.debugf( "key: %s", key );
@ -71,7 +76,7 @@ abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements Gen
return null; return null;
} }
else { else {
Element element = cache.get( key ); final Element element = getCache().get( key );
if ( element == null ) { if ( element == null ) {
LOG.debugf( "Element for key %s is null", key ); LOG.debugf( "Element for key %s is null", key );
return null; return null;
@ -93,14 +98,12 @@ abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements Gen
} }
} }
/** @Override
* {@inheritDoc}
*/
public void put(Object key, Object value) throws CacheException { public void put(Object key, Object value) throws CacheException {
LOG.debugf( "key: %s value: %s", key, value ); LOG.debugf( "key: %s value: %s", key, value );
try { try {
Element element = new Element( key, value ); final Element element = new Element( key, value );
cache.put( element ); getCache().put( element );
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
throw new CacheException( e ); throw new CacheException( e );
@ -119,12 +122,10 @@ abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements Gen
} }
} }
/** @Override
* {@inheritDoc}
*/
public void evict(Object key) throws CacheException { public void evict(Object key) throws CacheException {
try { try {
cache.remove( key ); getCache().remove( key );
} }
catch (ClassCastException e) { catch (ClassCastException e) {
throw new CacheException( e ); throw new CacheException( e );
@ -143,12 +144,10 @@ abstract class EhcacheGeneralDataRegion extends EhcacheDataRegion implements Gen
} }
} }
/** @Override
* {@inheritDoc}
*/
public void evictAll() throws CacheException { public void evictAll() throws CacheException {
try { try {
cache.removeAll(); getCache().removeAll();
} }
catch (IllegalStateException e) { catch (IllegalStateException e) {
throw new CacheException( e ); throw new CacheException( e );

View File

@ -47,20 +47,26 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheNaturalIdRegion extends EhcacheTransactionalDataRegion implements NaturalIdRegion { public class EhcacheNaturalIdRegion extends EhcacheTransactionalDataRegion implements NaturalIdRegion {
/** /**
* Constructs an EhcacheNaturalIdRegion around the given underlying cache. * Constructs an EhcacheNaturalIdRegion around the given underlying cache.
* *
* @param accessStrategyFactory * @param accessStrategyFactory The factory for building needed NaturalIdRegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param settings The Hibernate settings
* @param metadata Metadata about the data to be cached in this region
* @param properties Any additional[ properties
*/ */
public EhcacheNaturalIdRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache underlyingCache, Settings settings, public EhcacheNaturalIdRegion(
CacheDataDescription metadata, Properties properties) { EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Settings settings,
CacheDataDescription metadata,
Properties properties) {
super( accessStrategyFactory, underlyingCache, settings, metadata, properties ); super( accessStrategyFactory, underlyingCache, settings, metadata, properties );
} }
@Override @Override
public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
return accessStrategyFactory.createNaturalIdRegionAccessStrategy( this, accessType ); return getAccessStrategyFactory().createNaturalIdRegionAccessStrategy( this, accessType );
} }
} }

View File

@ -37,13 +37,17 @@ import org.hibernate.cache.spi.QueryResultsRegion;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheQueryResultsRegion extends EhcacheGeneralDataRegion implements QueryResultsRegion { public class EhcacheQueryResultsRegion extends EhcacheGeneralDataRegion implements QueryResultsRegion {
/** /**
* Constructs an EhcacheQueryResultsRegion around the given underlying cache. * Constructs an EhcacheQueryResultsRegion around the given underlying cache.
* *
* @param accessStrategyFactory * @param accessStrategyFactory The factory for building needed CollectionRegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param properties Any additional[ properties
*/ */
public EhcacheQueryResultsRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache underlyingCache, Properties properties) { public EhcacheQueryResultsRegion(
EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Properties properties) {
super( accessStrategyFactory, underlyingCache, properties ); super( accessStrategyFactory, underlyingCache, properties );
} }

View File

@ -38,13 +38,17 @@ import org.hibernate.cache.spi.TimestampsRegion;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheTimestampsRegion extends EhcacheGeneralDataRegion implements TimestampsRegion { public class EhcacheTimestampsRegion extends EhcacheGeneralDataRegion implements TimestampsRegion {
/** /**
* Constructs an EhcacheTimestampsRegion around the given underlying cache. * Constructs an EhcacheTimestampsRegion around the given underlying cache.
* *
* @param accessStrategyFactory * @param accessStrategyFactory The factory for building needed CollectionRegionAccessStrategy instance
* @param underlyingCache The ehcache cache instance
* @param properties Any additional[ properties
*/ */
public EhcacheTimestampsRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache underlyingCache, Properties properties) { public EhcacheTimestampsRegion(
EhcacheAccessStrategyFactory accessStrategyFactory,
Ehcache underlyingCache,
Properties properties) {
super( accessStrategyFactory, underlyingCache, properties ); super( accessStrategyFactory, underlyingCache, properties );
} }
} }

View File

@ -51,13 +51,9 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements TransactionalDataRegion { public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements TransactionalDataRegion {
private static final int LOCAL_LOCK_PROVIDER_CONCURRENCY = 128; private static final int LOCAL_LOCK_PROVIDER_CONCURRENCY = 128;
/** private final Settings settings;
* Hibernate settings associated with the persistence unit.
*/
protected final Settings settings;
/** /**
* Metadata associated with the objects stored in the region. * Metadata associated with the objects stored in the region.
@ -69,13 +65,14 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Construct an transactional Hibernate cache region around the given Ehcache instance. * Construct an transactional Hibernate cache region around the given Ehcache instance.
*/ */
EhcacheTransactionalDataRegion(EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache cache, Settings settings, EhcacheTransactionalDataRegion(
EhcacheAccessStrategyFactory accessStrategyFactory, Ehcache cache, Settings settings,
CacheDataDescription metadata, Properties properties) { CacheDataDescription metadata, Properties properties) {
super( accessStrategyFactory, cache, properties ); super( accessStrategyFactory, cache, properties );
this.settings = settings; this.settings = settings;
this.metadata = metadata; this.metadata = metadata;
Object context = cache.getInternalContext(); final Object context = cache.getInternalContext();
if ( context instanceof CacheLockProvider ) { if ( context instanceof CacheLockProvider ) {
this.lockProvider = (CacheLockProvider) context; this.lockProvider = (CacheLockProvider) context;
} }
@ -85,7 +82,7 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
} }
/** /**
* Return the hibernate settings * Access the Hibernate settings associated with the persistence unit.
* *
* @return settings * @return settings
*/ */
@ -93,26 +90,26 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
return settings; return settings;
} }
/** @Override
* {@inheritDoc}
*/
public boolean isTransactionAware() { public boolean isTransactionAware() {
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public CacheDataDescription getCacheDataDescription() { public CacheDataDescription getCacheDataDescription() {
return metadata; return metadata;
} }
/** /**
* Get the value mapped to this key, or null if no value is mapped to this key. * Get the value mapped to this key, or null if no value is mapped to this key.
*
* @param key The cache key
*
* @return The cached data
*/ */
public final Object get(Object key) { public final Object get(Object key) {
try { try {
Element element = cache.get( key ); final Element element = getCache().get( key );
if ( element == null ) { if ( element == null ) {
return null; return null;
} }
@ -134,11 +131,16 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Map the given value to the given key, replacing any existing mapping for this key * Map the given value to the given key, replacing any existing mapping for this key
*
* @param key The cache key
* @param value The data to cache
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void put(Object key, Object value) throws CacheException { public final void put(Object key, Object value) throws CacheException {
try { try {
Element element = new Element( key, value ); final Element element = new Element( key, value );
cache.put( element ); getCache().put( element );
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
throw new CacheException( e ); throw new CacheException( e );
@ -159,10 +161,14 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Remove the mapping for this key (if any exists). * Remove the mapping for this key (if any exists).
*
* @param key The cache key
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void remove(Object key) throws CacheException { public final void remove(Object key) throws CacheException {
try { try {
cache.remove( key ); getCache().remove( key );
} }
catch (ClassCastException e) { catch (ClassCastException e) {
throw new CacheException( e ); throw new CacheException( e );
@ -183,10 +189,12 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Remove all mapping from this cache region. * Remove all mapping from this cache region.
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void clear() throws CacheException { public final void clear() throws CacheException {
try { try {
cache.removeAll(); getCache().removeAll();
} }
catch (IllegalStateException e) { catch (IllegalStateException e) {
throw new CacheException( e ); throw new CacheException( e );
@ -204,6 +212,10 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Attempts to write lock the mapping for the given key. * Attempts to write lock the mapping for the given key.
*
* @param key The cache key
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void writeLock(Object key) { public final void writeLock(Object key) {
try { try {
@ -222,6 +234,10 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Attempts to write unlock the mapping for the given key. * Attempts to write unlock the mapping for the given key.
*
* @param key The cache key
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void writeUnlock(Object key) { public final void writeUnlock(Object key) {
try { try {
@ -240,6 +256,10 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Attempts to read lock the mapping for the given key. * Attempts to read lock the mapping for the given key.
*
* @param key The cache key
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void readLock(Object key) { public final void readLock(Object key) {
try { try {
@ -258,6 +278,10 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
/** /**
* Attempts to read unlock the mapping for the given key. * Attempts to read unlock the mapping for the given key.
*
* @param key The cache key
*
* @throws CacheException Indicates a problem accessing the cache
*/ */
public final void readUnlock(Object key) { public final void readUnlock(Object key) {
try { try {
@ -279,6 +303,8 @@ public class EhcacheTransactionalDataRegion extends EhcacheDataRegion implements
* <p/> * <p/>
* Independent locks are not locked by the cache when the cache is accessed directly. This means that for an independent lock * Independent locks are not locked by the cache when the cache is accessed directly. This means that for an independent lock
* lock holds taken through a region method will not block direct access to the cache via other means. * lock holds taken through a region method will not block direct access to the cache via other means.
*
* @return true/false. See discussion above.
*/ */
public final boolean locksAreIndependentOfCache() { public final boolean locksAreIndependentOfCache() {
return lockProvider instanceof StripedReadWriteLockSync; return lockProvider instanceof StripedReadWriteLockSync;

View File

@ -0,0 +1,4 @@
/**
* Defines {@link org.hibernate.cache.spi.RegionFactory} support for the Ehcache integration
*/
package org.hibernate.cache.ehcache.internal.regions;

View File

@ -37,24 +37,34 @@ import org.hibernate.cfg.Settings;
* @author Alex Snaps * @author Alex Snaps
*/ */
abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion> { abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion> {
private final T region;
/** private final Settings settings;
* The wrapped Hibernate cache region.
*/
protected final T region;
/**
* The settings for this persistence unit.
*/
protected final Settings settings;
/** /**
* Create an access strategy wrapping the given region. * Create an access strategy wrapping the given region.
*
* @param region The wrapped region. Accessible to subclasses via {@link #region()}
* @param settings The Hibernate settings. Accessible to subclasses via {@link #settings()}
*/ */
AbstractEhcacheAccessStrategy(T region, Settings settings) { AbstractEhcacheAccessStrategy(T region, Settings settings) {
this.region = region; this.region = region;
this.settings = settings; this.settings = settings;
} }
/**
* The wrapped Hibernate cache region.
*/
protected T region() {
return region;
}
/**
* The settings for this persistence unit.
*/
protected Settings settings() {
return settings;
}
/** /**
* This method is a placeholder for method signatures supplied by interfaces pulled in further down the class * This method is a placeholder for method signatures supplied by interfaces pulled in further down the class
* hierarchy. * hierarchy.
@ -84,6 +94,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion() * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockRegion()
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockRegion() * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockRegion()
*/ */
@SuppressWarnings("UnusedDeclaration")
public final SoftLock lockRegion() { public final SoftLock lockRegion() {
return null; return null;
} }
@ -94,6 +105,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock) * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock) * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockRegion(org.hibernate.cache.spi.access.SoftLock)
*/ */
@SuppressWarnings("UnusedDeclaration")
public final void unlockRegion(SoftLock lock) throws CacheException { public final void unlockRegion(SoftLock lock) throws CacheException {
region.clear(); region.clear();
} }
@ -114,6 +126,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll() * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#removeAll()
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#removeAll() * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#removeAll()
*/ */
@SuppressWarnings("UnusedDeclaration")
public final void removeAll() throws CacheException { public final void removeAll() throws CacheException {
region.clear(); region.clear();
} }
@ -134,6 +147,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evictAll() * @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evictAll()
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#evictAll() * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#evictAll()
*/ */
@SuppressWarnings("UnusedDeclaration")
public final void evictAll() throws CacheException { public final void evictAll() throws CacheException {
region.clear(); region.clear();
} }

View File

@ -44,13 +44,15 @@ import org.hibernate.cfg.Settings;
* @author Chris Dennis * @author Chris Dennis
* @author Alex Snaps * @author Alex Snaps
*/ */
abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion> abstract class AbstractReadWriteEhcacheAccessStrategy<T
extends EhcacheTransactionalDataRegion>
extends AbstractEhcacheAccessStrategy<T> { extends AbstractEhcacheAccessStrategy<T> {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger( private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class, EhCacheMessageLogger.class,
AbstractReadWriteEhcacheAccessStrategy.class.getName() AbstractReadWriteEhcacheAccessStrategy.class.getName()
); );
private final UUID uuid = UUID.randomUUID(); private final UUID uuid = UUID.randomUUID();
private final AtomicLong nextLockId = new AtomicLong(); private final AtomicLong nextLockId = new AtomicLong();
@ -74,9 +76,9 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
public final Object get(Object key, long txTimestamp) throws CacheException { public final Object get(Object key, long txTimestamp) throws CacheException {
readLockIfNeeded( key ); readLockIfNeeded( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
boolean readable = item != null && item.isReadable( txTimestamp ); final boolean readable = item != null && item.isReadable( txTimestamp );
if ( readable ) { if ( readable ) {
return item.getValue(); return item.getValue();
} }
@ -97,14 +99,19 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean) * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean)
*/ */
@Override @Override
public final boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public final boolean putFromLoad(
Object key,
Object value,
long txTimestamp,
Object version,
boolean minimalPutOverride)
throws CacheException { throws CacheException {
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
boolean writeable = item == null || item.isWriteable( txTimestamp, version, versionComparator ); final boolean writeable = item == null || item.isWriteable( txTimestamp, version, versionComparator );
if ( writeable ) { if ( writeable ) {
region.put( key, new Item( value, version, region.nextTimestamp() ) ); region().put( key, new Item( value, version, region().nextTimestamp() ) );
return true; return true;
} }
else { else {
@ -112,7 +119,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
@ -123,20 +130,20 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object) * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
*/ */
public final SoftLock lockItem(Object key, Object version) throws CacheException { public final SoftLock lockItem(Object key, Object version) throws CacheException {
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
long timeout = region.nextTimestamp() + region.getTimeout(); final long timeout = region().nextTimestamp() + region().getTimeout();
final Lock lock = (item == null) ? new Lock( timeout, uuid, nextLockId(), version ) : item.lock( final Lock lock = (item == null) ? new Lock( timeout, uuid, nextLockId(), version ) : item.lock(
timeout, timeout,
uuid, uuid,
nextLockId() nextLockId()
); );
region.put( key, lock ); region().put( key, lock );
return lock; return lock;
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
@ -147,9 +154,9 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock) * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/ */
public final void unlockItem(Object key, SoftLock lock) throws CacheException { public final void unlockItem(Object key, SoftLock lock) throws CacheException {
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
if ( (item != null) && item.isUnlockable( lock ) ) { if ( (item != null) && item.isUnlockable( lock ) ) {
decrementLock( key, (Lock) item ); decrementLock( key, (Lock) item );
@ -159,7 +166,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
@ -171,29 +178,29 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* Unlock and re-put the given key, lock combination. * Unlock and re-put the given key, lock combination.
*/ */
protected void decrementLock(Object key, Lock lock) { protected void decrementLock(Object key, Lock lock) {
lock.unlock( region.nextTimestamp() ); lock.unlock( region().nextTimestamp() );
region.put( key, lock ); region().put( key, lock );
} }
/** /**
* Handle the timeout of a previous lock mapped to this key * Handle the timeout of a previous lock mapped to this key
*/ */
protected void handleLockExpiry(Object key, Lockable lock) { protected void handleLockExpiry(Object key, Lockable lock) {
LOG.softLockedCacheExpired( region.getName(), key, lock == null ? "(null)" : lock.toString() ); LOG.softLockedCacheExpired( region().getName(), key, lock == null ? "(null)" : lock.toString() );
long ts = region.nextTimestamp() + region.getTimeout(); final long ts = region().nextTimestamp() + region().getTimeout();
// create new lock that times out immediately // create new lock that times out immediately
Lock newLock = new Lock( ts, uuid, nextLockId.getAndIncrement(), null ); final Lock newLock = new Lock( ts, uuid, nextLockId.getAndIncrement(), null );
newLock.unlock( ts ); newLock.unlock( ts );
region.put( key, newLock ); region().put( key, newLock );
} }
/** /**
* Read lock the entry for the given key if internal cache locks will not provide correct exclusion. * Read lock the entry for the given key if internal cache locks will not provide correct exclusion.
*/ */
private void readLockIfNeeded(Object key) { private void readLockIfNeeded(Object key) {
if ( region.locksAreIndependentOfCache() ) { if ( region().locksAreIndependentOfCache() ) {
region.readLock( key ); region().readLock( key );
} }
} }
@ -201,8 +208,8 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* Read unlock the entry for the given key if internal cache locks will not provide correct exclusion. * Read unlock the entry for the given key if internal cache locks will not provide correct exclusion.
*/ */
private void readUnlockIfNeeded(Object key) { private void readUnlockIfNeeded(Object key) {
if ( region.locksAreIndependentOfCache() ) { if ( region().locksAreIndependentOfCache() ) {
region.readUnlock( key ); region().readUnlock( key );
} }
} }
@ -242,8 +249,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
/** /**
* Wrapper type representing unlocked items. * Wrapper type representing unlocked items.
*/ */
protected final static class Item implements Serializable, Lockable { protected static final class Item implements Serializable, Lockable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Object value; private final Object value;
private final Object version; private final Object version;
@ -258,37 +264,28 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
this.timestamp = timestamp; this.timestamp = timestamp;
} }
/** @Override
* {@inheritDoc}
*/
public boolean isReadable(long txTimestamp) { public boolean isReadable(long txTimestamp) {
return txTimestamp > timestamp; return txTimestamp > timestamp;
} }
/** @Override
* {@inheritDoc} @SuppressWarnings("unchecked")
*/
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) { public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) {
return version != null && versionComparator.compare( version, newVersion ) < 0; return version != null && versionComparator.compare( version, newVersion ) < 0;
} }
/** @Override
* {@inheritDoc}
*/
public Object getValue() { public Object getValue() {
return value; return value;
} }
/** @Override
* {@inheritDoc}
*/
public boolean isUnlockable(SoftLock lock) { public boolean isUnlockable(SoftLock lock) {
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public Lock lock(long timeout, UUID uuid, long lockId) { public Lock lock(long timeout, UUID uuid, long lockId) {
return new Lock( timeout, uuid, lockId, version ); return new Lock( timeout, uuid, lockId, version );
} }
@ -297,8 +294,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
/** /**
* Wrapper type representing locked items. * Wrapper type representing locked items.
*/ */
protected final static class Lock implements Serializable, Lockable, SoftLock { protected static final class Lock implements Serializable, Lockable, SoftLock {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
private final UUID sourceUuid; private final UUID sourceUuid;
@ -320,16 +316,13 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
this.sourceUuid = sourceUuid; this.sourceUuid = sourceUuid;
} }
/** @Override
* {@inheritDoc}
*/
public boolean isReadable(long txTimestamp) { public boolean isReadable(long txTimestamp) {
return false; return false;
} }
/** @Override
* {@inheritDoc} @SuppressWarnings({"SimplifiableIfStatement", "unchecked"})
*/
public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) { public boolean isWriteable(long txTimestamp, Object newVersion, Comparator versionComparator) {
if ( txTimestamp > timeout ) { if ( txTimestamp > timeout ) {
// if timedout then allow write // if timedout then allow write
@ -339,30 +332,23 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
// if still locked then disallow write // if still locked then disallow write
return false; return false;
} }
return version == null ? txTimestamp > unlockTimestamp : versionComparator.compare( return version == null
version, ? txTimestamp > unlockTimestamp
newVersion : versionComparator.compare( version, newVersion ) < 0;
) < 0;
} }
/** @Override
* {@inheritDoc}
*/
public Object getValue() { public Object getValue() {
return null; return null;
} }
/** @Override
* {@inheritDoc}
*/
public boolean isUnlockable(SoftLock lock) { public boolean isUnlockable(SoftLock lock) {
return equals( lock ); return equals( lock );
} }
/**
* {@inheritDoc}
*/
@Override @Override
@SuppressWarnings("SimplifiableIfStatement")
public boolean equals(Object o) { public boolean equals(Object o) {
if ( o == this ) { if ( o == this ) {
return true; return true;
@ -375,12 +361,9 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public int hashCode() { public int hashCode() {
int hash = ( sourceUuid != null ? sourceUuid.hashCode() : 0 ); final int hash = (sourceUuid != null ? sourceUuid.hashCode() : 0);
int temp = (int) lockId; int temp = (int) lockId;
for ( int i = 1; i < Long.SIZE / Integer.SIZE; i++ ) { for ( int i = 1; i < Long.SIZE / Integer.SIZE; i++ ) {
temp ^= (lockId >>> (i * Integer.SIZE)); temp ^= (lockId >>> (i * Integer.SIZE));
@ -395,9 +378,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
return concurrent; return concurrent;
} }
/** @Override
* {@inheritDoc}
*/
public Lock lock(long timeout, UUID uuid, long lockId) { public Lock lock(long timeout, UUID uuid, long lockId) {
concurrent = true; concurrent = true;
multiplicity++; multiplicity++;
@ -414,13 +395,9 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder( "Lock Source-UUID:" + sourceUuid + " Lock-ID:" + lockId ); return "Lock Source-UUID:" + sourceUuid + " Lock-ID:" + lockId;
return sb.toString();
} }
} }
} }

View File

@ -32,42 +32,46 @@ import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
/** /**
* Factory to create {@link EntityRegionAccessStrategy} * Factory to create {@link org.hibernate.cache.spi.access.RegionAccessStrategy} instance
* *
* @author Abhishek Sanoujam * @author Abhishek Sanoujam
* @author Alex Snaps * @author Alex Snaps
*/ */
public interface EhcacheAccessStrategyFactory { public interface EhcacheAccessStrategyFactory {
/** /**
* Create {@link EntityRegionAccessStrategy} for the input {@link EhcacheEntityRegion} and {@link AccessType} * Create {@link EntityRegionAccessStrategy} for the input {@link EhcacheEntityRegion} and {@link AccessType}
* *
* @param entityRegion * @param entityRegion The entity region being wrapped
* @param accessType * @param accessType The type of access to allow to the region
* *
* @return the created {@link EntityRegionAccessStrategy} * @return the created {@link EntityRegionAccessStrategy}
*/ */
public EntityRegionAccessStrategy createEntityRegionAccessStrategy(EhcacheEntityRegion entityRegion, AccessType accessType); public EntityRegionAccessStrategy createEntityRegionAccessStrategy(
EhcacheEntityRegion entityRegion,
AccessType accessType);
/** /**
* Create {@link CollectionRegionAccessStrategy} for the input {@link org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion} and {@link AccessType} * Create {@link CollectionRegionAccessStrategy} for the input {@link EhcacheCollectionRegion} and {@link AccessType}
* *
* @param collectionRegion * @param collectionRegion The collection region being wrapped
* @param accessType * @param accessType The type of access to allow to the region
* *
* @return the created {@link CollectionRegionAccessStrategy} * @return the created {@link CollectionRegionAccessStrategy}
*/ */
public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(EhcacheCollectionRegion collectionRegion, public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(
EhcacheCollectionRegion collectionRegion,
AccessType accessType); AccessType accessType);
/** /**
* Create {@link NaturalIdRegionAccessStrategy} for the input {@link org.hibernate.cache.ehcache.internal.regions.EhcacheNaturalIdRegion} and {@link AccessType} * Create {@link NaturalIdRegionAccessStrategy} for the input {@link EhcacheNaturalIdRegion} and {@link AccessType}
* *
* @param naturalIdRegion * @param naturalIdRegion The natural-id region being wrapped
* @param accessType * @param accessType The type of access to allow to the region
* *
* @return the created {@link NaturalIdRegionAccessStrategy} * @return the created {@link NaturalIdRegionAccessStrategy}
*/ */
public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion naturalIdRegion, public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(
EhcacheNaturalIdRegion naturalIdRegion,
AccessType accessType); AccessType accessType);
} }

View File

@ -47,10 +47,10 @@ public class EhcacheAccessStrategyFactoryImpl implements EhcacheAccessStrategyFa
EhcacheAccessStrategyFactoryImpl.class.getName() EhcacheAccessStrategyFactoryImpl.class.getName()
); );
/** @Override
* {@inheritDoc} public EntityRegionAccessStrategy createEntityRegionAccessStrategy(
*/ EhcacheEntityRegion entityRegion,
public EntityRegionAccessStrategy createEntityRegionAccessStrategy(EhcacheEntityRegion entityRegion, AccessType accessType) { AccessType accessType) {
switch ( accessType ) { switch ( accessType ) {
case READ_ONLY: case READ_ONLY:
if ( entityRegion.getCacheDataDescription().isMutable() ) { if ( entityRegion.getCacheDataDescription().isMutable() ) {
@ -79,10 +79,9 @@ public class EhcacheAccessStrategyFactoryImpl implements EhcacheAccessStrategyFa
} }
/** @Override
* {@inheritDoc} public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(
*/ EhcacheCollectionRegion collectionRegion,
public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(EhcacheCollectionRegion collectionRegion,
AccessType accessType) { AccessType accessType) {
switch ( accessType ) { switch ( accessType ) {
case READ_ONLY: case READ_ONLY:
@ -114,7 +113,8 @@ public class EhcacheAccessStrategyFactoryImpl implements EhcacheAccessStrategyFa
} }
@Override @Override
public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion naturalIdRegion, public NaturalIdRegionAccessStrategy createNaturalIdRegionAccessStrategy(
EhcacheNaturalIdRegion naturalIdRegion,
AccessType accessType) { AccessType accessType) {
switch ( accessType ) { switch ( accessType ) {
case READ_ONLY: case READ_ONLY:

View File

@ -42,58 +42,58 @@ public class NonStrictReadWriteEhcacheCollectionRegionAccessStrategy
/** /**
* Create a non-strict read/write access strategy accessing the given collection region. * Create a non-strict read/write access strategy accessing the given collection region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public NonStrictReadWriteEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) { public NonStrictReadWriteEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public CollectionRegion getRegion() { public CollectionRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** @Override
* {@inheritDoc}
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
region.remove( key ); region().remove( key );
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
region.remove( key ); region().remove( key );
} }
} }

View File

@ -42,90 +42,97 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy
/** /**
* Create a non-strict read/write access strategy accessing the given collection region. * Create a non-strict read/write access strategy accessing the given collection region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public NonStrictReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) { public NonStrictReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public EntityRegion getRegion() { public EntityRegion getRegion() {
return region; return super.region();
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** @Override
* {@inheritDoc}
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
region.remove( key ); region().remove( key );
} }
/** /**
* {@inheritDoc}
* <p/>
* Returns <code>false</code> since this is an asynchronous cache access strategy. * Returns <code>false</code> since this is an asynchronous cache access strategy.
*/ */
@Override
public boolean insert(Object key, Object value, Object version) throws CacheException { public boolean insert(Object key, Object value, Object version) throws CacheException {
return false; return false;
} }
/** /**
* {@inheritDoc}
* <p/>
* Returns <code>false</code> since this is a non-strict read/write cache access strategy * Returns <code>false</code> since this is a non-strict read/write cache access strategy
*/ */
@Override
public boolean afterInsert(Object key, Object value, Object version) throws CacheException { public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
return false; return false;
} }
/** /**
* {@inheritDoc}
* <p/>
* Removes the entry since this is a non-strict read/write cache strategy. * Removes the entry since this is a non-strict read/write cache strategy.
*/ */
@Override
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException { throws CacheException {
remove( key ); remove( key );
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException { throws CacheException {
unlockItem( key, lock ); unlockItem( key, lock );
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
region.remove( key ); region().remove( key );
} }
} }

View File

@ -42,88 +42,95 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy
/** /**
* Create a non-strict read/write access strategy accessing the given NaturalId region. * Create a non-strict read/write access strategy accessing the given NaturalId region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) { public NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public NaturalIdRegion getRegion() { public NaturalIdRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** @Override
* {@inheritDoc}
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** /**
* {@inheritDoc}
* <p/>
* Since this is a non-strict read/write strategy item locking is not used. * Since this is a non-strict read/write strategy item locking is not used.
*/ */
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
region.remove( key ); region().remove( key );
} }
/** /**
* {@inheritDoc}
* <p/>
* Returns <code>false</code> since this is an asynchronous cache access strategy. * Returns <code>false</code> since this is an asynchronous cache access strategy.
*/ */
@Override
public boolean insert(Object key, Object value) throws CacheException { public boolean insert(Object key, Object value) throws CacheException {
return false; return false;
} }
/** /**
* {@inheritDoc}
* <p/>
* Returns <code>false</code> since this is a non-strict read/write cache access strategy * Returns <code>false</code> since this is a non-strict read/write cache access strategy
*/ */
@Override
public boolean afterInsert(Object key, Object value) throws CacheException { public boolean afterInsert(Object key, Object value) throws CacheException {
return false; return false;
} }
/** /**
* {@inheritDoc}
* <p/>
* Removes the entry since this is a non-strict read/write cache strategy. * Removes the entry since this is a non-strict read/write cache strategy.
*/ */
@Override
public boolean update(Object key, Object value) throws CacheException { public boolean update(Object key, Object value) throws CacheException {
remove( key ); remove( key );
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException {
unlockItem( key, lock ); unlockItem( key, lock );
return false; return false;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
region.remove( key ); region().remove( key );
} }
} }

View File

@ -42,46 +42,47 @@ public class ReadOnlyEhcacheCollectionRegionAccessStrategy
/** /**
* Create a read-only access strategy accessing the given collection region. * Create a read-only access strategy accessing the given collection region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public ReadOnlyEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) { public ReadOnlyEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public CollectionRegion getRegion() { public CollectionRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** @Override
* {@inheritDoc}
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
@Override
public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException {
return null; return null;
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this cache is read-only * A no-op since this cache is read-only
*/ */
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
} }
} }

View File

@ -30,10 +30,6 @@ import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cfg.Settings; import org.hibernate.cfg.Settings;
/**
* @author Alex Snaps
*/
/** /**
* Ehcache specific read-only entity region access strategy * Ehcache specific read-only entity region access strategy
* *
@ -45,6 +41,9 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc
/** /**
* Create a read-only access strategy accessing the given entity region. * Create a read-only access strategy accessing the given entity region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public ReadOnlyEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) { public ReadOnlyEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) {
super( region, settings ); super( region, settings );
@ -54,14 +53,14 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc
* {@inheritDoc} * {@inheritDoc}
*/ */
public EntityRegion getRegion() { public EntityRegion getRegion() {
return region; return region();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** /**
@ -69,11 +68,11 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc
*/ */
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
@ -100,7 +99,7 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc
* {@inheritDoc} * {@inheritDoc}
*/ */
public boolean afterInsert(Object key, Object value, Object version) throws CacheException { public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
region.put( key, value ); region().put( key, value );
return true; return true;
} }

View File

@ -42,79 +42,87 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy
/** /**
* Create a read-only access strategy accessing the given NaturalId region. * Create a read-only access strategy accessing the given NaturalId region.
*
* @param region THe wrapped region
* @param settings The Hibermate settings
*/ */
public ReadOnlyEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) { public ReadOnlyEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public NaturalIdRegion getRegion() { public NaturalIdRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
return region.get( key ); return region().get( key );
} }
/** @Override
* {@inheritDoc}
*/
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException { throws CacheException {
if ( minimalPutOverride && region.contains( key ) ) { if ( minimalPutOverride && region().contains( key ) ) {
return false; return false;
} }
else { else {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
} }
@Override
public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException {
return null; return null;
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this cache is read-only * A no-op since this cache is read-only
*/ */
@Override
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
region.remove( key ); region().remove( key );
}
/**
* This cache is asynchronous hence a no-op
*/
public boolean insert(Object key, Object value ) throws CacheException {
return false;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* <p/>
* This cache is asynchronous hence a no-op
*/ */
@Override
public boolean insert(Object key, Object value) throws CacheException {
return false;
}
@Override
public boolean afterInsert(Object key, Object value) throws CacheException { public boolean afterInsert(Object key, Object value) throws CacheException {
region.put( key, value ); region().put( key, value );
return true; return true;
} }
/** /**
* {@inheritDoc}
* <p/>
* Throws UnsupportedOperationException since this cache is read-only * Throws UnsupportedOperationException since this cache is read-only
* *
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
@Override
public boolean update(Object key, Object value) throws UnsupportedOperationException { public boolean update(Object key, Object value) throws UnsupportedOperationException {
throw new UnsupportedOperationException( "Can't write to a readonly object" ); throw new UnsupportedOperationException( "Can't write to a readonly object" );
} }
/** /**
* {@inheritDoc}
* <p/>
* Throws UnsupportedOperationException since this cache is read-only * Throws UnsupportedOperationException since this cache is read-only
* *
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
@Override
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws UnsupportedOperationException { public boolean afterUpdate(Object key, Object value, SoftLock lock) throws UnsupportedOperationException {
throw new UnsupportedOperationException( "Can't write to a readonly object" ); throw new UnsupportedOperationException( "Can't write to a readonly object" );
} }

View File

@ -40,15 +40,16 @@ public class ReadWriteEhcacheCollectionRegionAccessStrategy
/** /**
* Create a read/write access strategy accessing the given collection region. * Create a read/write access strategy accessing the given collection region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public ReadWriteEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) { public ReadWriteEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public CollectionRegion getRegion() { public CollectionRegion getRegion() {
return region; return region();
} }
} }

View File

@ -42,21 +42,25 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
/** /**
* Create a read/write access strategy accessing the given entity region. * Create a read/write access strategy accessing the given entity region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public ReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) { public ReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public EntityRegion getRegion() { public EntityRegion getRegion() {
return region; return region();
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this is an asynchronous cache access strategy. * A no-op since this is an asynchronous cache access strategy.
*/ */
@Override
public boolean insert(Object key, Object value, Object version) throws CacheException { public boolean insert(Object key, Object value, Object version) throws CacheException {
return false; return false;
} }
@ -66,12 +70,13 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
* <p/> * <p/>
* Inserts will only succeed if there is no existing value mapped to this key. * Inserts will only succeed if there is no existing value mapped to this key.
*/ */
@Override
public boolean afterInsert(Object key, Object value, Object version) throws CacheException { public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
if ( item == null ) { if ( item == null ) {
region.put( key, new Item( value, version, region.nextTimestamp() ) ); region().put( key, new Item( value, version, region().nextTimestamp() ) );
return true; return true;
} }
else { else {
@ -79,13 +84,16 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this is an asynchronous cache access strategy. * A no-op since this is an asynchronous cache access strategy.
*/ */
@Override
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) public boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException { throws CacheException {
return false; return false;
@ -98,12 +106,13 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
* duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during * duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during
* the course of this transaction. * the course of this transaction.
*/ */
@Override
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException { throws CacheException {
//what should we do with previousVersion here? //what should we do with previousVersion here?
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
if ( item != null && item.isUnlockable( lock ) ) { if ( item != null && item.isUnlockable( lock ) ) {
Lock lockItem = (Lock) item; Lock lockItem = (Lock) item;
@ -112,7 +121,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
return false; return false;
} }
else { else {
region.put( key, new Item( value, currentVersion, region.nextTimestamp() ) ); region().put( key, new Item( value, currentVersion, region().nextTimestamp() ) );
return true; return true;
} }
} }
@ -122,7 +131,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
} }

View File

@ -42,21 +42,25 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy
/** /**
* Create a read/write access strategy accessing the given NaturalId region. * Create a read/write access strategy accessing the given NaturalId region.
*
* @param region The wrapped region
* @param settings The Hibernate settings
*/ */
public ReadWriteEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) { public ReadWriteEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Settings settings) {
super( region, settings ); super( region, settings );
} }
/** @Override
* {@inheritDoc}
*/
public NaturalIdRegion getRegion() { public NaturalIdRegion getRegion() {
return region; return region();
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this is an asynchronous cache access strategy. * A no-op since this is an asynchronous cache access strategy.
*/ */
@Override
public boolean insert(Object key, Object value) throws CacheException { public boolean insert(Object key, Object value) throws CacheException {
return false; return false;
} }
@ -66,12 +70,13 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy
* <p/> * <p/>
* Inserts will only succeed if there is no existing value mapped to this key. * Inserts will only succeed if there is no existing value mapped to this key.
*/ */
@Override
public boolean afterInsert(Object key, Object value) throws CacheException { public boolean afterInsert(Object key, Object value) throws CacheException {
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
if ( item == null ) { if ( item == null ) {
region.put( key, new Item( value, null, region.nextTimestamp() ) ); region().put( key, new Item( value, null, region().nextTimestamp() ) );
return true; return true;
} }
else { else {
@ -79,15 +84,17 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
/** /**
* {@inheritDoc}
* <p/>
* A no-op since this is an asynchronous cache access strategy. * A no-op since this is an asynchronous cache access strategy.
*/ */
public boolean update(Object key, Object value ) @Override
throws CacheException { public boolean update(Object key, Object value) throws CacheException {
return false; return false;
} }
@ -98,20 +105,21 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy
* duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during * duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during
* the course of this transaction. * the course of this transaction.
*/ */
@Override
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException {
//what should we do with previousVersion here? //what should we do with previousVersion here?
region.writeLock( key ); region().writeLock( key );
try { try {
Lockable item = (Lockable) region.get( key ); final Lockable item = (Lockable) region().get( key );
if ( item != null && item.isUnlockable( lock ) ) { if ( item != null && item.isUnlockable( lock ) ) {
Lock lockItem = (Lock) item; final Lock lockItem = (Lock) item;
if ( lockItem.wasLockedConcurrently() ) { if ( lockItem.wasLockedConcurrently() ) {
decrementLock( key, lockItem ); decrementLock( key, lockItem );
return false; return false;
} }
else { else {
region.put( key, new Item( value, null, region.nextTimestamp() ) ); region().put( key, new Item( value, null, region().nextTimestamp() ) );
return true; return true;
} }
} }
@ -121,7 +129,7 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy
} }
} }
finally { finally {
region.writeUnlock( key ); region().writeUnlock( key );
} }
} }
} }

View File

@ -53,18 +53,18 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy
* @param ehcache the cache. * @param ehcache the cache.
* @param settings the Hibernate settings. * @param settings the Hibernate settings.
*/ */
public TransactionalEhcacheCollectionRegionAccessStrategy(EhcacheCollectionRegion region, Ehcache ehcache, Settings settings) { public TransactionalEhcacheCollectionRegionAccessStrategy(
EhcacheCollectionRegion region,
Ehcache ehcache,
Settings settings) {
super( region, settings ); super( region, settings );
this.ehcache = ehcache; this.ehcache = ehcache;
} }
@Override
/**
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
Element element = ehcache.get( key ); final Element element = ehcache.get( key );
return element == null ? null : element.getObjectValue(); return element == null ? null : element.getObjectValue();
} }
catch (net.sf.ehcache.CacheException e) { catch (net.sf.ehcache.CacheException e) {
@ -72,25 +72,23 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy
} }
} }
/** @Override
* {@inheritDoc}
*/
public CollectionRegion getRegion() { public CollectionRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** @Override
* {@inheritDoc} public boolean putFromLoad(
*/ Object key,
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object value,
Object version, boolean minimalPutOverride) throws CacheException { long txTimestamp,
Object version,
boolean minimalPutOverride) throws CacheException {
try { try {
if ( minimalPutOverride && ehcache.get( key ) != null ) { if ( minimalPutOverride && ehcache.get( key ) != null ) {
return false; return false;
@ -104,9 +102,6 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
@ -117,9 +112,7 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy
} }
} }
/** @Override
* {@inheritDoc}
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
// no-op // no-op
} }

View File

@ -52,31 +52,28 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca
* @param ehcache the cache. * @param ehcache the cache.
* @param settings the Hibernate settings. * @param settings the Hibernate settings.
*/ */
public TransactionalEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, Ehcache ehcache, Settings settings) { public TransactionalEhcacheEntityRegionAccessStrategy(
EhcacheEntityRegion region,
Ehcache ehcache,
Settings settings) {
super( region, settings ); super( region, settings );
this.ehcache = ehcache; this.ehcache = ehcache;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterInsert(Object key, Object value, Object version) { public boolean afterInsert(Object key, Object value, Object version) {
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
Element element = ehcache.get( key ); final Element element = ehcache.get( key );
return element == null ? null : element.getObjectValue(); return element == null ? null : element.getObjectValue();
} }
catch (net.sf.ehcache.CacheException e) { catch (net.sf.ehcache.CacheException e) {
@ -84,16 +81,12 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca
} }
} }
/** @Override
* {@inheritDoc}
*/
public EntityRegion getRegion() { public EntityRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public boolean insert(Object key, Object value, Object version) public boolean insert(Object key, Object value, Object version)
throws CacheException { throws CacheException {
//OptimisticCache? versioning? //OptimisticCache? versioning?
@ -106,18 +99,18 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca
} }
} }
/** @Override
* {@inheritDoc}
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** @Override
* {@inheritDoc} public boolean putFromLoad(
*/ Object key,
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object value,
Object version, boolean minimalPutOverride) throws CacheException { long txTimestamp,
Object version,
boolean minimalPutOverride) throws CacheException {
try { try {
if ( minimalPutOverride && ehcache.get( key ) != null ) { if ( minimalPutOverride && ehcache.get( key ) != null ) {
return false; return false;
@ -131,9 +124,6 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
@ -144,17 +134,16 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca
} }
} }
/** @Override
* {@inheritDoc}
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
// no-op // no-op
} }
/** @Override
* {@inheritDoc} public boolean update(
*/ Object key,
public boolean update(Object key, Object value, Object currentVersion, Object value,
Object currentVersion,
Object previousVersion) throws CacheException { Object previousVersion) throws CacheException {
try { try {
ehcache.put( new Element( key, value ) ); ehcache.put( new Element( key, value ) );

View File

@ -53,32 +53,28 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy
* @param ehcache the cache. * @param ehcache the cache.
* @param settings the Hibernate settings. * @param settings the Hibernate settings.
*/ */
public TransactionalEhcacheNaturalIdRegionAccessStrategy(EhcacheNaturalIdRegion region, Ehcache ehcache, Settings settings) { public TransactionalEhcacheNaturalIdRegionAccessStrategy(
EhcacheNaturalIdRegion region,
Ehcache ehcache,
Settings settings) {
super( region, settings ); super( region, settings );
this.ehcache = ehcache; this.ehcache = ehcache;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterInsert(Object key, Object value) { public boolean afterInsert(Object key, Object value) {
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public boolean afterUpdate(Object key, Object value, SoftLock lock) { public boolean afterUpdate(Object key, Object value, SoftLock lock) {
return false; return false;
} }
@Override
/**
* {@inheritDoc}
*/
public Object get(Object key, long txTimestamp) throws CacheException { public Object get(Object key, long txTimestamp) throws CacheException {
try { try {
Element element = ehcache.get( key ); final Element element = ehcache.get( key );
return element == null ? null : element.getObjectValue(); return element == null ? null : element.getObjectValue();
} }
catch (net.sf.ehcache.CacheException e) { catch (net.sf.ehcache.CacheException e) {
@ -86,16 +82,12 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy
} }
} }
/** @Override
* {@inheritDoc}
*/
public NaturalIdRegion getRegion() { public NaturalIdRegion getRegion() {
return region; return region();
} }
/** @Override
* {@inheritDoc}
*/
public boolean insert(Object key, Object value) throws CacheException { public boolean insert(Object key, Object value) throws CacheException {
//OptimisticCache? versioning? //OptimisticCache? versioning?
try { try {
@ -107,18 +99,18 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy
} }
} }
/** @Override
* {@inheritDoc}
*/
public SoftLock lockItem(Object key, Object version) throws CacheException { public SoftLock lockItem(Object key, Object version) throws CacheException {
return null; return null;
} }
/** @Override
* {@inheritDoc} public boolean putFromLoad(
*/ Object key,
public boolean putFromLoad(Object key, Object value, long txTimestamp, Object value,
Object version, boolean minimalPutOverride) throws CacheException { long txTimestamp,
Object version,
boolean minimalPutOverride) throws CacheException {
try { try {
if ( minimalPutOverride && ehcache.get( key ) != null ) { if ( minimalPutOverride && ehcache.get( key ) != null ) {
return false; return false;
@ -132,9 +124,6 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void remove(Object key) throws CacheException { public void remove(Object key) throws CacheException {
try { try {
@ -145,16 +134,12 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy
} }
} }
/** @Override
* {@inheritDoc}
*/
public void unlockItem(Object key, SoftLock lock) throws CacheException { public void unlockItem(Object key, SoftLock lock) throws CacheException {
// no-op // no-op
} }
/** @Override
* {@inheritDoc}
*/
public boolean update(Object key, Object value) throws CacheException { public boolean update(Object key, Object value) throws CacheException {
try { try {
ehcache.put( new Element( key, value ) ); ehcache.put( new Element( key, value ) );

View File

@ -0,0 +1,4 @@
/**
* Defines {@link org.hibernate.cache.spi.access.RegionAccessStrategy} support for the Ehcache integration
*/
package org.hibernate.cache.ehcache.internal.strategy;

View File

@ -0,0 +1,129 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache.ehcache.internal.util;
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;
/**
* Copy of Ehcache utils into Hibernate code base
*
* @author Chris Dennis
* @author Abhishek Sanoujam
* @author Alex Snaps
*/
public final class HibernateEhcacheUtils {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class,
HibernateEhcacheUtils.class.getName()
);
private HibernateEhcacheUtils() {
}
/**
* Create a cache manager configuration from the supplied url, correcting it for Hibernate compatibility.
* <p/>
* Currently "correcting" for Hibernate compatibility means simply switching any identity based value modes
* to serialization.
*
* @param url The url to load the config from
*
* @return The Ehcache Configuration object
*/
public static Configuration loadAndCorrectConfiguration(URL url) {
final Configuration config = ConfigurationFactory.parseConfiguration( url );
if ( config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
if ( ValueMode.IDENTITY
.equals( config.getDefaultCacheConfiguration().getTerracottaConfiguration().getValueMode() ) ) {
LOG.incompatibleCacheValueMode();
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.setValueMode( ValueMode.SERIALIZATION.name() );
}
setupHibernateTimeoutBehavior(
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.getNonstopConfiguration()
);
}
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() );
}
}
return config;
}
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;
}
}
}
}
}

View File

@ -1,116 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cache.ehcache.internal.util;
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;
/**
* @author Chris Dennis
* @author Abhishek Sanoujam
* @author Alex Snaps
*/
public final class HibernateUtil {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class,
HibernateUtil.class.getName()
);
private HibernateUtil() {
}
/**
* Create a cache manager configuration from the supplied url, correcting it for Hibernate compatibility.
* <p/>
* Currently correcting for Hibernate compatibility means simply switching any identity based value modes to serialization.
*/
public static Configuration loadAndCorrectConfiguration(URL url) {
Configuration config = ConfigurationFactory.parseConfiguration( url );
if ( config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
if ( ValueMode.IDENTITY
.equals( config.getDefaultCacheConfiguration().getTerracottaConfiguration().getValueMode() ) ) {
LOG.incompatibleCacheValueMode();
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.setValueMode( ValueMode.SERIALIZATION.name() );
}
setupHibernateTimeoutBehavior(
config.getDefaultCacheConfiguration()
.getTerracottaConfiguration()
.getNonstopConfiguration()
);
}
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() );
}
}
return config;
}
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.
*/
public static void validateEhcache(Ehcache cache) throws CacheException {
CacheConfiguration cacheConfig = cache.getCacheConfiguration();
if ( cacheConfig.isTerracottaClustered() ) {
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;
}
}
}
}

View File

@ -0,0 +1,4 @@
/**
* Defines utilities used by the Ehcache integration
*/
package org.hibernate.cache.ehcache.internal.util;

View File

@ -24,9 +24,6 @@
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import javax.management.ListenerNotFoundException; import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo; import javax.management.MBeanNotificationInfo;
import javax.management.NotCompliantMBeanException; import javax.management.NotCompliantMBeanException;
@ -36,64 +33,61 @@ import javax.management.NotificationEmitter;
import javax.management.NotificationFilter; import javax.management.NotificationFilter;
import javax.management.NotificationListener; import javax.management.NotificationListener;
import javax.management.StandardMBean; import javax.management.StandardMBean;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
/** /**
* Base MBean impl
*
* @author gkeim * @author gkeim
*/ */
public abstract class BaseEmitterBean extends StandardMBean implements NotificationEmitter { public abstract class AbstractEmitterBean extends StandardMBean implements NotificationEmitter {
/** private final Emitter emitter = new Emitter();
* emitter private final AtomicLong sequenceNumber = new AtomicLong();
*/
protected final Emitter emitter = new Emitter();
/**
* sequenceNumber
*/
protected final AtomicLong sequenceNumber = new AtomicLong();
private final List<NotificationListener> notificationListeners = new CopyOnWriteArrayList<NotificationListener>(); private final List<NotificationListener> notificationListeners = new CopyOnWriteArrayList<NotificationListener>();
/** /**
* BaseEmitterBean * Constructs a AbstractEmitterBean
* *
* @param <T> * @param mbeanInterface The MBean contract
* @param mbeanInterface * @param <T> Not used as far as I can see
* *
* @throws javax.management.NotCompliantMBeanException * @throws javax.management.NotCompliantMBeanException thrown from JMX super ctor
*/ */
protected <T> BaseEmitterBean(Class<T> mbeanInterface) throws NotCompliantMBeanException { protected <T> AbstractEmitterBean(Class<T> mbeanInterface) throws NotCompliantMBeanException {
super( mbeanInterface ); super( mbeanInterface );
} }
/** /**
* sendNotification * Sends notification of an event
* *
* @param eventType * @param eventType The type of event
*/ */
public void sendNotification(String eventType) { public void sendNotification(String eventType) {
sendNotification( eventType, null, null ); sendNotification( eventType, null, null );
} }
/** /**
* sendNotification * Sends notification of an event
* *
* @param eventType * @param eventType The type of event
* @param data * @param data The event data
*/ */
public void sendNotification(String eventType, Object data) { public void sendNotification(String eventType, Object data) {
sendNotification( eventType, data, null ); sendNotification( eventType, data, null );
} }
/** /**
* sendNotification * Sends notification of an event
* *
* @param eventType * @param eventType The type of event
* @param data * @param data The event data
* @param msg * @param msg A message
*/ */
public void sendNotification(String eventType, Object data, String msg) { public void sendNotification(String eventType, Object data, String msg) {
Notification notif = new Notification( final Notification notification = new Notification(
eventType, eventType,
this, this,
sequenceNumber.incrementAndGet(), sequenceNumber.incrementAndGet(),
@ -101,9 +95,9 @@ public abstract class BaseEmitterBean extends StandardMBean implements Notificat
msg msg
); );
if ( data != null ) { if ( data != null ) {
notif.setUserData( data ); notification.setUserData( data );
} }
emitter.sendNotification( notif ); emitter.sendNotification( notification );
} }
/** /**
@ -119,31 +113,19 @@ public abstract class BaseEmitterBean extends StandardMBean implements Notificat
*/ */
protected abstract void doDispose(); protected abstract void doDispose();
/**
* @author gkeim
*/
private class Emitter extends NotificationBroadcasterSupport { private class Emitter extends NotificationBroadcasterSupport {
/**
* @see javax.management.NotificationBroadcasterSupport#getNotificationInfo()
*/
@Override @Override
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {
return BaseEmitterBean.this.getNotificationInfo(); return AbstractEmitterBean.this.getNotificationInfo();
} }
} }
/** @Override
* @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
* javax.management.NotificationFilter, java.lang.Object)
*/
public void addNotificationListener(NotificationListener notif, NotificationFilter filter, Object callBack) { public void addNotificationListener(NotificationListener notif, NotificationFilter filter, Object callBack) {
emitter.addNotificationListener( notif, filter, callBack ); emitter.addNotificationListener( notif, filter, callBack );
notificationListeners.add( notif ); notificationListeners.add( notif );
} }
/**
* remove all added notification listeners
*/
private void removeAllNotificationListeners() { private void removeAllNotificationListeners() {
for ( NotificationListener listener : notificationListeners ) { for ( NotificationListener listener : notificationListeners ) {
try { try {
@ -156,24 +138,17 @@ public abstract class BaseEmitterBean extends StandardMBean implements Notificat
notificationListeners.clear(); notificationListeners.clear();
} }
/** @Override
* @see javax.management.NotificationBroadcaster#getNotificationInfo()
*/
public abstract MBeanNotificationInfo[] getNotificationInfo(); public abstract MBeanNotificationInfo[] getNotificationInfo();
/** @Override
* @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
*/
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
emitter.removeNotificationListener( listener ); emitter.removeNotificationListener( listener );
notificationListeners.remove( listener ); notificationListeners.remove( listener );
} }
/** @Override
* @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener,
* javax.management.NotificationFilter, java.lang.Object)
*/
public void removeNotificationListener(NotificationListener notif, NotificationFilter filter, Object callBack) public void removeNotificationListener(NotificationListener notif, NotificationFilter filter, Object callBack)
throws ListenerNotFoundException { throws ListenerNotFoundException {
emitter.removeNotificationListener( notif, filter, callBack ); emitter.removeNotificationListener( notif, filter, callBack );

View File

@ -36,17 +36,17 @@ public class BeanUtils {
/** /**
* Return the named getter method on the bean or null if not found. * Return the named getter method on the bean or null if not found.
* *
* @param bean * @param bean The bean
* @param propertyName * @param propertyName The property to get the getter for
* *
* @return the named getter method * @return the named getter method
*/ */
private static Method getMethod(Object bean, String propertyName) { private static Method getMethod(Object bean, String propertyName) {
StringBuilder sb = new StringBuilder( "get" ).append( Character.toUpperCase( propertyName.charAt( 0 ) ) ); final StringBuilder sb = new StringBuilder( "get" ).append( Character.toUpperCase( propertyName.charAt( 0 ) ) );
if ( propertyName.length() > 1 ) { if ( propertyName.length() > 1 ) {
sb.append( propertyName.substring( 1 ) ); sb.append( propertyName.substring( 1 ) );
} }
String getterName = sb.toString(); final String getterName = sb.toString();
for ( Method m : bean.getClass().getMethods() ) { for ( Method m : bean.getClass().getMethods() ) {
if ( getterName.equals( m.getName() ) && m.getParameterTypes().length == 0 ) { if ( getterName.equals( m.getName() ) && m.getParameterTypes().length == 0 ) {
return m; return m;
@ -55,14 +55,6 @@ public class BeanUtils {
return null; return null;
} }
/**
* Return the named field on the bean or null if not found.
*
* @param bean
* @param propertyName
*
* @return the named field
*/
private static Field getField(Object bean, String propertyName) { private static Field getField(Object bean, String propertyName) {
for ( Field f : bean.getClass().getDeclaredFields() ) { for ( Field f : bean.getClass().getDeclaredFields() ) {
if ( propertyName.equals( f.getName() ) ) { if ( propertyName.equals( f.getName() ) ) {
@ -87,8 +79,8 @@ public class BeanUtils {
/** /**
* Retrieve a named bean property value. * Retrieve a named bean property value.
* *
* @param bean bean * @param bean The bean instance
* @param propertyName * @param propertyName The name of the property whose value to extract
* *
* @return the property value * @return the property value
*/ */
@ -96,7 +88,7 @@ public class BeanUtils {
validateArgs( bean, propertyName ); validateArgs( bean, propertyName );
// try getters first // try getters first
Method getter = getMethod( bean, propertyName ); final Method getter = getMethod( bean, propertyName );
if ( getter != null ) { if ( getter != null ) {
try { try {
return getter.invoke( bean ); return getter.invoke( bean );
@ -107,7 +99,7 @@ public class BeanUtils {
} }
// then try fields // then try fields
Field field = getField( bean, propertyName ); final Field field = getField( bean, propertyName );
if ( field != null ) { if ( field != null ) {
try { try {
field.setAccessible( true ); field.setAccessible( true );
@ -124,16 +116,16 @@ public class BeanUtils {
/** /**
* Retrieve a Long bean property value. * Retrieve a Long bean property value.
* *
* @param bean bean * @param bean The bean instance
* @param propertyName * @param propertyName The name of the property whose value to extract
* *
* @return long value * @return long value
* *
* @throws NoSuchFieldException * @throws NoSuchFieldException If the value is null (wow)
*/ */
public static long getLongBeanProperty(final Object bean, final String propertyName) throws NoSuchFieldException { public static long getLongBeanProperty(final Object bean, final String propertyName) throws NoSuchFieldException {
validateArgs( bean, propertyName ); validateArgs( bean, propertyName );
Object o = getBeanProperty( bean, propertyName ); final Object o = getBeanProperty( bean, propertyName );
if ( o == null ) { if ( o == null ) {
throw new NoSuchFieldException( propertyName ); throw new NoSuchFieldException( propertyName );
} }
@ -142,4 +134,7 @@ public class BeanUtils {
} }
return ((Number) o).longValue(); return ((Number) o).longValue();
} }
private BeanUtils() {
}
} }

View File

@ -23,10 +23,6 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
@ -36,10 +32,15 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType; import javax.management.openmbean.TabularType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics;
/** /**
* Bean for exposing region stats
*
* @author gkeim * @author gkeim
*/ */
public class CacheRegionStats implements Serializable { public class CacheRegionStats implements Serializable {
@ -123,7 +124,9 @@ public class CacheRegionStats implements Serializable {
protected long elementCountTotal; protected long elementCountTotal;
/** /**
* @param region * Construct a CacheRegionStats
*
* @param region The region name
*/ */
public CacheRegionStats(String region) { public CacheRegionStats(String region) {
this.region = region; this.region = region;
@ -131,8 +134,10 @@ public class CacheRegionStats implements Serializable {
} }
/** /**
* @param region * Construct a CacheRegionStats
* @param src *
* @param region The region name
* @param src The SecondLevelCacheStatistics reference
*/ */
public CacheRegionStats(String region, SecondLevelCacheStatistics src) { public CacheRegionStats(String region, SecondLevelCacheStatistics src) {
this( region ); this( region );
@ -153,8 +158,11 @@ public class CacheRegionStats implements Serializable {
} }
/** /**
* @param cData * Construct a CacheRegionStats
*
* @param cData No idea
*/ */
@SuppressWarnings("UnusedAssignment")
public CacheRegionStats(final CompositeData cData) { public CacheRegionStats(final CompositeData cData) {
int i = 0; int i = 0;
region = (String) cData.get( ITEM_NAMES[i++] ); region = (String) cData.get( ITEM_NAMES[i++] );
@ -168,30 +176,15 @@ public class CacheRegionStats implements Serializable {
elementCountTotal = (Long) cData.get( ITEM_NAMES[i++] ); elementCountTotal = (Long) cData.get( ITEM_NAMES[i++] );
} }
private static int safeParseInt(String s) {
try {
return Integer.parseInt( s );
}
catch ( Exception e ) {
return -1;
}
}
/**
* @return hit ratio
*/
protected double determineHitRatio() { protected double determineHitRatio() {
final long readCount = getHitCount() + getMissCount();
double result = 0; double result = 0;
long readCount = getHitCount() + getMissCount();
if ( readCount > 0 ) { if ( readCount > 0 ) {
result = getHitCount() / ((double) readCount); result = getHitCount() / ((double) readCount);
} }
return result; return result;
} }
/**
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
return "region=" + getRegion() + "shortName=" + getShortName() + ", hitCount=" + getHitCount() + ", missCount=" return "region=" + getRegion() + "shortName=" + getShortName() + ", hitCount=" + getHitCount() + ", missCount="
@ -200,70 +193,45 @@ public class CacheRegionStats implements Serializable {
+ getElementCountTotal(); + getElementCountTotal();
} }
/**
* @return region name
*/
public String getRegion() { public String getRegion() {
return region; return region;
} }
/**
* @return short name
*/
public String getShortName() { public String getShortName() {
return shortName; return shortName;
} }
/**
* @return hit count
*/
public long getHitCount() { public long getHitCount() {
return hitCount; return hitCount;
} }
/**
* @return miss count
*/
public long getMissCount() { public long getMissCount() {
return missCount; return missCount;
} }
/**
* @return put count
*/
public long getPutCount() { public long getPutCount() {
return putCount; return putCount;
} }
/**
* @return hit ratio
*/
public double getHitRatio() { public double getHitRatio() {
return hitRatio; return hitRatio;
} }
/**
* @return in-memory element count
*/
public long getElementCountInMemory() { public long getElementCountInMemory() {
return elementCountInMemory; return elementCountInMemory;
} }
/**
* @return on-disk element count
*/
public long getElementCountOnDisk() { public long getElementCountOnDisk() {
return elementCountOnDisk; return elementCountOnDisk;
} }
/**
* @return total element count
*/
public long getElementCountTotal() { public long getElementCountTotal() {
return elementCountTotal; return elementCountTotal;
} }
/** /**
* Convert our state into a JMX CompositeData
*
* @return composite data * @return composite data
*/ */
public CompositeData toCompositeData() { public CompositeData toCompositeData() {
@ -282,6 +250,8 @@ public class CacheRegionStats implements Serializable {
} }
/** /**
* Convert our state into a JMX TabularData
*
* @return tabular data * @return tabular data
*/ */
public static TabularData newTabularDataInstance() { public static TabularData newTabularDataInstance() {
@ -289,14 +259,17 @@ public class CacheRegionStats implements Serializable {
} }
/** /**
* @param tabularData * Re-build the CacheRegionStats from JMX tabular data
*
* @param tabularData The JMX tabular data
* *
* @return array of region statistics * @return array of region statistics
*/ */
@SuppressWarnings("UnusedDeclaration")
public static CacheRegionStats[] fromTabularData(final TabularData tabularData) { public static CacheRegionStats[] fromTabularData(final TabularData tabularData) {
final List<CacheRegionStats> countList = new ArrayList( tabularData.size() ); final List<CacheRegionStats> countList = new ArrayList<CacheRegionStats>( tabularData.size() );
for ( final Iterator pos = tabularData.values().iterator(); pos.hasNext(); ) { for ( Object o : tabularData.values() ) {
countList.add( new CacheRegionStats( (CompositeData) pos.next() ) ); countList.add( new CacheRegionStats( (CompositeData) o ) );
} }
return countList.toArray( new CacheRegionStats[countList.size()] ); return countList.toArray( new CacheRegionStats[countList.size()] );
} }

View File

@ -23,13 +23,14 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.awt.*; import java.awt.Color;
/** /**
* CacheRegionUtils * CacheRegionUtils
* *
* @author gkeim * @author gkeim
*/ */
@SuppressWarnings("UnusedDeclaration")
public abstract class CacheRegionUtils { public abstract class CacheRegionUtils {
/** /**
* HIT_COLOR * HIT_COLOR
@ -49,51 +50,53 @@ public abstract class CacheRegionUtils {
/** /**
* HIT_FILL_COLOR * HIT_FILL_COLOR
*/ */
public final static Color HIT_FILL_COLOR = CacheRegionUtils.HIT_COLOR.brighter().brighter().brighter(); public static final Color HIT_FILL_COLOR = CacheRegionUtils.HIT_COLOR.brighter().brighter().brighter();
/** /**
* MISS_FILL_COLOR * MISS_FILL_COLOR
*/ */
public final static Color MISS_FILL_COLOR = CacheRegionUtils.MISS_COLOR.brighter().brighter().brighter(); public static final Color MISS_FILL_COLOR = CacheRegionUtils.MISS_COLOR.brighter().brighter().brighter();
/** /**
* PUT_FILL_COLOR * PUT_FILL_COLOR
*/ */
public final static Color PUT_FILL_COLOR = CacheRegionUtils.PUT_COLOR.brighter().brighter().brighter(); public static final Color PUT_FILL_COLOR = CacheRegionUtils.PUT_COLOR.brighter().brighter().brighter();
/** /**
* HIT_DRAW_COLOR * HIT_DRAW_COLOR
*/ */
public final static Color HIT_DRAW_COLOR = CacheRegionUtils.HIT_COLOR.darker(); public static final Color HIT_DRAW_COLOR = CacheRegionUtils.HIT_COLOR.darker();
/** /**
* MISS_DRAW_COLOR * MISS_DRAW_COLOR
*/ */
public final static Color MISS_DRAW_COLOR = CacheRegionUtils.MISS_COLOR.darker(); public static final Color MISS_DRAW_COLOR = CacheRegionUtils.MISS_COLOR.darker();
/** /**
* PUT_DRAW_COLOR * PUT_DRAW_COLOR
*/ */
public final static Color PUT_DRAW_COLOR = CacheRegionUtils.PUT_COLOR.darker(); public static final Color PUT_DRAW_COLOR = CacheRegionUtils.PUT_COLOR.darker();
/** /**
* determineShortName * Determine a short name from the full name
* *
* @param fullName * @param fullName The full name
*
* @return The short name
*/ */
public static String determineShortName(String fullName) { public static String determineShortName(String fullName) {
String result = fullName; String result = fullName;
if ( fullName != null ) { if ( fullName != null ) {
String[] comps = fullName.split( "\\." ); final String[] comps = fullName.split( "\\." );
if ( comps.length == 1 ) { if ( comps.length == 1 ) {
return fullName; return fullName;
} }
boolean truncate = true; boolean truncate = true;
for ( int i = 0; i < comps.length; i++ ) { for ( int i = 0; i < comps.length; i++ ) {
String comp = comps[i]; String comp = comps[i];
char c = comp.charAt( 0 ); final char c = comp.charAt( 0 );
if ( truncate && Character.isUpperCase( c ) ) { if ( truncate && Character.isUpperCase( c ) ) {
truncate = false; truncate = false;
} }
@ -108,16 +111,18 @@ public abstract class CacheRegionUtils {
} }
/** /**
* join * Same as Hibernate internal {@link org.hibernate.internal.util.StringHelper#join} methods
* *
* @param elements * @param elements The things to join
* @param c * @param c The separator between elements
*
* @return The joined string
*/ */
private static String join(String[] elements, char c) { private static String join(String[] elements, char c) {
if ( elements == null ) { if ( elements == null ) {
return null; return null;
} }
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for ( String s : elements ) { for ( String s : elements ) {
sb.append( s ).append( c ); sb.append( s ).append( c );
} }

View File

@ -23,10 +23,6 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
@ -36,6 +32,9 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType; import javax.management.openmbean.TabularType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.stat.CollectionStatistics; import org.hibernate.stat.CollectionStatistics;
@ -115,19 +114,23 @@ public class CollectionStats implements Serializable {
/** /**
* @param roleName * Constructs a CollectionsStats
*
* @param role The collection role
*/ */
public CollectionStats(String roleName) { public CollectionStats(String role) {
this.roleName = roleName; this.roleName = role;
this.shortName = CacheRegionUtils.determineShortName( roleName ); this.shortName = CacheRegionUtils.determineShortName( role );
} }
/** /**
* @param name * Constructs a CollectionsStats
* @param src *
* @param role The collection role
* @param src The CollectionStatistics instance
*/ */
public CollectionStats(String name, CollectionStatistics src) { public CollectionStats(String role, CollectionStatistics src) {
this( name ); this( role );
try { try {
this.loadCount = BeanUtils.getLongBeanProperty( src, "loadCount" ); this.loadCount = BeanUtils.getLongBeanProperty( src, "loadCount" );
@ -143,8 +146,11 @@ public class CollectionStats implements Serializable {
} }
/** /**
* @param cData * Constructs a CollectionsStats from a JMX CompositeData
*
* @param cData The JMX CompositeData
*/ */
@SuppressWarnings("UnusedAssignment")
public CollectionStats(final CompositeData cData) { public CollectionStats(final CompositeData cData) {
int i = 0; int i = 0;
roleName = (String) cData.get( ITEM_NAMES[i++] ); roleName = (String) cData.get( ITEM_NAMES[i++] );
@ -156,17 +162,10 @@ public class CollectionStats implements Serializable {
recreateCount = (Long) cData.get( ITEM_NAMES[i++] ); recreateCount = (Long) cData.get( ITEM_NAMES[i++] );
} }
private static int safeParseInt(String s) {
try {
return Integer.parseInt( s );
}
catch ( Exception e ) {
return -1;
}
}
/** /**
* @param stats * Update the internal stats
*
* @param stats The incoming stats
*/ */
public void add(CollectionStats stats) { public void add(CollectionStats stats) {
loadCount += stats.getLoadCount(); loadCount += stats.getLoadCount();
@ -176,9 +175,6 @@ public class CollectionStats implements Serializable {
recreateCount += stats.getRecreateCount(); recreateCount += stats.getRecreateCount();
} }
/**
* toString
*/
@Override @Override
public String toString() { public String toString() {
return "roleName=" + roleName + "shortName=" + shortName + ", loadCount=" + loadCount + ", fetchCount=" return "roleName=" + roleName + "shortName=" + shortName + ", loadCount=" + loadCount + ", fetchCount="
@ -186,65 +182,47 @@ public class CollectionStats implements Serializable {
+ recreateCount; + recreateCount;
} }
/** @SuppressWarnings("UnusedDeclaration")
* getRoleName
*/
public String getRoleName() { public String getRoleName() {
return roleName; return roleName;
} }
/** @SuppressWarnings("UnusedDeclaration")
* getShortName
*/
public String getShortName() { public String getShortName() {
return shortName; return shortName;
} }
/**
* getLoadCount
*/
public long getLoadCount() { public long getLoadCount() {
return loadCount; return loadCount;
} }
/**
* getFetchCount
*/
public long getFetchCount() { public long getFetchCount() {
return fetchCount; return fetchCount;
} }
/**
* getUpdateCount
*/
public long getUpdateCount() { public long getUpdateCount() {
return updateCount; return updateCount;
} }
/**
* getRemoveCount
*/
public long getRemoveCount() { public long getRemoveCount() {
return removeCount; return removeCount;
} }
/**
* getRecreateCount
*/
public long getRecreateCount() { public long getRecreateCount() {
return recreateCount; return recreateCount;
} }
/** /**
* toCompositeData * Builds a JMX CompositeData view of our state
*
* @return The JMX CompositeData
*/ */
public CompositeData toCompositeData() { public CompositeData toCompositeData() {
try { try {
return new CompositeDataSupport( return new CompositeDataSupport(
COMPOSITE_TYPE, ITEM_NAMES, new Object[] { COMPOSITE_TYPE,
roleName, shortName, loadCount, ITEM_NAMES,
fetchCount, updateCount, removeCount, recreateCount, new Object[] { roleName, shortName, loadCount, fetchCount, updateCount, removeCount, recreateCount }
}
); );
} }
catch (OpenDataException e) { catch (OpenDataException e) {
@ -253,19 +231,26 @@ public class CollectionStats implements Serializable {
} }
/** /**
* newTabularDataInstance * Builds a JMX TabularData
*
* @return JMX TabularData
*/ */
public static TabularData newTabularDataInstance() { public static TabularData newTabularDataInstance() {
return new TabularDataSupport( TABULAR_TYPE ); return new TabularDataSupport( TABULAR_TYPE );
} }
/** /**
* fromTabularData * Re-builds CollectionStats from JMX TabularData
*
* @param tabularData The JMX TabularData
*
* @return The CollectionsStats
*/ */
@SuppressWarnings("UnusedDeclaration")
public static CollectionStats[] fromTabularData(final TabularData tabularData) { public static CollectionStats[] fromTabularData(final TabularData tabularData) {
final List<CollectionStats> countList = new ArrayList( tabularData.size() ); final List<CollectionStats> countList = new ArrayList<CollectionStats>( tabularData.size() );
for ( final Iterator pos = tabularData.values().iterator(); pos.hasNext(); ) { for ( Object o : tabularData.values() ) {
countList.add( new CollectionStats( (CompositeData) pos.next() ) ); countList.add( new CollectionStats( (CompositeData) o ) );
} }
return countList.toArray( new CollectionStats[countList.size()] ); return countList.toArray( new CollectionStats[countList.size()] );
} }

View File

@ -23,12 +23,12 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.management.MBeanNotificationInfo; import javax.management.MBeanNotificationInfo;
import javax.management.NotCompliantMBeanException; import javax.management.NotCompliantMBeanException;
import javax.management.Notification; import javax.management.Notification;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.hibernate.management.api.EhcacheHibernateMBean; import net.sf.ehcache.hibernate.management.api.EhcacheHibernateMBean;
@ -44,7 +44,7 @@ import org.hibernate.SessionFactory;
* *
* @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a> * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
*/ */
public class EhcacheHibernate extends BaseEmitterBean implements EhcacheHibernateMBean { public class EhcacheHibernate extends AbstractEmitterBean implements EhcacheHibernateMBean {
private static final MBeanNotificationInfo NOTIFICATION_INFO; private static final MBeanNotificationInfo NOTIFICATION_INFO;
private final AtomicBoolean statsEnabled = new AtomicBoolean( true ); private final AtomicBoolean statsEnabled = new AtomicBoolean( true );
@ -588,7 +588,7 @@ public class EhcacheHibernate extends BaseEmitterBean implements EhcacheHibernat
} }
/** /**
* @see BaseEmitterBean#getNotificationInfo() * @see AbstractEmitterBean#getNotificationInfo()
*/ */
@Override @Override
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {

View File

@ -23,16 +23,17 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.lang.management.ManagementFactory;
import java.util.Properties;
import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectName; import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.Properties;
import net.sf.ehcache.CacheException; import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Status; import net.sf.ehcache.Status;
import net.sf.ehcache.event.CacheManagerEventListener; import net.sf.ehcache.event.CacheManagerEventListener;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;

View File

@ -23,12 +23,12 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.management.MBeanNotificationInfo; import javax.management.MBeanNotificationInfo;
import javax.management.NotCompliantMBeanException; import javax.management.NotCompliantMBeanException;
import javax.management.Notification; import javax.management.Notification;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import net.sf.ehcache.Cache; import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
@ -42,7 +42,7 @@ import net.sf.ehcache.management.sampled.SampledCacheManager;
* *
* @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a> * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
*/ */
public class EhcacheStatsImpl extends BaseEmitterBean implements EhcacheStats { public class EhcacheStatsImpl extends AbstractEmitterBean implements EhcacheStats {
private static final long MILLIS_PER_SECOND = 1000; private static final long MILLIS_PER_SECOND = 1000;
private static final MBeanNotificationInfo NOTIFICATION_INFO; private static final MBeanNotificationInfo NOTIFICATION_INFO;
@ -680,7 +680,7 @@ public class EhcacheStatsImpl extends BaseEmitterBean implements EhcacheStats {
} }
/** /**
* @see BaseEmitterBean#getNotificationInfo() * @see AbstractEmitterBean#getNotificationInfo()
*/ */
@Override @Override
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {

View File

@ -23,10 +23,6 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
@ -36,6 +32,10 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType; import javax.management.openmbean.TabularType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.stat.EntityStatistics; import org.hibernate.stat.EntityStatistics;

View File

@ -23,13 +23,13 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.util.ArrayList;
import java.util.List;
import javax.management.MBeanNotificationInfo; import javax.management.MBeanNotificationInfo;
import javax.management.NotCompliantMBeanException; import javax.management.NotCompliantMBeanException;
import javax.management.Notification; import javax.management.Notification;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import java.util.ArrayList;
import java.util.List;
import net.sf.ehcache.hibernate.management.api.HibernateStats; import net.sf.ehcache.hibernate.management.api.HibernateStats;
@ -43,7 +43,7 @@ import org.hibernate.stat.Statistics;
* *
* @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a> * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
*/ */
public class HibernateStatsImpl extends BaseEmitterBean implements HibernateStats { public class HibernateStatsImpl extends AbstractEmitterBean implements HibernateStats {
private static final double MILLIS_PER_SECOND = 1000; private static final double MILLIS_PER_SECOND = 1000;
private static final MBeanNotificationInfo NOTIFICATION_INFO; private static final MBeanNotificationInfo NOTIFICATION_INFO;
@ -321,7 +321,7 @@ public class HibernateStatsImpl extends BaseEmitterBean implements HibernateStat
} }
/** /**
* @see BaseEmitterBean#getNotificationInfo() * @see AbstractEmitterBean#getNotificationInfo()
*/ */
@Override @Override
public MBeanNotificationInfo[] getNotificationInfo() { public MBeanNotificationInfo[] getNotificationInfo() {

View File

@ -31,6 +31,7 @@ import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
@ -94,7 +95,8 @@ public class ProviderMBeanRegistrationHelper {
private final CacheManager manager; private final CacheManager manager;
private final Properties properties; private final Properties properties;
public RegisterMBeansTask(EhcacheHibernateMBeanRegistrationImpl ehcacheHibernateMBeanRegistration, public RegisterMBeansTask(
EhcacheHibernateMBeanRegistrationImpl ehcacheHibernateMBeanRegistration,
CacheManager manager, Properties properties) { CacheManager manager, Properties properties) {
this.ehcacheHibernateMBeanRegistration = ehcacheHibernateMBeanRegistration; this.ehcacheHibernateMBeanRegistration = ehcacheHibernateMBeanRegistration;
this.manager = manager; this.manager = manager;

View File

@ -23,10 +23,6 @@
*/ */
package org.hibernate.cache.ehcache.management.impl; package org.hibernate.cache.ehcache.management.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType; import javax.management.openmbean.CompositeType;
@ -36,6 +32,10 @@ import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType; import javax.management.openmbean.TabularType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.stat.QueryStatistics; import org.hibernate.stat.QueryStatistics;

View File

@ -0,0 +1,4 @@
/**
* Defines JMX support for the Ehcache integration
*/
package org.hibernate.cache.ehcache.management.impl;

View File

@ -0,0 +1,4 @@
/**
* Defines the integration with Ehcache as a second-level cache service.
*/
package org.hibernate.cache.ehcache;