Product overview > Tutorials, examples, and samples > ObjectQuery tutorial



ObjectQuery tutorial - step 2

With the following steps, you can continue to create an ObjectGrid with one map and an index, along with a schema for the map. Then you can insert an object into the cache and later retrieve it using a simple query.


Before you begin

Be sure that you have completed ObjectQuery tutorial - step 1 before proceeding with this step of the tutorial.


Procedure


Schema and index

Application.java


// Create an index
    HashIndex idx= new HashIndex();
    idx.setName("theItemName");
    idx.setAttributeName("itemName");
    idx.setRangeIndex(true);
    idx.setFieldAccessAttribute(true);
    orderBMap.addMapIndexPlugin(idx);
}

The index must be a com.ibm.websphere.objectgrid.plugins.index.HashIndex instance with the following settings:

When a query runs that filters on the itemName field, the query engine automatically uses the defined index. Using the index allows the query to run much faster and a map scan is not needed. The next step demonstrates how an index can be used to optimize the query.

Next step


Parent topic:

ObjectQuery tutorial


Previous topic:

ObjectQuery tutorial - step 1


Next topic:

ObjectQuery tutorial - step 3