# Package table

The code and scripts in this package demonstrate some of the basic functions of the Oracle NoSQL Database table API, including creation and use of secondary indexes.

See: Description

- Class Summary
  Class | Description
  --- | ---
  TableAPIExample | This file includes a number of examples that demonstrate some of the features of tables and secondary indexes in Oracle NoSQL Database.

## Package table Description

The code and scripts in this package demonstrate some of the basic functions of the Oracle NoSQL Database table API, including creation and use of secondary indexes.

All example Java code is in the single class `TableAPIExample`. There are a number of independent example functions in that class. These can be run together or independently. They have no interactions.

### Before Running the Table Examples

#### Start a Store

The examples require a running KVStore instance that has been populated with the example tables and indexes. A KVLite instance is suitable as a running store. These instructions assume that a default KVLite instance has been started using the command:

      java -jar lib/kvstore.jar kvlite

This creates a store named "kvstore" on localhost on port 5000. If you use another store or other parameters, adjust the instructions below accordingly. By default this creates a store in a new "kvroot" directory in your current directory. The location can be changed using additional parameters.

#### Create Tables and Indexes

This only needs to be done once for all examples. In the directory :

      java -jar lib/kvstore.jar runadmin -host localhost -port 5000 load -file \
         create_tables.kvs

This will take a minute or so.

### Building and Running Examples

#### Build the example code

In the directory /examples/table:

      javac -d . -cp /lib/kvclient.jar TableAPIExample.java

#### Run the example code

This only requires the client interface, in kvclient.jar. In the examples/table directory:

      java -cp .:/lib/kvclient.jar table.TableAPIExample     \
        [-host localhost] [-port 5000] [-store kvstore] [-example <1-9>]*

     All parameters have default values:
     store -- kvstore
     host -- localhost
     port -- 5000

By default all examples are run. More than one example can be run in a single invocation by using the -example flag multiple times.

### NOTES

Example 7 will show different results if the script evolve_table.kvs is run.

      java -jar lib/kvstore.jar runadmin -host localhost -port 5000 load -file \
         evolve_tables.kvs

After running the examples run the remove_tables.kvs script to clear the tables from the database. This removes all data as well.

      java -jar lib/kvstore.jar runadmin -host localhost -port 5000 load -file \
         remove_tables.kvs

Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.