Retrieving a Single Record

To retrieve a record from the store, use the KVStore.get() method. This method returns a ValueVersion object. Use ValueVersion.getValue() to return the Value object associated with the key. It is then up to your application to turn the Value's byte array into a useful form. Normally, this will require the use of an Avro binding. See Avro Bindings for details.

For example, in Writing Records to the Store we showed a trivial example of storing a key-value pair to the store, where the value was a simple String. The following trivial example shows how to retrieve that record. (Again, this is not how your code should deserialize data, because this example does not use Avro to manage the value's schema.)

package kvstore.basicExample;


import oracle.kv.Key;
import oracle.kv.Value;
import oracle.kv.ValueVersion;
import java.util.ArrayList;


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


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


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

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

ValueVersion vv = kvstore.get(myKey);
Value v = vv.getValue(); 
String data = new String(v.getValue());