You are here: Basics Operations & Concepts > Indexing > Traversing the Index Values

Traversing the Index Values

The db4o query processor uses the index to speed up queries. So you just use the query APIs to benefit from indexes. For special cases you might want to traverse the indexed values yourself. You can do this by accessing the index via the db4o meta data. There you can get the meta-info for a field and then traverse its index. Note that the traverse-method will throw an exception if there is no index available.

final StoredField storedField = container.ext()
        .storedClass(Item.class).storedField("data", int.class);
storedField.traverseValues(new Visitor4<Integer>() {
    @Override
    public void visit(Integer fieldValue) {
        System.out.println("Value "+fieldValue);
    }
});
TraverseIndexExample.java: Traverse index