com.h3c.util.persistence.cassandra.index

## Class AllRowsSecondaryIndex<C extends Serializable & Comparable<C>,D>

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

- Type Parameters:
    `C` - type of the row key in the main column family. Such row key will be the column name in the secondary index column.
    `D` - type of the denormalized data to set as the value in the indexed columns.
  All Implemented Interfaces:
    ColumnFamilyHandler

      public class AllRowsSecondaryIndex<C extends Serializable & Comparable<C>,D>
      extends Object
      implements ColumnFamilyHandler

  Custom secondary index column family to keep all rows from another column family (or main column family) as columns in a wide row so they are counted and paged.

  All Rows Secondary Index Column Family:

  - Row key (Key validation: String): Single row with a well-known key.
  - Column value (default validation: Bytes): Denormalized data.
  - Column name (comparator: row key in the main column family or composite value when sorting information is included): The row key in the main column family. For each row there will be a an entry in the columns to keep the row key.

       column_family_name {
           "rows": {
               id_1: <data provided by the denormalizer>,
               ...
               id_n: <data provided by the denormalizer>,
           }
       }

  See `IndexEntryHandler` for a recipe to update secondary indexes.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AllRowsSecondaryIndex(String columnFamilyName, CassDataTypes indexedColumnNameDataType, com.netflix.astyanax.Serializer<C> indexedColumnNameSerializer, Denormalizer<C,D> denormalizer)` Creates a custom secondary index.

  - ### 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(DataStoreContext context)` Counts all the rows in the main column family or the number of columns in the index column family.
    `void` | `delete(C indexEntry, DataStoreContext context)` Updates the index after a row has been deleted from the main column family.
    `Collection<ColumnFamilyDefinition<?,?>>` | `getColumnFamilyDefinitions()` Gets the definition of all column families this handler reads from and writes into.
    `void` | `insert(C indexEntry, D denormalizedData, DataStoreContext context)` Updates the index after a row has been inserted into the main column family.
    `List<Column<C,D>>` | `read(DataStoreContext context)` Reads the index entries.
    `List<Column<C,D>>` | `read(List<C> indexEntries, 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

    - #### AllRowsSecondaryIndex

          public AllRowsSecondaryIndex(String columnFamilyName,
                               CassDataTypes indexedColumnNameDataType,
                               com.netflix.astyanax.Serializer<C> indexedColumnNameSerializer,
                               Denormalizer<C,D> denormalizer)

      Creates a custom secondary index.
      Parameters:
        `columnFamilyName` - name for the column family this index will keep data into.
        `indexedColumnNameDataType` - type of the secondary index column name.
        `indexedColumnNameSerializer` - secondary index column name serializer.
        `denormalizer` - strategy to handle denormalized data included as part of the indexed columns. `null` if no denormalization will be used.

  - ### 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,
                    DataStoreContext context)

      Updates the index after a row has been inserted into the main column family.
      Parameters:
        `indexEntry` - key of the row inserted in the main column family.
        `denormalizedData` - denormalized data to include as part of the indexed columns. `null` if no denormalization is used. Note: A `Denormalizer` must be set at construction time to handle `denormalizedData` if it is not null.
        `context` - data store context.

    - #### delete

          public void delete(C indexEntry,
                    DataStoreContext context)

      Updates the index after a row has been deleted from the main column family.
      Parameters:
        `indexEntry` - key of the row removed from the main column family.
        `context` - data store context.

    - #### clear

          public void clear(DataStoreContext context)

      Updates the index after deleting all rows from the main column family.
      Parameters:
        `context` - data store context.

    - #### count

          public long count(DataStoreContext context)

      Counts all the rows in the main column family or the number of columns in the index column family.
      Parameters:
        `context` - data store context.
      Returns:
        the number of rows in the main column family or the number of columns in the index column family.

    - #### read

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

      Reads the index entries.

      Note that it is simpler to read the entire main column family. This method just guarantees sorting by row key but then the rows will need to be loaded from the main column family.

      Parameters:
        `context` - data store context.
      Returns:
        the list of indexed columns with the denormalized data.

    - #### read

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

      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`.

      Parameters:
        `indexEntries` - index entries to read.
        `context` - data store context.
      Returns:
        the list of indexed columns with the denormalized data. Any index entry from `indexEntries` that doesn't exist is not included in the result.

Copyright © 2014. All Rights Reserved.