com.h3c.util.persistence.cassandra.index

## Class GenericCustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>

- java.lang.Object
- - com.h3c.util.persistence.cassandra.index.GenericCustomSecondaryIndex<K,C,D>

- Type Parameters:
    `K` - type of the value (or composite values) of the indexed column (or columns) in the main column family. This value (or composite value) will become the row key in the secondary index column.
    `C` - type of the column name in the secondary index column family (row key in the main column family or composite value when sorting information is included).
    `D` - type of the denormalized data to set as the value in the indexed columns.
  All Implemented Interfaces:
    ColumnFamilyHandler, CustomSecondaryIndex<K,C,D>

      public class GenericCustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>
      extends Object
      implements CustomSecondaryIndex<K,C,D>

  Generic implementation of `CustomSecondaryIndex`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericCustomSecondaryIndex(ColumnFamilyDefinition<K,C> columnFamilyDefinition, Denormalizer<C,D> denormalizer)` Creates a `CustomSecondaryIndex`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear(DataStoreContext context)` Updates the index after deleting all rows from the main column family.
    `long` | `count(K indexKey, DataStoreContext context)` Counts the number of columns in the index.
    `void` | `delete(C indexEntry, K indexKey, DataStoreContext context)` Updates the index after a row has been deleted from the main column family.
    `void` | `delete(K indexKey, DataStoreContext context)` Deletes a row in the secondary index column family.
    `Collection<ColumnFamilyDefinition<?,?>>` | `getColumnFamilyDefinitions()` Gets the definition of all column families this handler reads from and writes into.
    `Provider<ColumnDecoder<C,?>,ColumnName<C,?>>` | `getDecoderProvider()` Returns the decoder provided used to read from the secondary index column family.
    `void` | `insert(C indexEntry, D denormalizedData, K indexKey, DataStoreContext context)` Updates the index after a row has been inserted into the main column family.
    `List<Column<C,D>>` | `read(K indexKey, DataStoreContext context)` Reads the index entries.
    `List<Column<C,D>>` | `read(List<C> indexEntries, K indexKey, DataStoreContext context)` Reads the index entries.

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

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

- - ### Constructor Detail

    - #### GenericCustomSecondaryIndex

          public GenericCustomSecondaryIndex(ColumnFamilyDefinition<K,C> columnFamilyDefinition,
                                     Denormalizer<C,D> denormalizer)

      Creates a `CustomSecondaryIndex`.
      Parameters:
        `columnFamilyDefinition` - column family this index will keep data into.
        `denormalizer` - strategy to handle denormalized data included as part of the indexed columns. `null` if no denormalization will be used. Note: If denormalization is used but a `Denormalizer` is not set then exceptions will be thrown when reading from the index.

  - ### Method Detail

    - #### getColumnFamilyDefinitions

          public Collection<ColumnFamilyDefinition<?,?>> getColumnFamilyDefinitions()

      Description copied from interface: `ColumnFamilyHandler`
      Gets the definition of all column families this handler reads from and writes into.
      Specified by:
        `getColumnFamilyDefinitions` in interface `ColumnFamilyHandler`
      Returns:
        column family definitions.

    - #### insert

          public void insert(C indexEntry,
                    D denormalizedData,
                    K indexKey,
                    DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Updates the index after a row has been inserted into the main column family.
      Specified by:
        `insert` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexEntry` - row key in the main column family (or composite value when sorting information is included). Such row key (or composite value) will become the name of the column in the secondary index.
        `denormalizedData` - denormalized data to include as part of the indexed columns. `null` if no denormalization is used.
        `indexKey` - value (or composite values) of the indexed column (or columns) in the main column family. This value (or composite value) will become the row key in the secondary index column.
        `context` - data store context.

    - #### delete

          public void delete(C indexEntry,
                    K indexKey,
                    DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Updates the index after a row has been deleted from the main column family.
      Specified by:
        `delete` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexEntry` - key of the row removed from the main column family.
        `indexKey` - value of the indexed column in the main column family.
        `context` - data store context.

    - #### delete

          public void delete(K indexKey,
                    DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Deletes a row in the secondary index column family.

      This method should be the preferred way to clear a secondary index if it contains a small well-know set of rows. Truncating a column family is an expensive operation.

      Specified by:
        `delete` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexKey` - value of the indexed column in the main column family.
        `context` - data store context.

    - #### clear

          public void clear(DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Updates the index after deleting all rows from the main column family.
      Specified by:
        `clear` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `context` - data store context.

    - #### count

          public long count(K indexKey,
                   DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Counts the number of columns in the index.
      Specified by:
        `count` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexKey` - value of the indexed column in the main column family or row key in the secondary index column family.
        `context` - data store context.
      Returns:
        the number of entries in the index key.

    - #### read

          public List<Column<C,D>> read(K indexKey,
                               DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Reads the index entries.
      Specified by:
        `read` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexKey` - value of the indexed column in the main column family or row key in the secondary index column family.
        `context` - data store context.
      Returns:
        the list of indexed columns with the denormalized data.

    - #### read

          public List<Column<C,D>> read(List<C> indexEntries,
                               K indexKey,
                               DataStoreContext context)

      Description copied from interface: `CustomSecondaryIndex`
      Reads the index entries.

      An index is normally used to get rows (from the main column family) that match a specific indexed value, not to load entries known to match the indexed value - like in this method. This method has been defined to allow secondary indexes to be used by a `SecondaryIndexIntegrator.SecondaryIndexReader`.

      Specified by:
        `read` in interface `CustomSecondaryIndex<K extends Serializable,C extends Serializable & Comparable<C>,D>`
      Parameters:
        `indexEntries` - index entries to read.
        `indexKey` - value of the indexed column in the main column family or row key in the secondary index column family.
        `context` - data store context.
      Returns:
        the list of indexed columns with the denormalized data. Any index entry from `indexEntries` that doesn't exist in the index given by `indexKey` is not included in the result.

    - #### getDecoderProvider

          public Provider<ColumnDecoder<C,?>,ColumnName<C,?>> getDecoderProvider()

      Returns the decoder provided used to read from the secondary index column family.
      Returns:
        decoder provider.

Copyright © 2014. All Rights Reserved.