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:
/Hats/-/baseball /Hats/-/baseball/longbill /Hats/-/baseball/longbill/blue /Hats/-/baseball/longbill/red /Hats/-/baseball/shortbill /Hats/-/baseball/shortbill/blue /Hats/-/baseball/shortbill/red /Hats/-/western /Hats/-/western/felt /Hats/-/western/felt/black /Hats/-/western/felt/gray /Hat/-/swestern/leather /Hat/-/swestern/leather/black /Hat/-/swestern/leather/gray
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
majorComponents.add("Hats");
// 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
}