Chapter 4. Developing for Oracle NoSQL Database

Table of Contents

The KVStore Handle
The KVStoreConfig Class

You access the data in the Oracle NoSQL Database KVStore using Java APIs that are provided with the product. These APIs allow you to create keys and values, put key-value pairs into the store, then retrieve them again. You also use these APIs to define consistency and durability guarantees. It is also possible to execute a sequence of store operations at one time so that all the operations succeed, or none of them do.

The rest of this book introduces the Java APIs that you use to access the store, and the concepts that go along with them.

Note

Oracle NoSQL Database requires Java SE 6 (jdk 1.6.0 u25) or later.

The KVStore Handle

In order to perform store access of any kind, you must obtain a KVStore handle. You obtain a KVStore handle by using the KVStoreFactory class.

When you get a KVStore handle from the KVStoreFactory class, you must provide a KVStoreConfig object. This object identifies important properties about the store that you are accessing. We describe the KVStoreConfig class next in this chapter, but at a minimum you must use this class to identify:

  • The name of the store. The name provided here must be identical to the name used when the store was installed.

  • The network contact information for one or more helper hosts. These are the network name and port information for replication nodes currently belonging to the replication group. Multiple nodes can be identified using an array of strings. You can use one or many. Many does not hurt. The downside of using one is that the chosen host may be temporarily down, so it is a good idea to use more than one.

package kvstore.basicExample;

import oracle.kv.KVStore;
import oracle.kv.KVStoreConfig;
import oracle.kv.KVStoreFactory;

...

String[] hhosts = {"n1.example.org:5088", "n2.example.org:4129"};
KVStoreConfig kconfig = new KVStoreConfig("exampleStore", hhosts);
KVStore kvstore = KVStoreFactory.getStore(kconfig); 

The KVStoreConfig Class

The KVStoreConfig class is used to describe properties about a KVStore handle. Most of the properties are optional; those that are required are provided when you construct a class instance.

The properties that you can provide using KVStoreConfig are:

  • Consistency

    Consistency is a property that describes how likely it is that a record read from a replica node is identical to the same record stored on a master node. For more information, see Consistency Guarantees.

  • Durability

    Durability is a property that describes how likely it is that a write operation performed on the master node will not be lost if the master node is lost or is shutdown abnormally. For more information, see Durability Guarantees.

  • Helper Hosts

    Helper hosts are hostname/port pairs that identify where nodes within the store can be contacted. Multiple hosts can be identified using an array of strings. For example:

    String[] hhosts = {"n1.example.org:3333", "n2.example.org:3333"};
  • Request Timeout

    Configures the amount of time the KVStore handle will wait for an operation to complete before it times out.

  • Store name

    Identifies the name of the store.