Class Recordset

java.lang.Object
ch.ivyteam.ivy.scripting.objects.NestedObject
ch.ivyteam.ivy.scripting.objects.Recordset
All Implemented Interfaces:
IIvyDataObject, Serializable, Cloneable

public final class Recordset extends NestedObject
A Recordset is a data structure corresponding to a table from a a database.
See Also:
API:
This is a public API.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new uninitialized recordset.
    Recordset(List<String> columns, List<List<Object>> rows)
    Creates a Recordset with the given columns and rows.
    This constructor does not create a clone of the given column and rows and has to be used carefully.
    Recordset(String[] _keys)
    Creates a new empty Recordset with given columns.
    Creates a new empty Recordset with given columns.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Transforms the argument to a Record and add it into the recordset.
    void
    add(List<?> row)
    Adds a copy of a record as last row.
    void
    add(Record record)
    Adds a copy of a record as last row.
    void
    addAll(Recordset recordset)
    Adds records from another Recordset to this Recordset.
    void
    addAll(List<?> newRecords)
    Adds records to this Recordset.
    void
    addColumn(String columnName, List<?> values)
    Appends a column into the recordset.
    void
    Removes all Records from this Recordset.
    Clones this recordset.
    int
    Returns the number of columns.
    Creates a deep clone.
    void
    elementChangedAt(int rowIndex, int columnIndex)
    Informs the listeners that an element was replaced or has changed.
    getAt(int row)
    Returns a specified (copy of a) record contained in this recordset.
    getColumn(String columnName)
    Returns a column.
    int
    getColumnIndex(String columnName)
    Gets the index of the column with the given column name.
    getField(int row, int column)
    Returns a specified field value of this recordset.
    getField(int row, String column)
    Returns a specified field value of this recordset.
    Returns a List with the keys of the column-names.
    Returns a List with the Records in this Recordset.
    int
    indexOf(List<?> record)
    Returns the first index of a Record in this Recordset.
    int
    indexOf(Record record)
    Returns the first index of a Record in this Recordset.
    void
    insertAllAt(int index, List<?> newRecords)
    Inserts records into this Recordset.
    void
    insertAllAt(int index, Recordset recordset)
    Adds records from another Recordset to this Recordset.
    void
    insertAt(int index, CompositeObject record)
    Inserts a new record at a given index.
    void
    insertAt(int index, List<?> record)
    Inserts a copy of the argument list as a new row at the given index in this recordset.
    void
    insertAt(int index, Record record)
    Inserts a record at a given index.
    void
    insertColumn(int index, String columnName, List<?> values)
    Inserts a column into the recordset.
    int
    lastIndexOf(List<?> record)
    Returns the last index of a Record in this Recordset.
    int
    Returns the last index of a Record in this Recordset.
    void
    putField(int row, String column, Object newValue)
    Set a specified field value in this recordset.
    void
    remove(List<Object> record)
    Removes a Record, given as a List of values, from this Recordset.
    void
    remove(Record record)
    Removes a Record from this Recordset.
    void
    removeAt(int index)
    Removes a Record from this Recordset.
    int
    Returns the number of Records in this Recordset.
    void
    sort(String colName)
    Sorts the recordset by a column in ascending order.
    void
    sortDesc(String colName)
    Sorts the recordset by a column in descending order.
    Converts this Recordset into a List of Records
    <T> List<T>
    toList(Class<T> dataClass)
    Converts this Recordset into a list of objects of type <T>.
    Converts this Recordset into a List of List
    toTree(String keyField, String parentKeyField)
    Creates a new tree from data of this recordset.
    toTree(String keyField, String parentKeyField, String valueField)
    Creates a new tree from data of this recordset.
    toTree(String keyField, String parentKeyField, String valueField, String infoField)
    Creates a new tree from data of this recordset.
    toTreeConstInfo(String keyField, String parentKeyField, String valueField, String info)
    Creates a new tree from data of this recordset.

    Methods inherited from class ch.ivyteam.ivy.scripting.objects.NestedObject

    equals, hashCode, toString
  • Constructor Details

    • Recordset

      public Recordset()
      Creates a new uninitialized recordset.
      API:
      This public API is available in Java.
    • Recordset

      public Recordset(String[] _keys)
      Creates a new empty Recordset with given columns.
      Parameters:
      _keys - The column-names for the Recordset.
      API:
      This public API is available in Java.
    • Recordset

      public Recordset(List<String> _keys)
      Creates a new empty Recordset with given columns.
      Parameters:
      _keys - The column-names for the Recordset.
      API:
      This public API is available in Java.
    • Recordset

      public Recordset(List<String> columns, List<List<Object>> rows)
      Creates a Recordset with the given columns and rows.
      This constructor does not create a clone of the given column and rows and has to be used carefully. It is not allowed to change the given column or rows after the recordset was created.
      Parameters:
      columns - List of column names
      rows - Rows to ad. Not null.
      Throws:
      IllegalArgumentException - If the column count of a row does not match with the column count.
      API:
      This public API is available in Java.
  • Method Details

    • getAt

      public Record getAt(int row)
      Returns a specified (copy of a) record contained in this recordset.
      Parameters:
      row - The index of the required record.
      Returns:
      A copy of the record with the specified index.
      API:
      This public API is available in Java.
    • getField

      public Object getField(int row, String column) throws IllegalArgumentException, IndexOutOfBoundsException
      Returns a specified field value of this recordset.
      Parameters:
      row - The row number of the required field.
      column - The column name of the required field.
      Returns:
      the value of the field at the specified row index and column name.
      Throws:
      IllegalArgumentException - If column name does not exist
      IndexOutOfBoundsException - If column or row does not exist
      API:
      This public API is available in Java.
    • getColumnIndex

      public int getColumnIndex(String columnName)
      Gets the index of the column with the given column name.
      Parameters:
      columnName - a name of a column
      Returns:
      the index of the column with the given name
      API:
      This public API is available in Java.
    • getField

      public Object getField(int row, int column) throws IndexOutOfBoundsException
      Returns a specified field value of this recordset.
      Parameters:
      row - The row number of the required field.
      column - The column index of the required field.
      Returns:
      the value of the field at the specified indices.
      Throws:
      IndexOutOfBoundsException - If column or row does not exist
      API:
      This public API is available in Java.
    • putField

      public void putField(int row, String column, Object newValue) throws IllegalArgumentException
      Set a specified field value in this recordset.
      Parameters:
      row - The row number of the required field.
      column - The column name of the required field.
      newValue - The new value for the specified field.
      Throws:
      IllegalArgumentException
      API:
      This public API is available in Java.
    • size

      public int size()
      Returns the number of Records in this Recordset.
      Returns:
      The number of Records in this Recordset.
      API:
      This public API is available in Java.
    • columnCount

      public int columnCount()
      Returns the number of columns.
      Returns:
      the number of columns.
      API:
      This public API is available in Java.
    • add

      public void add(Record record)
      Adds a copy of a record as last row. If the receiver recordset is not initialized, new columns are created corresponding to the fields in the argument. Otherwise, the new row has only fields for columns that already exist.
      Parameters:
      record - The new record.
      API:
      This public API is available in Java.
    • add

      public void add(List<?> row)
      Adds a copy of a record as last row. If the receiver recordset is not initialized, nothing is inserted. Otherwise, the new row has only fields for columns that already exist.
      Parameters:
      row - The new row.
      API:
      This public API is available in Java.
    • add

      public void add(CompositeObject object)
      Transforms the argument to a Record and add it into the recordset. If the receiver recordset is not initialized, new columns are created corresponding to the fields in the argument. Otherwise, the new row has only fields for columns that already exist.
      Parameters:
      object - An ivy object considered as new record.
      API:
      This public API is available in Java.
    • insertAt

      public void insertAt(int index, Record record)
      Inserts a record at a given index. If this receiver recordset is initialized, the new row has only fields for columns that already exist. If this recordset is not initialized, new columns are created corresponding to the fields in the argument record. If the given index is < 0, the record is inserted at 0. If the given row is greater than the number of rows, the record is appended at the end.
      Parameters:
      index - The index where to insert the new record.
      record - The Record to insert.
      API:
      This public API is available in Java.
    • insertAt

      public void insertAt(int index, List<?> record)
      Inserts a copy of the argument list as a new row at the given index in this recordset. If this recordset is not initialized, nothing is inserted. If the given index is < 0, the record is inserted at 0. If the given row is greater than the number of rows, the record is appended at the end.
      Parameters:
      index - The index where to insert the new record.
      record - The Record to insert.
      API:
      This public API is available in Java.
    • insertAt

      public void insertAt(int index, CompositeObject record)
      Inserts a new record at a given index. The field values of the new record are extracted from the argument object. If the given row is < 0, the record in inserted at 0. If the given row is greater than the number of rows, the record is appended. If the receiver recordset is initialized, the new row has only fields for columns that already exist. If the receiver recordset is not initialized, new columns are created corresponding to the fields in the argument IvyObject.
      Parameters:
      index - The index where to insert the new record.
      record - The Record to insert.
      API:
      This public API is available in Java.
    • addAll

      public void addAll(List<?> newRecords)
      Adds records to this Recordset.
      Parameters:
      newRecords - A list of records; this List may contain Records or Lists.
      API:
      This public API is available in Java.
    • addAll

      public void addAll(Recordset recordset)
      Adds records from another Recordset to this Recordset.
      Parameters:
      recordset - A recordset whose records are appended to this recordset;
      API:
      This public API is available in Java.
    • insertAllAt

      public void insertAllAt(int index, List<?> newRecords)
      Inserts records into this Recordset.
      Parameters:
      index - Where to insert the Records.
      newRecords - A list of records; this List may contain Records or Lists.
      API:
      This public API is available in Java.
    • insertAllAt

      public void insertAllAt(int index, Recordset recordset)
      Adds records from another Recordset to this Recordset.
      Parameters:
      index - Where to insert the Records.
      recordset - A recordset whose records are inserted to this recordset;
      API:
      This public API is available in Java.
    • toList

      public List<Record> toList()
      Converts this Recordset into a List of Records
      Returns:
      A list of records.
      API:
      This public API is available in Java.
    • toList

      public <T> List<T> toList(Class<T> dataClass)
      Converts this Recordset into a list of objects of type <T>. All fields with matching column names and assignable type will be matched, case insensitively. All other fields with names that don't match a column name or with non-assignable data types are ignored.
      Given dataClass must be a valid JavaBean class or an Ivy Data Class.
      Example:
         Recordset rs = queryCustomers();
         List<Customer> customers = rs.toList(Customer.class);
         customers.forEach(customer -> emailCustomer(customer));
       
      Type Parameters:
      T - The type of the data object to be constructed
      Parameters:
      dataClass - The JavaBean class matching the database entity
      Returns:
      A list of objects of given class of type <T>
      Throws:
      IllegalArgumentException - If dataClass is null, cannot be instantiated or no data could be mapped (e.g. because of no matching field names or types)
      Since:
      9.1
      API:
      This public API is available in Java.
    • toMatrix

      public List<List<Object>> toMatrix()
      Converts this Recordset into a List of List
      Returns:
      A List of Lists with cell data.
      API:
      This public API is available in Java.
    • getKeys

      public List<String> getKeys()
      Returns a List with the keys of the column-names.
      Returns:
      A List with the keys of the column-names.
      API:
      This public API is available in Java.
    • getRecords

      public List<Record> getRecords()
      Returns a List with the Records in this Recordset.
      Returns:
      A List with the Records in this Recordset.
      API:
      This public API is available in Java.
    • getColumn

      public List<Object> getColumn(String columnName)
      Returns a column.
      Parameters:
      columnName - The name of a column.
      Returns:
      The column given by its name or null.
      API:
      This public API is available in Java.
    • addColumn

      public void addColumn(String columnName, List<?> values)
      Appends a column into the recordset.
      Parameters:
      columnName - The name of the new column.
      values - A List with the values of the new columns.
      API:
      This public API is available in Java.
    • insertColumn

      public void insertColumn(int index, String columnName, List<?> values)
      Inserts a column into the recordset.
      Parameters:
      index - The index where to insert the column.
      columnName - The name of the new column.
      values - A List with the values of the new columns.
      API:
      This public API is available in Java.
    • indexOf

      public int indexOf(Record record)
      Returns the first index of a Record in this Recordset.
      Parameters:
      record - A Record.
      Returns:
      The first index of the Record in this Recordset; -1, if the Record in the argument is not contained in this Recordset.
      API:
      This public API is available in Java.
    • indexOf

      public int indexOf(List<?> record)
      Returns the first index of a Record in this Recordset.
      Parameters:
      record - A Record, given as List of values.
      Returns:
      The first index of the Record in this Recordset; -1, if the Record in the argument is not contained in this Recordset.
      API:
      This public API is available in Java.
    • lastIndexOf

      public int lastIndexOf(Record record)
      Returns the last index of a Record in this Recordset.
      Parameters:
      record - A Record.
      Returns:
      The last index of the Record in this Recordset; -1, if the Record in the argument is not contained in this Recordset.
      API:
      This public API is available in Java.
    • lastIndexOf

      public int lastIndexOf(List<?> record)
      Returns the last index of a Record in this Recordset.
      Parameters:
      record - A Record, given as List of values.
      Returns:
      The last index of the Record in this Recordset; -1, if the Record in the argument is not contained in this Recordset.
      API:
      This public API is available in Java.
    • remove

      public void remove(Record record)
      Removes a Record from this Recordset.
      Parameters:
      record - The record to remove.
      API:
      This public API is available in Java.
    • remove

      public void remove(List<Object> record)
      Removes a Record, given as a List of values, from this Recordset.
      Parameters:
      record - The record to remove.
      API:
      This public API is available in Java.
    • removeAt

      public void removeAt(int index)
      Removes a Record from this Recordset.
      Parameters:
      index - The index of the record to remove.
      API:
      This public API is available in Java.
    • clear

      public void clear()
      Removes all Records from this Recordset.
      API:
      This public API is available in Java.
    • sort

      public void sort(String colName)
      Sorts the recordset by a column in ascending order.
      Parameters:
      colName - The column the Recordset is ordered by.
      API:
      This public API is available in Java.
    • sortDesc

      public void sortDesc(String colName)
      Sorts the recordset by a column in descending order.
      Parameters:
      colName - The column the Recordset is ordered by.
      API:
      This public API is available in Java.
    • toTree

      public Tree toTree(String keyField, String parentKeyField)
      Creates a new tree from data of this recordset. This recordset must contain a hierarchy that is specified by the keyField and parentKeyField. There must be at least one record whose parentKeyField is null. The values of the tree nodes are the records.
      Parameters:
      keyField - the key field
      parentKeyField - the parent key field
      Returns:
      A tree constructed from this recordset.
      API:
      This public API is available in Java.
    • toTree

      public Tree toTree(String keyField, String parentKeyField, String valueField)
      Creates a new tree from data of this recordset. This recordset must contain a hierarchy that is specified by the keyField and parentKeyField. There must be at least one record whose parentKeyField is null. The values of the tree nodes is the value of the valueField of a record.
      Parameters:
      keyField - the key field
      parentKeyField - the parent key field
      valueField - the field that contains the value of a tree node
      Returns:
      A tree constructed from this recordset.
      API:
      This public API is available in Java.
    • toTree

      public Tree toTree(String keyField, String parentKeyField, String valueField, String infoField)
      Creates a new tree from data of this recordset. This recordset must contain a hierarchy that is specified by the keyField and parentKeyField. There must be at least one record whose parentKeyField is null. The values of the tree nodes is the value of the valueField of a record. If the valueField is null the values of the tree nodes are the records.
      Parameters:
      keyField - the key field
      parentKeyField - the parent key field
      valueField - the field that contains the value of a tree node. Maybe null.
      infoField - the field that contains the info. Maybe null. Either _info or infoField or both must be null.
      Returns:
      A tree constructed from this recordset.
      API:
      This public API is available in Java.
    • toTreeConstInfo

      public Tree toTreeConstInfo(String keyField, String parentKeyField, String valueField, String info)
      Creates a new tree from data of this recordset. This recordset must contain a hierarchy that is specified by the keyField and parentKeyField. There must be at least one record whose parentKeyField is null. The values of the tree nodes is the value of the valueField of a record.
      Parameters:
      keyField - the key field
      parentKeyField - the parent key field
      valueField - the field that contains the value of a tree node
      info - the info.
      Returns:
      A tree constructed from data of this recordset.
      API:
      This public API is available in Java.
    • elementChangedAt

      public void elementChangedAt(int rowIndex, int columnIndex)
      Informs the listeners that an element was replaced or has changed.
      Parameters:
      rowIndex -
      columnIndex -
      API:
      This public API is available in Java.
    • clone

      public Recordset clone()
      Clones this recordset.
      Specified by:
      clone in interface IIvyDataObject
      Overrides:
      clone in class NestedObject
      Returns:
      A clone of this object.
      See Also:
      API:
      This public API is available in Java.
    • deepClone

      public Recordset deepClone()
      Description copied from class: NestedObject
      Creates a deep clone.
      Specified by:
      deepClone in interface IIvyDataObject
      Overrides:
      deepClone in class NestedObject
      Returns:
      a deep clone.
      API:
      This public API is available in Java.