Class NetricsRecFile

  • All Implemented Interfaces:
    java.io.Serializable

    public class NetricsRecFile
    extends java.lang.Object
    implements java.io.Serializable
    This class is used to specify a file of records read by the ibi™ Patterns - Search Server. The file must be located inside the server's loadable-data directory.

    File types currently supported are:
    CSV Excel format CSV files.
    Fixed Width Fixed width files.

    In both cases the files may start with an optional header line defining the field names, and/or an optional header line defining the field types. If both are given the field names must be given first.

    Record keys are defined in one of four ways:

    No key - no key is given in the file, keys are generated by the server.
    Leading key - an unnamed, untyped initial field in each data record provides the record key. This field does not appear in the header records, so data records will have one more field than the header records.
    Field Index - the index position (starting at 0) of the field containing the key is given. This field appears in all header records as well as data records, but this field is loaded as the record key and does not appear as a record data field.
    Field Name - the name of the field containing the key is given. If this method is used then the field names header record must be present. This is like Field Index in behavior.

    If you are loading records into a child table a field of the file can be specified as containing the parent key. This can be done either with the field name or the field index.

    The optional field types header line can use either the field type integer id (as defined in NetricsTable) or one of the following field type names. The names are not letter case sensitive, so may appear in either upper or lower case.
    attributes or attrs
    date
    datetime or datet
    double or float
    integer or int
    key
    parent-key or parent_key or parentkey
    searchtext or srchtext
    text


    All leading and trailing whitespace is ignored.

    Simple examples of each file type are given below. All file types except Field Index are shown with both header records. They are optional in all file types except Field Name where the Field Names header record is required.

    No Key
    first,middle,last,order
    5,5,5,INT
    William,Jefferson,Clinton,42
    George,W,Bush,43

    Leading Key
    first,middle,last,order
    srchtext,srchtext,srchtext,integer
    key1,William,Jefferson,Clinton,42
    key1,George,W,Bush,43

    Field Index (value 4)
    William,Jefferson,Clinton,42,key1
    George,W,Bush,43,key2

    Field Name(value key)
    first,middle,last,order,key
    SEARCHTEXT,SEARCHTEXT,SEARCHTEXT,INTEGER,KEY
    William,Jefferson,Clinton,42,key1
    key1,George,W,Bush,43,key2

    Loading Child records. Field Name(value key) Parent Field Name(value parent-key)
    key,first,middle,last,parent-key
    Key,5,5,5,ParentKey
    c1,Chelsea,Victoria,Clinton,key1
    c1,Jenna,Bush,Hager,key2
    c2,Barbara,Pierce,Bush,key2

    See Also:
    NetricsServerInterface.tblload(NetricsTable,NetricsRecFile), NetricsServerInterface.addRecsFromFile(String,boolean,NetricsRecFile), Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      NetricsRecFile​(java.lang.String fileName)
      Define a default CSV file record source.
      NetricsRecFile​(java.lang.String fileName, int keyIndex)
      Define a default CSV file record source.
      NetricsRecFile​(java.lang.String fileName, int[] fieldLengths, java.lang.String encoding, boolean doMaxWork, boolean leadingKey, int initialKey, boolean fieldNamesFirst, boolean fieldTypesFirst, int keyIndex, java.lang.String keyName)
      Define a Fixed Width file record source.
      NetricsRecFile​(java.lang.String fileName, java.lang.String encoding, boolean doMaxWork, boolean leadingKey, int initialKey, boolean fieldNamesFirst, boolean fieldTypesFirst, int keyIndex, java.lang.String keyName)
      Define a CSV file record source with attributes.
      NetricsRecFile​(java.lang.String fileName, java.lang.String encoding, boolean doMaxWork, boolean leadingKey, int initialKey, boolean fieldNamesFirst, boolean fieldTypesFirst, int keyIndex, java.lang.String keyName, int parentKeyIndex, java.lang.String parentKeyName)
      Define a CSV file record source with attributes.
      NetricsRecFile​(java.lang.String fileName, java.lang.String keyName, java.lang.String parentKeyName)
      Define a default CSV file record source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getDoMaxWork()
      Return the Do Max Work setting.
      java.lang.String getEncoding()
      Return the value of character encoding setting.
      boolean getFieldNamesFirst()
      Return the state of the field-names-first setting.
      boolean getFieldTypesFirst()
      Return the state of the field-types-first setting.
      java.lang.String getFileName()
      Return the source file name.
      int getInitialKey()
      Return the initial key setting.
      int getKeyIndex()
      Return the value of the key index.
      java.lang.String getKeyName()
      Return the value of the key name.
      boolean getLeadingKey()
      Return the leading key setting.
      int getParentKeyIndex()
      Return the value of the parent key index.
      java.lang.String getParentKeyName()
      Return the value of the parent key name.
      void setDoMaxWork​(boolean doMaxWork)
      Set the Do Max Work (ignore errors) setting.
      void setEncoding​(java.lang.String encoding)
      Set the character set encoding of the source file.
      void setFieldNamesFirst​(boolean fieldNamesFirst)
      Set the field names first flag.
      void setFieldTypesFirst​(boolean fieldTypesFirst)
      Set the state of the field-types-first flag.
      void setFileName​(java.lang.String fileName)
      Set the source file name.
      void setInitialKey​(int initialKey)
      Set the initial key value.
      void setKeyIndex​(int keyIndex)
      Set the key index value.
      void setKeyName​(java.lang.String keyName)
      Set the name of the field holding the record key.
      void setLeadingKey​(boolean leadingKey)
      Set the leading key.
      void setParentKeyIndex​(int parentKeyIndex)
      Set the parent key index value.
      void setParentKeyName​(java.lang.String parentKeyName)
      Set the name of the field holding the record parent key.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName)
                       throws NetricsException
        Define a default CSV file record source.

        This is the same as:
        NetricsRecFile(fileName,null,false,false,-1,true,false,-1,null)

        Parameters:
        fileName - The name of the file containing the records.
        Throws:
        NetricsException - never (declared for compatibility).
      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName,
                              java.lang.String keyName,
                              java.lang.String parentKeyName)
                       throws NetricsException
        Define a default CSV file record source.

        This is the same as:
        NetricsRecFile(fileName,null,false,false,-1,true,false,-1,keyName,-1,parentKeyName)

        Parameters:
        fileName - The name of the file containing the records.
        keyName - Specifies the name of the field that holds record key values in the file. Optional. If specified, the file must contain a field names header record and fieldNamesFirst must be true.
        parentKeyName - Specifies the name of the field that holds record parent key values in the file. Optional. If specified, the file must contain a field names header record and fieldNamesFirst must be true.
        Throws:
        NetricsException - never (declared for compatibility).
      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName,
                              int keyIndex)
                       throws NetricsException
        Define a default CSV file record source.

        This is the same as:
        NetricsRecFile(fileName,null,false,false,-1,true,false,keyIndex,null)

        Parameters:
        fileName - The name of the file containing the records.
        keyIndex - If this is non-negative it defines the index (0 based) of the key field in the file records.
        Throws:
        NetricsException - never (declared for compatibility).
      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName,
                              java.lang.String encoding,
                              boolean doMaxWork,
                              boolean leadingKey,
                              int initialKey,
                              boolean fieldNamesFirst,
                              boolean fieldTypesFirst,
                              int keyIndex,
                              java.lang.String keyName,
                              int parentKeyIndex,
                              java.lang.String parentKeyName)
                       throws NetricsException
        Define a CSV file record source with attributes.
        Parameters:
        fileName - The name of the file containing the records.
        encoding - This defines the character encoding used in the file. Currently supported encodings are: "UTF-8" or "LATIN1". DEFAULT: "LATIN1"
        doMaxWork - Ignore badly formatted records.
        leadingKey - This parameter is true if the file has the Leading Key format.
        initialKey - If the No Key format is used this defines the initial key value for the generated keys. If this is less than 0 the default value of 0 is used. Keys are sequential numbers starting at the initial key.
        fieldNamesFirst - If true the field names header line is present in the file.
        fieldTypesFirst - If true the field types header line is present in the file.
        keyIndex - If this is non-negative it defines the index (0 based) of the key field in the file records.
        keyName - If this is non-null it defines the name of the key field in the file records and the file must contain a field names header record and fieldNamesFirst must be true.
        parentKeyIndex - If this is non-negative it defines the index (0 based) of the parent key field in the file records.
        parentKeyName - If this is non-null it defines the name of the parent key field in the file records and the file must contain a field names header record and fieldNamesFirst must be true.
        Throws:
        NetricsException - If an invalid or illegal combination of values is given.
      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName,
                              java.lang.String encoding,
                              boolean doMaxWork,
                              boolean leadingKey,
                              int initialKey,
                              boolean fieldNamesFirst,
                              boolean fieldTypesFirst,
                              int keyIndex,
                              java.lang.String keyName)
                       throws NetricsException
        Define a CSV file record source with attributes.

        Parameters:
        fileName - The name of the file containing the records.
        encoding - This defines the character encoding used in the file. Currently supported encodings are: "UTF-8" or "LATIN1". DEFAULT: "LATIN1"
        doMaxWork - Ignore badly formatted records.
        leadingKey - This parameter is true if the file has the Leading Key format.
        initialKey - If the No Key format is used this defines the initial key value for the generated keys. If this is less than 0 the default value of 0 is used. Keys are sequential numbers starting at the initial key.
        fieldNamesFirst - If true the field names header line is present in the file.
        fieldTypesFirst - If true the field types header line is present in the file.
        keyIndex - If this is non-negative it defines the index (0 based) of the key field in the file records.
        keyName - If this is non-null it defines the name of the key field in the file records and the file must contain a field names header record and fieldNamesFirst must be true.
        Throws:
        NetricsException - If an invalid or illegal combination of values is given.
      • NetricsRecFile

        public NetricsRecFile​(java.lang.String fileName,
                              int[] fieldLengths,
                              java.lang.String encoding,
                              boolean doMaxWork,
                              boolean leadingKey,
                              int initialKey,
                              boolean fieldNamesFirst,
                              boolean fieldTypesFirst,
                              int keyIndex,
                              java.lang.String keyName)
                       throws NetricsException
        Define a Fixed Width file record source.
        Parameters:
        fileName - The name of the file containing the records.
        fieldLengths - This array contains the field widths in characters. The length of the array must be the same as the number of fields in the record, including and key field, even if it is a leading key field.
        encoding - This defines the character encoding used in the file. Currently supported encodings are: "UTF-8" or "LATIN1". DEFAULT: "LATIN1"
        doMaxWork - Ignore badly formatted records.
        leadingKey - This parameter is true if the file has the Leading Key format.
        initialKey - If the No Key format is used this defines the initial key value for the generated keys. If this is less than 0 the default value of 0 is used. Keys are sequential numbers starting at the initial key.
        fieldNamesFirst - If true the field names header line is present in the file.
        fieldTypesFirst - If true the field types header line is present in the file.
        keyIndex - If this is non-negative it defines the index (0 based) of the key field in the file records.
        keyName - If this is non-null it defines the name of the key field in the file records and the file must contain a field names header record and fieldNamesFirst must be true.
        Throws:
        NetricsException - If an invalid or illegal combination of values is given.
    • Method Detail

      • getFileName

        public java.lang.String getFileName()
        Return the source file name. Returns the CSV or Fixed width file name. Null if it was not set.
        Returns:
        the source file name.
      • setFileName

        public void setFileName​(java.lang.String fileName)
        Set the source file name. Sets the name of the source file for either CSV or fixed width files.
        Parameters:
        fileName - the name of a CSV or fixed-width file.
      • getEncoding

        public java.lang.String getEncoding()
        Return the value of character encoding setting. Returns the character encoding. Null if it was not set.
        Returns:
        the value of character encoding setting.
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
        Set the character set encoding of the source file.
        Parameters:
        encoding - a character set encoding name.
      • getDoMaxWork

        public boolean getDoMaxWork()
        Return the Do Max Work setting. Returns false if it was never set.
        Returns:
        the Do Max Work setting.
      • setDoMaxWork

        public void setDoMaxWork​(boolean doMaxWork)
        Set the Do Max Work (ignore errors) setting.
        Parameters:
        doMaxWork - true to ignore badly formatted records.
      • getLeadingKey

        public boolean getLeadingKey()
        Return the leading key setting. Returns false if it was never set.
        Returns:
        the leading key setting.
      • setLeadingKey

        public void setLeadingKey​(boolean leadingKey)
        Set the leading key.
        Parameters:
        leadingKey - pass true if the file has the Leading Key format.
      • getInitialKey

        public int getInitialKey()
        Return the initial key setting. Returns the initial key setting. -1 if initial key was not set.
        Returns:
        the initial key setting.
      • getKeyIndex

        public int getKeyIndex()
        Return the value of the key index. Returns the key index setting. -1 if key index was not set.
        Returns:
        the value of the key index.
      • setKeyIndex

        public void setKeyIndex​(int keyIndex)
        Set the key index value. This sets the index of the field (zero based) to be used as the record key. Use -1 to indicate the key field is not specified.
        Parameters:
        keyIndex - new value of the key index.
        Throws:
        java.lang.IllegalStateException - thrown if key is already specified by name
      • getKeyName

        public java.lang.String getKeyName()
        Return the value of the key name. Returns the key name setting. Null if key name was not set.
        Returns:
        the value of the key name.
      • setKeyName

        public void setKeyName​(java.lang.String keyName)
        Set the name of the field holding the record key. This sets the name of the field to be used as the record key. Use null to indicate the key field is not specified.
        Parameters:
        keyName - new value for the key name.
        Throws:
        java.lang.IllegalStateException - thrown if key is already specified by index
      • getParentKeyIndex

        public int getParentKeyIndex()
        Return the value of the parent key index. Returns the parent key index setting. -1 if parent key index was not set.
        Returns:
        the value of the parent key index.
      • setParentKeyIndex

        public void setParentKeyIndex​(int parentKeyIndex)
        Set the parent key index value. This sets the index of the field (zero based) to be used as the record parent key. Use -1 to indicate the parent key field is not specified.
        Parameters:
        parentKeyIndex - new value of the parent key index.
        Throws:
        java.lang.IllegalStateException - thrown if parent key is already specified by name
      • getParentKeyName

        public java.lang.String getParentKeyName()
        Return the value of the parent key name. Returns the parent key name setting. Null if parent key name was not set.
        Returns:
        the value of the parent key name.
      • setParentKeyName

        public void setParentKeyName​(java.lang.String parentKeyName)
        Set the name of the field holding the record parent key. This sets the name of the field to be used as the record parent key. Use null to indicate the parent key field is not specified.
        Parameters:
        parentKeyName - new value of the parent key name.
        Throws:
        java.lang.IllegalStateException - thrown if parent key is already specified by index
      • getFieldNamesFirst

        public boolean getFieldNamesFirst()
        Return the state of the field-names-first setting.
        Returns:
        the field-names-first setting.
      • setFieldNamesFirst

        public void setFieldNamesFirst​(boolean fieldNamesFirst)
        Set the field names first flag. If true is given the first line of the file is used as the field names.
        Parameters:
        fieldNamesFirst - new value for the field-names-first flag.
      • getFieldTypesFirst

        public boolean getFieldTypesFirst()
        Return the state of the field-types-first setting.
        Returns:
        the field-types-first setting.
      • setFieldTypesFirst

        public void setFieldTypesFirst​(boolean fieldTypesFirst)
        Set the state of the field-types-first flag. If this is true the first line of the file (after any field names) contains the integer values of the field types.
        Parameters:
        fieldTypesFirst - new value for the field-types-first flag.