IBM WebSphereTM eXtreme Scale, Release 8.5
API Specification

com.ibm.websphere.objectgrid.hibernate.cache
Class ObjectGridHibernateCacheProvider

java.lang.Object
  extended by com.ibm.websphere.objectgrid.hibernate.cache.ObjectGridHibernateCacheProvider
All Implemented Interfaces:
org.hibernate.cache.CacheProvider

public final class ObjectGridHibernateCacheProvider
extends Object
implements org.hibernate.cache.CacheProvider

The ObjectGridHibernateCacheProvider is the implementation of Hibernate CacheProvider. Users can enable ObjectGrid as level 2 cache for Hibernate by configuring cache provider property in the Hibernate configuration file.

If using Hibernate as a JPA provider, the cache provider property name in persistence.xml is hibernate.cache.provider_class:

 <property
   name="hibernate.cache.provider_class"
   value="com.ibm.websphere.objectgrid.hibernate.cache.ObjectGridHibernateCacheProvider" />
 

If using the traditional Hibernate configuration, the cache provider property name is cache.provider_class:

 <property
   name="cache.provider_class">
     com.ibm.websphere.objectgrid.hibernate.cache.ObjectGridHibernateCacheProvider
 </property>
 

The following additional properties apply to the ObjectGrid:

  1. objectgrid.configuration: Comma-delimited ObjectGrid configuration properties.
  2. objectgrid.hibernate.regionNames: Comma-delimited Hibernate region names in use. This is optional property and should be specified when regionNames are defined after ObjectGrid cache is initialized. For example, if the Query.setCacheRegion(String regionName) method is executed after ObjectGrid cache initialization. This regionName could be a new regionName to cache and there won't be a corresponding BackingMap for it. To have better performance, these regionNames should be included in this property. If not, all regionNames that are determined dynamically will use a shared default BackingMap.

The following is a configuration example of JPA persistence.xml file.

 <property
   name="hibernate.cache.provider_class"
   value="com.ibm.websphere.objectgrid.hibernate.cache.ObjectGridHibernateCacheProvider" />
 <property
   name="hibernate.cache.use_query_cache" value="true" />
 <property
   name="objectgrid.configuration" value="ObjectGridName=MyObjectGridName, ObjectGridType=EMBEDDED , MaxNumberOfReplicas=47" />
 <property
   name="objectgrid.hibernate.regionNames" value="queryRegion1, queryRegion2" />

 

Since:
WAS XD 6.1.0.3

Constructor Summary
ObjectGridHibernateCacheProvider()
          The default constructor.
 
Method Summary
 org.hibernate.cache.Cache buildCache(String regionName, Properties props)
           
 int getPreloadBatchSize()
          Return the batch size of the preload process.
 String getPuName()
          Return the persistence unit name of the corresponding persistence unit.
 Set getTypeNames()
          Return the collection of type names used to create BackingMaps of the ObjectGrid.
 boolean isMinimalPutsEnabledByDefault()
           
 boolean isPreLoadMode()
          Return true if the cache provider is preloading data.
 long nextTimestamp()
           
static void preload(String objectGridName, EntityManagerFactory emf, Class theClass, int fetchSize, int maxRecords)
          Preload Hibernate entities into the ObjectGrid cache using the Hibernate JPA EntityManagerFactory.
static void preload(String objectGridName, org.hibernate.SessionFactory sF, Class theClass, int fetchSize, int maxRecords)
          Preload records from a database into the cache.
 void setPreloadBatchSize(int preloadBatchSize)
          Set the batch size of the preload process
 void start(Properties configProperty)
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectGridHibernateCacheProvider

public ObjectGridHibernateCacheProvider()
The default constructor.

Method Detail

buildCache

public org.hibernate.cache.Cache buildCache(String regionName,
                                            Properties props)
                                     throws org.hibernate.cache.CacheException
Specified by:
buildCache in interface org.hibernate.cache.CacheProvider
Throws:
org.hibernate.cache.CacheException
See Also:
CacheProvider.buildCache(java.lang.String, java.util.Properties)

isMinimalPutsEnabledByDefault

public boolean isMinimalPutsEnabledByDefault()
Specified by:
isMinimalPutsEnabledByDefault in interface org.hibernate.cache.CacheProvider
See Also:
CacheProvider.isMinimalPutsEnabledByDefault()

nextTimestamp

public long nextTimestamp()
Specified by:
nextTimestamp in interface org.hibernate.cache.CacheProvider
See Also:
CacheProvider.nextTimestamp()

start

public void start(Properties configProperty)
           throws org.hibernate.cache.CacheException
Specified by:
start in interface org.hibernate.cache.CacheProvider
Throws:
org.hibernate.cache.CacheException
See Also:
CacheProvider.start(java.util.Properties)

stop

public void stop()
Specified by:
stop in interface org.hibernate.cache.CacheProvider
See Also:
CacheProvider.stop()

getPuName

public String getPuName()
Return the persistence unit name of the corresponding persistence unit. This persistence name is not the persistence name configured in the persistence.xml file. It is generated by the cache provider.

Returns:
persistence unit name

getTypeNames

public Set getTypeNames()
Return the collection of type names used to create BackingMaps of the ObjectGrid. Each type name is corresponding to a BackingMap.

Returns:
the collection of type names

isPreLoadMode

public boolean isPreLoadMode()
Return true if the cache provider is preloading data.

Returns:
true if the cache provider is in preload mode

getPreloadBatchSize

public int getPreloadBatchSize()
Return the batch size of the preload process.

Returns:
the batch size of preload process

setPreloadBatchSize

public void setPreloadBatchSize(int preloadBatchSize)
Set the batch size of the preload process

Parameters:
preloadBatchSize -

preload

public static void preload(String objectGridName,
                           org.hibernate.SessionFactory sF,
                           Class theClass,
                           int fetchSize,
                           int maxRecords)
Preload records from a database into the cache.

Parameters:
objectGridName - the objectGrid name configured for the cache of persistence unit.
sF - Hibernate SessionFactory to use
theClass - The class corresponding to the database table to load
fetchSize - The number of records to fetch from the database at once
maxRecords - If > 0 this is the maximum record count to preload.

preload

public static void preload(String objectGridName,
                           EntityManagerFactory emf,
                           Class theClass,
                           int fetchSize,
                           int maxRecords)
Preload Hibernate entities into the ObjectGrid cache using the Hibernate JPA EntityManagerFactory.

Parameters:
objectGridName - the objectGrid name configured for the cache of persistence unit.
emf - The Hibernate JPA EntityManagerFactory to use to interact with Hibernate.
theClass - The class corresponding to the database table to load
fetchSize - The number of records to fetch from the database at once
maxRecords - If > 0 this is the maximum record count to preload.

IBM WebSphereTM eXtreme Scale, Release 8.5
API Specification

© Copyright International Business Machines Corp 2005,2012. All rights reserved.