Package com.netrics.likeit

## Class NetricsCompoundReader

- java.lang.Object
- - com.netrics.likeit.NetricsCompoundReader

- All Implemented Interfaces:
    `NetricsBaseRecSrc`, `NetricsCompoundRecSrc`

      public class NetricsCompoundReader
      extends java.lang.Object
      implements NetricsCompoundRecSrc

  Read compound records from a set of record sources.

  Objects of this class provide a means of reading in compound records. A compound record is a parent record along with a set of zero or more child records. It may also be an orphan child record. This class builds compound records from a set of record sources. One source represents the parent table, zero or more additional sources represent the child tables. Each source is associated with a table name, all table names must be unique.

  To build compound records it is assumed that all sources are sorted by the parent record key. The child record sources are not sorted by their own key, they must be sorted by the parent record key. In this way the sources can be read in parallel and merged.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `NetricsCompoundReader​(java.lang.String parent_tbl_name, NetricsRecSrc parent_recs, boolean return_orphans)` | Create a compound record reader.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addChildTable​(java.lang.String child_tbl_name, NetricsRecSrc child_recs)` | add a new child table to this compound record reader.
    `java.util.List<java.lang.String>` | `getChildTables()` | return a list of child table names used.
    `NetricsCompoundRecord` | `getNext()` | return the next record.
    `java.lang.String` | `getParentTable()` |
    `int` | `getPosition()` |
    `boolean` | `hasNext()` | Implement the hasNext method.
    `void` | `reset()` | Implement the reset method.

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

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

- - ### Constructor Detail

    - #### NetricsCompoundReader

          public NetricsCompoundReader​(java.lang.String parent_tbl_name,
                                       NetricsRecSrc parent_recs,
                                       boolean return_orphans)
                                throws java.lang.IllegalArgumentException,
                                       NetricsRecSrcException

      Create a compound record reader. This creates a compound record reader. It is created with a single parent table. Child tables must be added using the addChildTable method.
      Parameters:
        `parent_tbl_name` - the name of the parent table.
        `parent_recs` - a record source that provides parent records. The records MUST be provided in sort order of the record keys.
        `return_orphans` - if this is true orphan child records are returned as a NetricsCompoundRecord with no children. If this is false orphan child records are quietly skipped.
      Throws:
        `java.lang.IllegalArgumentException` - if any argument is null or the parent table name is empty (zero length).
        `NetricsRecSrcException` - if there is an error reading the first parent record.

  - ### Method Detail

    - #### addChildTable

          public void addChildTable​(java.lang.String child_tbl_name,
                                    NetricsRecSrc child_recs)
                             throws java.lang.IllegalArgumentException,
                                    NetricsRecSrcException

      add a new child table to this compound record reader. This is used to add a child table to this compound record reader. This call should be made before any records are read, but this is not enforced.
      Parameters:
        `child_tbl_name` - the name of the child table. This must not be the same as the name of the parent table or any existing child table.
        `child_recs` - this is the source of child records. The records returned by this source should be child records. The records must be returned in sort order of the parent key.
      Throws:
        `java.lang.IllegalArgumentException` - if either argument is null, the table name is zero length, the table name is the same as the parent table or an existing child table.
        `NetricsRecSrcException` - if there is an error reading the first record.

    - #### getNext

          public NetricsCompoundRecord getNext()
                                        throws NetricsRecSrcException

      return the next record.
      Specified by:
        `getNext` in interface `NetricsBaseRecSrc`
      Specified by:
        `getNext` in interface `NetricsCompoundRecSrc`
      Returns:
        the next record, null if no more records.
      Throws:
        `NetricsRecSrcException` - if there is an error on any of the underlying readers when reading the next record.

    - #### hasNext

          public boolean hasNext()
                          throws NetricsRecSrcException

      Implement the hasNext method.
      Specified by:
        `hasNext` in interface `NetricsBaseRecSrc`
      Returns:
        True if there is another record, false otherwise
      Throws:
        `NetricsRecSrcException` - if an error occurs.

    - #### reset

          public void reset()
                     throws NetricsRecSrcException

      Implement the reset method.
      Specified by:
        `reset` in interface `NetricsBaseRecSrc`
      Throws:
        `NetricsRecSrcException` - if an error occurs, or if the record source does not support resetting.

    - #### getPosition

          public int getPosition()

      Returns:
        an indicator of the current position in the scan.

    - #### getParentTable

          public java.lang.String getParentTable()

      Specified by:
        `getParentTable` in interface `NetricsCompoundRecSrc`
      Returns:
        the parent/primary table name for the compound record.

    - #### getChildTables

          public java.util.List<java.lang.String> getChildTables()

      Description copied from interface: `NetricsCompoundRecSrc`
      return a list of child table names used. This list represents all possible child tables. Any particular compound record returned may not contain child records for all of these tables.
      Specified by:
        `getChildTables` in interface `NetricsCompoundRecSrc`
      Returns:
        the list of child table names.