IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

com.ibm.websphere.objectgrid.jpa
Class JPALoader

java.lang.Object
  extended by com.ibm.websphere.objectgrid.jpa.JPALoader
All Implemented Interfaces:
Loader, RetryableLoader
Direct Known Subclasses:
JPAEntityLoader

public class JPALoader
extends Object
implements RetryableLoader

This is the loader that uses Java Persistence API (JPA) to load and store data in the "database". Therefore, a JPA provider is required to use this feature. The "database" here can be any backend supported by the chosen JPA provider.

A TransactionCallback plugin, JPATxCallback, should be configured on the ObjectGrid to provide the transaction coordination between the ObjectGrid transaction and the JPA entity manager transaction for this loader to work. Otherwise, a LoaderException will be thrown.

A JPA persistence unit name and entity class name are required to use JPA. The persistence unit name is provided to the JPATxCallback instance and the entity class name is provided to this loader. This establishes a one to one relation between ObjectGrid instances and JPA persistence units and a one to one relation between ObjectGrid maps and JPA entities.

This loader is used for ObjectGrid maps that store POJO only. Use JPAEntityLoader for ObjectGrid maps that store ObjectGrid entities.

If the preloadPartition property is set to a valid partition, the preloadMap method will preload all the data into the ObjectGrid maps from that partition. The preloadMap uses ClientLoader to preload a map. By default, the preloadPartition is set to -1 to disable the map preload.

This JPALoader implements the RetryableLoader because it can handle a retry record from ObjectGrid. When the retry indication slot contains a Boolean.TRUE, the JPALoader handles the ObjectGrid log elements in the following ways:

  1. For an insert or update type log element, it calls EntityManager.merge(Object) method to merge the entity.
  2. For a delete type log element, if calls EntityManager.find(Class, Object) method to find the entity. If the entity is found, it calls EntityManager.remove(Object) method to remove it.

Since:
WAS XD 6.1.0.3
See Also:
ClientLoader

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.ibm.websphere.objectgrid.plugins.Loader
Loader.SpecialValue
 
Field Summary
protected  Class entityClass
           
protected  String entityClassName
           
protected  String mapName
           
protected  String ogName
           
protected  int preloadPartition
           
protected  int retryIndicationSlot
           
protected  JPATxCallback txCallback
           
 
Fields inherited from interface com.ibm.websphere.objectgrid.plugins.Loader
KEY_NOT_FOUND
 
Constructor Summary
JPALoader()
          Default constructor
 
Method Summary
 void batchUpdate(TxID txid, LogSequence sequence)
          Write the data from ObjectGrid entity maps to JPA.
 List get(TxID txid, List keyList, boolean forUpdate)
          Returns the list of values corresponding to the set of keys passed in by retrieving the data using JPA.
 String getEntityClassName()
          Retrieve the JPA entity class name that should be loaded.
 int getPreloadPartition()
           
 JPATxCallback getTxCallback()
          Retrieve the JPA transaction callback instance.
 void preloadMap(Session session, BackingMap backingMap)
          This method initializes the loader and preloads the map using the ClientLoader.load(ObjectGrid, String, String, Map, Class, String, Map, boolean, ClientLoadCallback) method.
 void setEntityClassName(String entityClassName)
          Set the name of the JPA entity class to load.
 void setPreloadPartition(int preloadPartition)
          Specify the partition at which the map preload will be launched.
 void setRetryIndicationSlot(int slotNumber)
          set the slot number which contains whether the batch update from ObjectGrid is a retry of previous transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txCallback

protected JPATxCallback txCallback

entityClassName

protected String entityClassName

entityClass

protected Class entityClass

preloadPartition

protected int preloadPartition

retryIndicationSlot

protected int retryIndicationSlot

ogName

protected String ogName

mapName

protected String mapName
Constructor Detail

JPALoader

public JPALoader()
Default constructor

Method Detail

setRetryIndicationSlot

public void setRetryIndicationSlot(int slotNumber)
Description copied from interface: RetryableLoader
set the slot number which contains whether the batch update from ObjectGrid is a retry of previous transaction. The retryable loader checks the retry indication Boolean by calling TxID.getSlot(int) method. If the slot contains a Boolean.TRUE object, then the log sequence is a retry sequence. If the slot contains a null object or a Boolean.FALSE, then the log sequence is not a retry sequence.

Specified by:
setRetryIndicationSlot in interface RetryableLoader
Parameters:
slotNumber - the slot number

batchUpdate

public void batchUpdate(TxID txid,
                        LogSequence sequence)
                 throws LoaderException,
                        OptimisticCollisionException
Write the data from ObjectGrid entity maps to JPA.

The LogSequence contains a sequence of log elements which contain keys and values. These keys are values are used to interact with JPA to insert, update, or merge a JPA entity.

Specified by:
batchUpdate in interface Loader
Parameters:
txid - the transaction id object
sequence - the set of changes being applied to this object's map
Throws:
LoaderException - if an error occurs during processing of this method
OptimisticCollisionException - if a version mismatch is detected
See Also:
Loader.batchUpdate(TxID, LogSequence)

get

public List get(TxID txid,
                List keyList,
                boolean forUpdate)
         throws LoaderException
Returns the list of values corresponding to the set of keys passed in by retrieving the data using JPA. The values are the JPA entities retrieved from JPA as a result of JPA find operation.

Specified by:
get in interface Loader
Parameters:
txid - the transaction ID object
keyList - List of keys
forUpdate - true when a getForUpdate method is called. This parameter can be used to do a "SELECT for UPDATE" invocation for proper database locking. JPA as a result of JPA find operation.
Returns:
List of Object values
Throws:
LoaderException - if an error occurs during processing of this method
See Also:
Loader.get(TxID, List, boolean)

preloadMap

public void preloadMap(Session session,
                       BackingMap backingMap)
                throws LoaderException
This method initializes the loader and preloads the map using the ClientLoader.load(ObjectGrid, String, String, Map, Class, String, Map, boolean, ClientLoadCallback) method. The persistence unit name and persistence property map are retrieved from the JPATxCallback TransactionCallback instance configured on the ObjectGrid.

For partition maps, the preload will only be called in one partition, which is specified by users using the preloadPartition property. If the preloadPartition value is set to less than 0, or greater than totalNumberOfPartition -1, no preload will happen.

Specified by:
preloadMap in interface Loader
Parameters:
session - a Session reference to use for demarcating transactions.
backingMap - the BackingMap this object is associated with
Throws:
LoaderException - if an error occurs during processing of this method Since the default value of preloadPartition is -1, the map will not be preloaded by default.
LoaderException - if a JPATxCallback is not configured.

See Also:
Loader.preloadMap(Session, BackingMap)

getPreloadPartition

public int getPreloadPartition()
Returns:
Returns the preloadPartition.

setPreloadPartition

public void setPreloadPartition(int preloadPartition)
Specify the partition at which the map preload will be launched. If the preloadPartition is less than 0, or greater than totalNumberOfPartition -1, map preload will not be launched.

The default value of preloadPartition is -1. Therefore, by default, map preload will not be launched.

Parameters:
preloadPartition - The preloadPartition to set.

getEntityClassName

public String getEntityClassName()
Retrieve the JPA entity class name that should be loaded.

Returns:
the JPA entity class name.

setEntityClassName

public void setEntityClassName(String entityClassName)
Set the name of the JPA entity class to load.

Parameters:
entityClassName - the JPA entity class name to set.
Throws:
IllegalArgumentException - if the entity class name cannot be found

getTxCallback

public JPATxCallback getTxCallback()
Retrieve the JPA transaction callback instance. The JPATxCallback instance can be used to retrieve the EntityManager instance for this transaction.

Returns:
the JPATxCallback instance
See Also:
JPATxCallback.getEntityManager(TxID)

IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

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