org.hibernate.cache.ehcache
Class EhCacheRegionFactory

java.lang.Object
  extended by org.hibernate.cache.ehcache.EhCacheRegionFactory
All Implemented Interfaces:
Serializable, RegionFactory, Service

public class EhCacheRegionFactory
extends Object

A non-singleton EhCacheRegionFactory implementation.

See Also:
Serialized Form

Field Summary
protected  EhcacheAccessStrategyFactory accessStrategyFactory
          EhcacheAccessStrategyFactory for creating various access strategies
protected  net.sf.ehcache.CacheManager manager
          Ehcache CacheManager that supplied Ehcache instances for this Hibernate RegionFactory.
protected  ProviderMBeanRegistrationHelper mbeanRegistrationHelper
          MBean registration helper class instance for Ehcache Hibernate MBeans.
static String NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME
          The Hibernate system property specifying the location of the ehcache configuration file name.
protected  Settings settings
          Settings object for the Hibernate persistence unit.
 
Constructor Summary
EhCacheRegionFactory()
           
EhCacheRegionFactory(Properties prop)
          Creates a non-singleton EhCacheRegionFactory
 
Method Summary
 CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata)
          Build a cache region specialized for storing collection data.
 EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata)
          Build a cache region specialized for storing entity data.
 NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata)
          Build a cache region specialized for storing NaturalId to Primary Key mappings.
 QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties)
          Build a cache region specialized for storing query results
 TimestampsRegion buildTimestampsRegion(String regionName, Properties properties)
          Build a cache region specialized for storing update-timestamps data.
 AccessType getDefaultAccessType()
          Default access-type used when the configured using JPA 2.0 config.
 boolean isMinimalPutsEnabledByDefault()
          Whether to optimize for minimals puts or minimal gets.
protected  URL loadResource(String configurationResourceName)
          Load a resource from the classpath.
 long nextTimestamp()
          Generate a timestamp.
 void setClassLoaderService(ClassLoaderService classLoaderService)
           
 void start(Settings settings, Properties properties)
          Lifecycle callback to perform any necessary initialization of the underlying cache implementation(s).
 void stop()
          Lifecycle callback to perform any necessary cleanup of the underlying cache implementation(s).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME

public static final String NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME
The Hibernate system property specifying the location of the ehcache configuration file name.

If not set, ehcache.xml will be looked for in the root of the classpath.

If set to say ehcache-1.xml, ehcache-1.xml will be looked for in the root of the classpath.

See Also:
Constant Field Values

mbeanRegistrationHelper

protected final ProviderMBeanRegistrationHelper mbeanRegistrationHelper
MBean registration helper class instance for Ehcache Hibernate MBeans.


manager

protected volatile net.sf.ehcache.CacheManager manager
Ehcache CacheManager that supplied Ehcache instances for this Hibernate RegionFactory.


settings

protected Settings settings
Settings object for the Hibernate persistence unit.


accessStrategyFactory

protected final EhcacheAccessStrategyFactory accessStrategyFactory
EhcacheAccessStrategyFactory for creating various access strategies

Constructor Detail

EhCacheRegionFactory

public EhCacheRegionFactory()

EhCacheRegionFactory

public EhCacheRegionFactory(Properties prop)
Creates a non-singleton EhCacheRegionFactory

Method Detail

start

public void start(Settings settings,
                  Properties properties)
           throws CacheException
Lifecycle callback to perform any necessary initialization of the underlying cache implementation(s). Called exactly once during the construction of a SessionFactoryImpl.

Parameters:
settings - The settings in effect.
properties - The defined cfg properties
Throws:
CacheException - Indicates problems starting the L2 cache impl; considered as a sign to stop SessionFactory building.

stop

public void stop()
Lifecycle callback to perform any necessary cleanup of the underlying cache implementation(s). Called exactly once during SessionFactory.close().


isMinimalPutsEnabledByDefault

public boolean isMinimalPutsEnabledByDefault()
Whether to optimize for minimals puts or minimal gets.

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 affect on unclustered users, and has great benefit for clustered users.

This setting can be overridden by setting the "hibernate.cache.use_minimal_puts" property in the Hibernate configuration.

Specified by:
isMinimalPutsEnabledByDefault in interface RegionFactory
Returns:
true, optimize for minimal puts

nextTimestamp

public long nextTimestamp()
Generate a timestamp.

This is generally used for cache content locking/unlocking purposes depending upon the access-strategy being used.

Specified by:
nextTimestamp in interface RegionFactory
Returns:
The generated timestamp.

buildEntityRegion

public EntityRegion buildEntityRegion(String regionName,
                                      Properties properties,
                                      CacheDataDescription metadata)
                               throws CacheException
Build a cache region specialized for storing entity data.

Specified by:
buildEntityRegion in interface RegionFactory
Parameters:
regionName - The name of the region.
properties - Configuration properties.
metadata - Information regarding the type of data to be cached
Returns:
The built region
Throws:
CacheException - Indicates problems building the region.

buildNaturalIdRegion

public NaturalIdRegion buildNaturalIdRegion(String regionName,
                                            Properties properties,
                                            CacheDataDescription metadata)
                                     throws CacheException
Description copied from interface: RegionFactory
Build a cache region specialized for storing NaturalId to Primary Key mappings.

Specified by:
buildNaturalIdRegion in interface RegionFactory
Parameters:
regionName - The name of the region.
properties - Configuration properties.
metadata - Information regarding the type of data to be cached
Returns:
The built region
Throws:
CacheException - Indicates problems building the region.

buildCollectionRegion

public CollectionRegion buildCollectionRegion(String regionName,
                                              Properties properties,
                                              CacheDataDescription metadata)
                                       throws CacheException
Build a cache region specialized for storing collection data.

Specified by:
buildCollectionRegion in interface RegionFactory
Parameters:
regionName - The name of the region.
properties - Configuration properties.
metadata - Information regarding the type of data to be cached
Returns:
The built region
Throws:
CacheException - Indicates problems building the region.

buildQueryResultsRegion

public QueryResultsRegion buildQueryResultsRegion(String regionName,
                                                  Properties properties)
                                           throws CacheException
Build a cache region specialized for storing query results

Specified by:
buildQueryResultsRegion in interface RegionFactory
Parameters:
regionName - The name of the region.
properties - Configuration properties.
Returns:
The built region
Throws:
CacheException - Indicates problems building the region.

setClassLoaderService

public void setClassLoaderService(ClassLoaderService classLoaderService)

buildTimestampsRegion

public TimestampsRegion buildTimestampsRegion(String regionName,
                                              Properties properties)
                                       throws CacheException
Build a cache region specialized for storing update-timestamps data.

Specified by:
buildTimestampsRegion in interface RegionFactory
Parameters:
regionName - The name of the region.
properties - Configuration properties.
Returns:
The built region
Throws:
CacheException - Indicates problems building the region.

loadResource

protected URL loadResource(String configurationResourceName)
Load a resource from the classpath.


getDefaultAccessType

public AccessType getDefaultAccessType()
Default access-type used when the configured using JPA 2.0 config. JPA 2.0 allows @Cacheable(true) to be attached to an entity without any access type or usage qualification.

We are conservative here in specifying AccessType.READ_WRITE so as to follow the mantra of "do no harm".

This is a Hibernate 3.5 method.

Specified by:
getDefaultAccessType in interface RegionFactory
Returns:
This factory's default access type.


Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.