public class SchemaExample extends Object
To understand this example, start by reading the KeyDefinition
class comments. These comments explain the overall
schema, key types and data object types. Then come back and
continue reading this class.
Since this example uses an Avro binding, the Avro and Jackson jars must be in the classpath, as well as the kvclient jar. The Avro and Jackson jars are included in the KVHOME/lib directory along with the kvclient jar:
kvclient.jar avro.jar jackson-core-asl.jar jackson-mapper-asl.jar
As long as all four jars are in the same directory, only the kvclient jar needs to be specified in the classpath, because the kvclient jar references the other three jars. If they are not in the same directory, all four jars must be explicitly specified in the classpath.
To build this example in the examples/avro directory:
cd KVHOME/examples/schema mkdir classes javac -cp KVHOME/lib/kvclient.jar -d classes *.java
Before running this example program, start a KVStore instance. The simplest way to do that is to run KV Lite as described in the Quickstart document.
After starting the KVStore instance, the Avro schemas used by the example must be added to the store using the administration command line interface (CLI). First start the admin CLI as described in the Oracle NoSQL Database Administrator's Guide. Then enter the following commands to add the example schemas:
ddl add-schema -file user-info.avsc ddl add-schema -file user-image.avsc ddl add-schema -file login-session.avsc ddl add-schema -file login-summary.avsc
After adding the schema, use the KVStore instance name, host and port for running this program, as follows:
java schema.SchemaExample -store <instance name> \ -host <host name> \ -port <port number>
For all examples the default instance name is kvstore, the default host name is localhost and the default port number is 5000. These defaults match the defaults for the run-kvlite.sh script, so the simplest way to run the examples along with kvlite is to omit all parameters.
When running this program, the Java classpath must include the kvclient.jar and the example 'classes' directory. The .avsc files must also be found as resources in the classpath, which can be accomplished by adding the 'examples' directory to the classpath or by copying the .avsc files to the 'classes/schema' directory.
This program adds a fixed set of Key/Value pairs to the store and then performs queries and prints the results of the queries. It is not interactive.
This program is a usage example and is not intended to be used directly for performance testing. The methods that access the store make some assumptions that access is single-client and single-threaded. However, the schema approach -- the key structure, object definitions and object serialization -- is intended to scale up and is an example of a design for a large data set with stringent performance requirements.
WARNING: To create a performance test, a multi-client multi-threaded client approach will be necessary to avoid limiting throughput at the client side. This example program is not designed for that type of testing.
Constructor and Description |
---|
SchemaExample(String[] argv)
Parses command line args and opens the KVStore.
|
Modifier and Type | Method and Description |
---|---|
static void |
main(String[] args)
Runs the SchemaExample command line program.
|
(package private) void |
runExample()
Performs example operations and closes the KVStore.
|
Copyright (c) 2011, 2015 Oracle and/or its affiliates. All rights reserved.