|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.websphere.objectgrid.plugins.index.HashIndex
public class HashIndex
HashIndex is a built-in index implementation of a MapIndexPlugin
and can be used for typical indexing operations.
This index plug-in supports both the MapIndex
and MapRangeIndex
interfaces and can be used for maps
that store native Java Objects, EntityManager API entities or when a DataSerializer plug-in is used.
Client applications should not extend this class.
When used with Java Objects (POJO), HashIndex uses Java reflection to dynamically introspect objects stored in a map when they are updated. It can index any individual fields or properties in the key or value portion of a map. The index implementation uses a synchronized HashMap to index the attributes for a non-range mode or a synchronized TreeMap for range mode.
When used with the KeySerializerPlugin
and ValueSerializerPlugin
BackingMap plug-ins,
the DataSerializer.DataAttributeInflatable.inflateDataObjectAttributes(DataObjectContext, XsDataInputStream, Object) is used
to inflate and introspect the cache data. HashIndex does not require that the attributes be defined in the DataDescriptor.
When used with a BackingMap associated with an EntityManager API entity, the attributes are fetched directly from the underlying Tuple. HashIndex validates configured index attributes against the associated EntityMetadata.
The following properties can be used to configure the index using the ObjectGrid deployment descriptor XML file or programmatically:
Property Name | Applicability | Description |
Name | POJO, Entity, Serializer | The name of the index. The name must be unique for each map. |
AttributeName | POJO, Entity, Serializer | The comma-delimited names of the attributes to index.
For field-access indexes, the attribute names are equivalent to the field names. |
FieldAccessAttribute | POJO | If true, the object is accessed using the fields directly. If not specified or false, the attribute's getter method is used to access the data. |
POJOKeyIndex | POJO | If true, the index will introspect the object in the key part of the map. This is useful when the key is a composite key and the value does not have the key embedded within it. If not specified or false, then the index will introspect the object in the value part of the map. |
RangeIndex | POJO, Entity, Serializer | If true, range indexing is enabled. |
GlobalIndexEnabled | POJO, Entity, Serializer | If true, global index support is enabled. |
The following is an ObjectGrid descriptor XML file example that defines the built-in HashIndex MapIndexPlugin for BackingMap:
<?xml version="1.0" encoding="UTF-8"?> <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config"> <objectGrids> <objectGrid name="indexSampleGrid"> <backingMap name="person" pluginCollectionRef="person" readOnly="false" preloadMode="false" lockStrategy="OPTIMISTIC" copyMode="COPY_ON_READ_AND_COMMIT" /> </objectGrid> </objectGrids> <backingMapPluginCollections> <backingMapPluginCollection id="person"> <bean id="MapIndexPlugin" className="com.ibm.websphere.objectgrid.plugins.index.HashIndex"> <property name="Name" type="java.lang.String" value="person.employeeCode" description="index name" /> <property name="AttributeName" type="java.lang.String" value="employeeCode" description="attribute name" /> <property name="RangeIndex" type="boolean" value="true" description="true for MapRangeIndex" /> <property name="FieldAccessAttribute" type="boolean" value="false" description="property-access" /> <property name="POJOKeyIndex" type="boolean" value="false" description="Attribute is in the value (not the key)" /> </bean> </backingMapPluginCollection> </backingMapPluginCollections> </objectGridConfig>
These properties can also be set programmatically, using the JavaBean pattern. For example, the setName(String) method is for setting Name property:
BackingMap personBackingMap = ivObjectGrid.getMap("person"); //use the built-in HashIndex class as the index plug-in class. HashIndex mapIndexPlugin = new HashIndex(); mapIndexPlugin.setName("person.employeeCode"); mapIndexPlugin.setAttributeName("employeeCode"); mapIndexPlugin.setRangeIndex(true); mapIndexPlugin.setFieldAccessAttribute(true); mapIndexPlugin.setPOJOKeyIndex(true); personBackingMap.addMapIndexPlugin(mapIndexPlugin);
MapIndexPlugin
,
MapIndex
,
MapRangeIndex
Field Summary |
---|
Fields inherited from interface com.ibm.websphere.objectgrid.plugins.index.MapIndexPlugin |
---|
SYSTEM_KEY_INDEX_NAME |
Constructor Summary | |
---|---|
HashIndex()
Creates a new HashIndex object. |
Method Summary | |
---|---|
void |
destroy()
Invoked when the bean's state has been set and is ready to be destroyed. |
void |
doBatchUpdate(TxID txid,
LogSequence sequence)
Called by ObjectGrid runtime to allow the index to be updated as the result of changes applied to a map during the commit cycle of a transaction. |
Object |
getAttribute(Object valueOrKey)
Extracts the attribute from a specified object. |
String |
getAttributeName()
Retrieves the attribute name or comma-delimited list of attribute names that was set with the setAttributeName(String) method. |
String[] |
getAttributeNames()
Retrieves the names of each attribute included in the index that was set with the setAttributeName(String) method. |
BackingMap |
getBackingMap()
Retrieve the BackingMap instance associated with this plug-in. |
Object |
getIndexProxy(MapIndexInfo map)
Gets an index proxy object for performing index lookup operations. |
Object |
getIndexProxy(MapIndexInfo map,
boolean forUpdate)
Gets an index proxy object for performing index lookup operations, optionally requesting upgradeable (U) locks when accessing maps during validation. |
String |
getName()
Gets the name of the index. |
Properties |
getProperties()
Extract properties from a MapIndexPlugin instance. |
void |
initialize()
Invoked when the bean's state has been set and is ready to be initialized. |
boolean |
isDestroyed()
Answers true if the bean is in the destroyed state, false otherwise. |
boolean |
isFieldAccessAttribute()
return the value of FieldAccessAttribute property |
boolean |
isGlobalIndexEnabled()
return the value of globalIndexEnabled property |
boolean |
isInitialized()
Answers true if the bean is in the initialized state, false otherwise. |
boolean |
isPOJOKeyIndex()
return the value of POJOKeyIndex property |
boolean |
isRangeIndex()
Indicates if this index is the type of MapRangeIndex interface. |
void |
setAttributeName(String attributeName)
Sets the comma-delimited set of attribute names to include in the index. |
void |
setBackingMap(BackingMap map)
The BackingMap instance is at an undefined state, depending on the type of plug-in and how it was registered with the map. |
void |
setEntityMetadata(EntityMetadata entityMetadata)
Called by the ObjectGrid runtime to set the EntityMetadata of the BackingMap. |
void |
setFieldAccessAttribute(boolean isFieldAccessAttribute)
Setter for the fieldAccessAttribute property. |
void |
setGlobalIndexEnabled(boolean globalIndexEnabled)
Sets whether to enable global index and create a MapGlobalIndex . |
void |
setName(String name)
Sets the name of this index. |
void |
setPOJOKeyIndex(boolean isPOJOKeyIndex)
Setter for the POJOKeyIndex property. |
void |
setProperties(Properties properties)
Set properties of a MapIndexPlugin instance. |
void |
setRangeIndex(boolean rangeIndex)
Sets whether to create a MapRangeIndex or a MapIndex . |
void |
undoBatchUpdate(TxID txid,
LogSequence sequence)
Called by the ObjectGrid runtime to undo any changes made to the index as a result of a prior call to the doBatchUpdate(TxID, LogSequence)
method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HashIndex()
Method Detail |
---|
public void setFieldAccessAttribute(boolean isFieldAccessAttribute)
This property does not apply BackingMaps that have an EntityManager API entity associated or if the BackingMap has a MapSerializerPlugin configured.
isFieldAccessAttribute
- public boolean isFieldAccessAttribute()
public void setPOJOKeyIndex(boolean isPOJOKeyIndex)
This property does not apply BackingMaps that have an EntityManager API entity associated or if the BackingMap has a MapSerializerPlugin configured.
isPOJOKeyIndex
- public boolean isPOJOKeyIndex()
public void setProperties(Properties properties)
MapIndexPlugin
setProperties
in interface MapIndexPlugin
properties
- The Properties object that can be used to initialize a MapIndexPlugin instance.MapIndexPlugin.getProperties()
public Properties getProperties()
MapIndexPlugin
getProperties
in interface MapIndexPlugin
MapIndexPlugin.setProperties(Properties)
public void setName(String name)
name
- the name of the indexpublic void setRangeIndex(boolean rangeIndex)
MapRangeIndex
or a MapIndex
.
If this method is never called, a MapIndex
is used as the default implementation.
rangeIndex
- true
for a MapRangeIndex, false
for MapIndexMapIndex
,
MapRangeIndex
,
ObjectMap.getIndex(String)
public boolean isGlobalIndexEnabled()
public void setGlobalIndexEnabled(boolean globalIndexEnabled)
MapGlobalIndex
.
globalIndexEnabled
- true
for support of MapGlobalIndex,
false
for no support of MapGlobalIndex.MapGlobalIndex
,
ObjectMap.getIndex(String)
public boolean isRangeIndex()
MapIndexPlugin
isRangeIndex
in interface MapIndexPlugin
MapRangeIndex
public String[] getAttributeNames()
setAttributeName(String)
method.
setAttributeName(String)
method. Answers
null
if the setAttributeName
method was
not previously called.setAttributeName(String)
public void setEntityMetadata(EntityMetadata entityMetadata)
MapIndexPlugin
The EntityMetadata is required for supporting Tuple indexing.
setEntityMetadata
in interface MapIndexPlugin
entityMetadata
- the EntityMetadata of the BackingMap.public void doBatchUpdate(TxID txid, LogSequence sequence) throws ObjectGridRuntimeException
MapIndexPlugin
Use the LogElement.getType()
method to determine what
operation is required for updating the index. Use the
LogElement.getBeforeImage()
method to get the value object
that existed prior to the committing transaction applying a change to the
map. Use the LogElement.getAfterImage()
method to get the
value object after the committing transaction applied the change to the
map entry.
For a MapIndexPlugin in an ObjectMap
that is configured to use OutputFormat.RAW
for the keys or values, the keys and values objects in the LogSequence
will be SerializedKey
or SerializedValue
objects respectively. If required, you
can use the SerializedEntry.getObject()
method to retrieve (possibly inflating
the serialized object) the original key or value object.
To override the map's output format configuration, use the PluginOutputFormat
annotation in the implementation class.
Note, the undoBatchUpdate(TxID, LogSequence)
method may be
called later to undo these changes if an exception occurs that causes
the committing transaction to be rolled back instead.
doBatchUpdate
in interface MapIndexPlugin
txid
- the transaction context (TxID) for the changes.sequence
- the log sequence that contains the changes from transaction.
ObjectGridRuntimeException
- is a failure occurs that requires transaction
to be rolled back.MapIndexPlugin.doBatchUpdate(TxID,LogSequence)
public void undoBatchUpdate(TxID txid, LogSequence sequence) throws ObjectGridException
MapIndexPlugin
doBatchUpdate(TxID, LogSequence)
method.
This method is called when an exception or error condition that requires
all changes made by a transaction to be rolled back. For this reason,
the implementation of this method should catch all Throwables and
continue with the next LogElement
in the
LogSequence
until all LogElement
s are processed
so that as many changes to the index are undone as possible. An
ObjectGridException should only be thrown after processing the entire
LogSequence
and this method was unable to successfully undo
one or more changes in the LogSequence
.
Use the LogElement.getUndoType()
method to determine what
operation is required to undo any change made to the index. Use the
LogElement.getBeforeImage()
to get the value object that
existed prior to the committing transaction applying a change to the map.
Use the LogElement.getAfterImage()
to get the value
object after the committing transaction applied the change to the map entry.
For a MapIndexPlugin in an ObjectMap
that is configured to use OutputFormat.RAW
for the keys or values, the keys and values objects in the LogSequence
will be SerializedKey
or SerializedValue
objects respectively. If required, you
can use the SerializedEntry.getObject()
method to retrieve (possibly inflating
the serialized object) the original key or value object.
To override the map's output format configuration, use the PluginOutputFormat
annotation in the implementation class.
undoBatchUpdate
in interface MapIndexPlugin
txid
- the transaction context (TxID) for the changes.sequence
- the log sequence that contains changes from transaction.
ObjectGridException
- is an error occurred during processingMapIndexPlugin.undoBatchUpdate(TxID, LogSequence)
public Object getAttribute(Object valueOrKey) throws ObjectGridRuntimeException
KeySerializerPlugin
or ValueSerializerPlugin
, then the
object passed in should be the key or value object as appropriate for the index.
getAttribute
in interface MapIndexPlugin
valueOrKey
- The value or key object.
ObjectGridRuntimeException
- is thrown if any exception occurs attempting to extract the attribute value from the value or key Object.public String getName()
MapIndexPlugin
getName
in interface MapIndexPlugin
ObjectMap.getIndex(String)
public String getAttributeName()
setAttributeName(String)
method.
getAttributeName
in interface MapIndexPlugin
setAttributeName(String)
method or null
if the setAttributeName
method was not previously
called or if more than one attribute is defined.setAttributeName(String)
,
getAttributeNames()
public void setAttributeName(String attributeName)
The attribute name format is dependent on how the associated BackingMap is configured:
For POJO maps, attributes are accessed using reflection, using the field name or the property name as defined by the JavaBean specification. The setPOJOKeyIndex(boolean) property identifies if the attribute is in the key or value of the cache entry. The setFieldAccessAttribute(boolean) identifies how to access the cache object: by field or by getter method.
For entity maps, attributes are accessed directly from the Tuple object stored in the map. The attribute name must match the attribute name assocated in the EntityMetadata.
For MapSerializerPlugin maps, the attribute names are passed directly to the DataSerializer.DataAttributeInflatable.getAttributeContexts(String...) method
and the attribute values are fetched using the
DataSerializer.DataAttributeInflatable.inflateDataObjectAttributes(DataObjectContext, XsDataInputStream, Object)
method. The attribute name is a path to an attribute within the key or value.
A key attribute is specified by including the "key" path prefix, or the prefix specified by the MapDataDescriptor.getAddressableKeyName()
method.
The path delmiter is specified in the DataDescriptor.getPathSeparator()
for the DataDescriptor for each KeyDataSerializer or ValueSerializer.
MapSerializerPlugin index attribute examples:
(assuming the default addressible key name of "key" and path separator of ".")
name
- Indexes the "name" attribute in the value.
key.ssn
- Indexes the "ssn" attribute in the key.
address.country.code
- Indexes the "code" attribute from the "country" embedded type from the "address" embedded type in the value.
setAttributeName
in interface MapIndexPlugin
attributeName
- the name of the attribute to set.MapIndexPlugin.setAttributeName(String)
public Object getIndexProxy(MapIndexInfo map)
MapIndexPlugin
The caller must cast the object returned to either a MapIndex
or
MapRangeIndex
to perform the lookup operations.
getIndexProxy
in interface MapIndexPlugin
map
- the MapIndexInfo object required for maintaining the index.
.
MapIndexPlugin.getIndexProxy(MapIndexInfo)
public Object getIndexProxy(MapIndexInfo map, boolean forUpdate)
The caller must cast the object returned to either a MapIndex
or
MapRangeIndex
to perform the lookup operations.
map
- the MapIndexInfo object required for maintaining the index.forUpdate
- if true, request upgradeable (U) locks when validating
results, otherwise request shareable (S) locks.
MapIndex
,
MapRangeIndex
,
ObjectMap.getIndex(String)
,
MapIndexPlugin.getIndexProxy(MapIndexInfo)
public void setBackingMap(BackingMap map)
BackingMapPlugin
BackingMap.getState()
method
to determine what state the map is in.
setBackingMap
in interface BackingMapPlugin
map
- the BackingMap associated with this plug-in instance.public BackingMap getBackingMap()
BackingMapPlugin
During normal operation, this method may be called to confirm the correct
operation of the BackingMapPlugin.
It must return the BackingMap instance previously set using
the BackingMapPlugin.setBackingMap(BackingMap)
method.
getBackingMap
in interface BackingMapPlugin
public void initialize() throws ObjectGridRuntimeException
Initializable
initialize
in interface Initializable
ObjectGridRuntimeException
public boolean isInitialized()
Initializable
During normal operation, this method may be called to confirm the correct
operation of the Initializable.initialize()
method.
isInitialized
in interface Initializable
public void destroy()
Destroyable
destroy
in interface Destroyable
public boolean isDestroyed()
Destroyable
During normal operation, this method may be called to confirm the correct
operation of the Destroyable.destroy()
method.
isDestroyed
in interface Destroyable
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |