secondaryindex

## Class IndexViewExample

- java.lang.Object
- - secondaryindex.IndexViewExample

-     public class IndexViewExample
      extends Object

  This is the "main" class for the IndexView example and implements all of the command line argument parsing and dispatch.

  IndexViewExample has 8 major commands:

  1. -loaddata Loads all records from a data file, parses them into KV Pairs using an avro-binding and stores the results into the "primary DB". For example,

          IndexViewExample -loaddata -file <dir_data_file> ...

     The <-file> argument is used to specify the path of data file. When the load is completed the count of records is output.

  2. -buildindex builds secondary indexes on the specified fields for all KV Pairs in the primary DB. For example,

          IndexViewExample -buildindex -name <field_name> ...

     This command also supports building multi-column indexes. For example,

          IndexViewExample -buildindex -name <field_name1>,<field_name2>,...

  3. -dropindex drops secondary indexes on the specified fields in the Index View. For example,

          IndexViewExample -dropindex -name <field_name>

     This command also supports dropping multi-column indexes. For example,

          IndexViewExample -dropindex -name <field_name1>,<field_name2>,...

  4. -insert inserts a record into the primary DB with corresponding record(s) into the Index View. For example,

          IndexViewExample -insert -key <primary_key_value> -value
          <field_name1>=<field_value1>, <field_name2>=<field_value2>,...

     The <-key> argument must be set to the value of primary key field -- "id" in this particular example -- which is the unique identifier of a BillInfo record. Any BillInfo fields that are not specified are set to their default values.

  5. -update updates one or more records in the primary DB as well as the corresponding Index View records. For example,

          IndexViewExample -update -key <primary_key_value> -value
          <field_name1>=<field_value1>, <field_name2>=<field_value2>,...

     This command also supports updating multi-column indexes. For example,

          IndexViewExample -update -seckey <field_name1>=<field_value1>,
          <field_name2>=<field_value2>,... -value <field_name1>=<field_value1>,
          <field_name2>=<field_value2>,...

     All primary DB records that are located using the given Index View key are updated.

  6. -delete deletes records in primary DB as well as their corresponding secondary index records.

          IndexViewExample -delete -key <primary_key_value>

     This command also supports deletion using multi-column indexes. For example,

          IndexViewExample -delete -seckey <field_name1>=<field_value1>,
          <field_name2>=<field_value2>,...

  7. -query queries records in the primary DB using one more Index Views. For example,

          IndexViewExample -query -seckey <field_name1>=<field_value1>,
          <field_name2>=<field_value2>,...

     This command performs the query using both the Index View and a scan of all primary DB records. The wall clock to perform both operations is output.

  8. -showindex outputs the field names, schema name and current status of all Index Views in the store.

          IndexViewExample -showindex

     To run the example, start a KVStore instance. A simple way is to run KVLite as described in the Oracle NoSQL Database Installation 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). Start the admin CLI as described in the Oracle NoSQL Database Administrator's Guide. Then enter the following commands to add the example schema:

          kv-> ddl add-schema -file billinfo-schema.avsc

     After adding the schema, use the KVStore instance name, host and port for running the example. e.g. in a -loaddata command:

          IndexViewExample -loaddata -host <host_name default: localhost> -port
          <port default: 5000> -store <store_name default: kvstore>

     In this package the default data file is "example_data.csv" which has 4000 records. If more data is required, use the "datagenerator" tool to generate more. For more information, see http://www.generatedata.com.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `(package private) class` | `IndexViewExample.ExecutorParser` Parses command line arguments.
    `(package private) static class` | `IndexViewExample.Operation`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IndexViewExample()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) void` | `buildIndexes()` Builds Index View(s) for the fields supplied on the command line.
    `(package private) void` | `deleteRecord()` Deletes record(s) in the primary DB and any related Index View record(s).
    `(package private) void` | `dropIndexes()` Drops Index View(s) on the fields supplied on the command line.
    `(package private) void` | `handle(IndexViewExample.Operation operation)`
    `(package private) void` | `init(String[] argv)`
    `(package private) void` | `insertRecord()` Inserts a record into primary DB and creates Index View record(s).
    `(package private) void` | `loadData()` Loads records.
    `static void` | `main(String[] argv)`
    `(package private) void` | `queryRecord()` Retrieves the primary DB record(s) associated with the Index View key argument(s).
    `(package private) void` | `runExample(String[] argv)`
    `(package private) void` | `showIndex()` Outputs field names, schema name and current status of all Index Views in Oracle NoSQL Database.
    `(package private) void` | `updateRecord()` Updates records in the primary DB and any related Index View record(s).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### IndexViewExample

          public IndexViewExample()

  - ### Method Detail

    - #### init

          void init(String[] argv)

    - #### handle

          void handle(IndexViewExample.Operation operation)

    - #### loadData

          void loadData()
                  throws IOException

      Loads records. A record is a String containing BillInfo field values with a fixed order. All field values in the input file are separated by semicolons.
      Throws:
        `IOException`

    - #### buildIndexes

          void buildIndexes()

      Builds Index View(s) for the fields supplied on the command line.

    - #### dropIndexes

          void dropIndexes()

      Drops Index View(s) on the fields supplied on the command line.

    - #### insertRecord

          void insertRecord()

      Inserts a record into primary DB and creates Index View record(s).

    - #### updateRecord

          void updateRecord()

      Updates records in the primary DB and any related Index View record(s).

    - #### deleteRecord

          void deleteRecord()

      Deletes record(s) in the primary DB and any related Index View record(s).

    - #### queryRecord

          void queryRecord()

      Retrieves the primary DB record(s) associated with the Index View key argument(s). In order to compare the query performance with and without Index Views, this function outputs the elapsed time for both cases.

    - #### showIndex

          void showIndex()

      Outputs field names, schema name and current status of all Index Views in Oracle NoSQL Database.

    - #### runExample

          void runExample(String[] argv)

    - #### main

          public static void main(String[] argv)

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