multiGet()の使用

KVStore.multiGet()を使用すると、複数のレコードで同じメジャー・パス・コンポーネントが共有されている場合、それらのレコードを一度に取得できます。指定するメジャー・パス・コンポーネントは、コンポーネントの完全なセットを表す必要があります。

取得セットがメモリーに完全に収まる場合にのみKVStore.multiGet()を使用します。

たとえば、次のキーを使用するとします。

/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

次のようにして、メジャー・キー・コンポーネントHatsを使用するすべてのレコードを取得できます。

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
} 

次のようにして、結果のソートされたマップを反復できます。

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