ストアで複数キー操作を行う場合、操作対象のレコードの範囲を指定できます。これは、KeyRangeクラスを使用して行います。このクラスで、複数取得操作で使用されるキーの直下のキー・コンポーネントに対してString値の範囲を定義します。
たとえば、次のキーを使用するとします。
/Smith/Bob/-/birthdate /Smith/Bobphone/-/number /Smith/Bob/-/image /Smith/Bob/-/userID /Smith/Patricia/-/birthdate /Smith/Patricia/-/phonenumber /Smith/Patricia/-/image /Smith/Patricia/-/userID /Smith/Richard/-/birthdate /Smith/Richard/-/phonenumber /Smith/Richard/-/image /Smith/Richard/-/userID /Wong/Bill/-/birthdate /Wong/Bill/-/phonenumber /Wong/Bill/-/image /Wong/Bill/-/userID
この仮定で、KeyRangeを作成して、ユーザーBob SmithとPatricia Smithに関連するすべてのレコードに対する操作を行うとします。これを行う場合、範囲の上限と下限を定義するキー・コンポーネントを指定する必要があります。指定したキー・コンポーネントを含めるか、除外するかも指定する必要があります。
このケースでは、文字列"Bob"を使用してキー範囲の始まりを定義し、キー範囲の終わりを"Patricia"と定義します。キー範囲の両端は含まれます。
package kvstore.basicExample;
...
import oracle.kv.KeyRange;
...
KeyRange kr = new KeyRange("Bob", true, "Patricia", true);
複数キー操作を行う際、KeyRangeインスタンスを使用します。たとえば、KVStore.storeIterator()を使用してストアからレコードを取得するとします。
package kvstore.basicExample;
...
import oracle.kv.Direction;
import oracle.kv.Key;
import oracle.kv.Value;
import oracle.kv.KeyRange;
import oracle.kv.KeyValueVersion;
import java.util.ArrayList;
import java.util.Iterator;
...
ArrayList<String> majorComponents = new ArrayList<String>();
...
// Define the major and minor path components for the key
majorComponents.add("Smith");
// Create the retrieval key
Key myKey = Key.createKey(majorComponents);
KeyRange kr = new KeyRange("Bob", true, "Patricia", true);
// Now retrieve the records. Note that we do not show the creation of
// the kvstore handle here.
Iterator<KeyValueVersion> i =
kvstore.storeIterator(Direction.UNORDERED, 0,
myKey, kr, null);
while (i.hasNext()) {
Value v = i.next().getValue();
// Do some work with the Value here
}