Configuring the HashIndex plug-in
You can configure the built-in HashIndex, the com.ibm.websphere.objectgrid.plugins.index.HashIndex class, with an XML file, programmatically or with an entity annotation on an entity map.
About this task
Configuring a composite index is the same as configuring a regular index with XML, except for the attributeName property value. In a composite index, the value of attributeName property is a comma-delimited list of attributes. For example, the value class Address has three attributes: city, state, and zipcode. A composite index can be defined with the attributeName property value as "city,state,zipcode" indicating that city, state, and zipcode are included in the composite index.
The composite HashIndexes do not support range lookups and therefore cannot have the RangeIndex property set to true.
Procedure
Example: Adding a HashIndex class into a BackingMap instance
In the following example, you configure the HashIndex plug-in by adding static index plug-ins to the XML file:
<backingMapPluginCollection id="person">
<bean id="MapIndexPlugin"
className="com.ibm.websphere.objectgrid.plugins.index.HashIndex">
<property name="Name" type="java.lang.String" value="CODE"
description="index name" />
<property name="RangeIndex" type="boolean" value="true"
description="true for MapRangeIndex" />
<property name="AttributeName" type="java.lang.String" value="employeeCode"
description="attribute name" />
</bean>
</backingMapPluginCollection>
In this XML configuration example, the built-in HashIndex class is used as the index plug-in. The HashIndex supports properties that users can configure, such as Name, RangeIndex, and AttributeName.
- The Name property is configured as
CODE
, a string that identifies this index plug-in. The Name property value must be unique within the scope of the backing map. The name can be used to retrieve the index object by name from the ObjectMap instance for the BackingMap. - The RangeIndex property is configured as
true
, which means the application can cast the retrieved index object to the MapRangeIndex interface. If the RangeIndex property is configured asfalse
, the application can only cast the retrieved index object to the MapIndex interface. A MapRangeIndex supports functions to find data using range functions such as greater than, less than, or both, while a MapIndex supports equals functions only. If the index is to be used by query, the RangeIndex property must be configured totrue
on single-attribute indexes orfalse
on relationship or composite indexes. For a relationship index and composite index, the RangeIndex property must be configured tofalse
. - The AttributeName property is configured
as
employeeCode
, which means the employeeCode attribute of the cached object is used to build a single-attribute index. If an application must search for cached objects with multiple attributes, the AttributeName property can be set to a comma-delimited list of attributes, yielding a composite index.
In summary, the previous example defines a single-attribute range HashIndex. It is a single-attribute HashIndex because the AttributeName property value is employeeCode that includes only one attribute name. It also is a range HashIndex.