Using multiGet()

KVStore.multiGet() allows you to retrieve multiple records at once, so long as they all share the same major path components. The major path components that you provide must represent a complete set of components.

Use KVStore.multiGet() only if your retrieval set will fit entirely in memory.

For example, suppose you use the following keys:


Then you can retrieve all of the records that use the major key component Hats as follows:

package kvstore.basicExample;


import oracle.kv.ConsistencyException;
import oracle.kv.Key;
import oracle.kv.RequestTimeoutException;
import oracle.kv.Value;
import oracle.kv.ValueVersion;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedMap;
import java.util.Map;


ArrayList<String> majorComponents = new ArrayList<String>();


// Define the major and minor path components for the key

// Create the retrieval key
Key myKey = Key.createKey(majorComponents);

// Now retrieve the records. Note that we do not show the creation of 
// the kvstore handle here.

SortedMap<Key, ValueVersion> myRecords = null;

try {
    myRecords = kvstore.multiGet(myKey, null, null);
} catch (ConsistencyException ce) {
    // The consistency guarantee was not met
} catch (RequestTimeoutException re) {
    // The operation was not completed within the 
    // timeout value

You can then iterate over the resulting sorted map as follows:

for (Map.Entry<Key, ValueVersion> entry : myRecords.entrySet()) {
    ValueVersion vv = entry.getValue();
    Value v = vv.getValue();
    // Do some work with the Value here