Package ch.ivyteam.ivy.scripting.objects
Class Recordset
java.lang.Object
ch.ivyteam.ivy.scripting.objects.NestedObject
ch.ivyteam.ivy.scripting.objects.Recordset
- All Implemented Interfaces:
IIvyDataObject
,Serializable
,Cloneable
A Recordset is a data structure corresponding to
a table from a a database.
- See Also:
- API:
- This is a public API.
-
Constructor Summary
ConstructorDescriptionCreates a new uninitialized recordset.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.Creates a new empty Recordset with given columns.Creates a new empty Recordset with given columns. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(CompositeObject object) Transforms the argument to a Record and add it into the recordset.void
Adds a copy of a record as last row.void
Adds a copy of a record as last row.void
Adds records from another Recordset to this Recordset.void
Adds records to this Recordset.void
Appends a column into the recordset.void
clear()
Removes all Records from this Recordset.clone()
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.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.Returns a specified field value of this recordset.getKeys()
Returns a List with the keys of the column-names.Returns a List with the Records in this Recordset.int
Returns the first index of a Record in this Recordset.int
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
Inserts a copy of the argument list as a new row at the given index in this recordset.void
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
lastIndexOf
(Record record) Returns the last index of a Record in this Recordset.void
Set a specified field value in this recordset.void
Removes a Record, given as a List of values, from this Recordset.void
Removes a Record from this Recordset.void
removeAt
(int index) Removes a Record from this Recordset.int
size()
Returns the number of Records in this Recordset.void
Sorts the recordset by a column in ascending order.void
Sorts the recordset by a column in descending order.toList()
Converts this Recordset into a List of Records<T> List<T>
Converts thisRecordset
into a list of objects of type <T>.toMatrix()
Converts this Recordset into a List of ListCreates a new tree from data of this recordset.Creates a new tree from data of this recordset.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
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
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
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 namesrows
- 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
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 existIndexOutOfBoundsException
- If column or row does not exist- API:
- This public API is available in Java.
-
getColumnIndex
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
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
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
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
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
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
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
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
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
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
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
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
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
Converts this Recordset into a List of Records- Returns:
- A list of records.
- API:
- This public API is available in Java.
-
toList
Converts thisRecordset
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.
GivendataClass
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
- IfdataClass
isnull
, 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
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
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
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
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
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
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
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
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
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
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
Removes a Record from this Recordset.- Parameters:
record
- The record to remove.- API:
- This public API is available in Java.
-
remove
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
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
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
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 fieldparentKeyField
- the parent key field- Returns:
- A tree constructed from this recordset.
- API:
- This public API is available in Java.
-
toTree
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 fieldparentKeyField
- the parent key fieldvalueField
- 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
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 fieldparentKeyField
- the parent key fieldvalueField
- 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
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 fieldparentKeyField
- the parent key fieldvalueField
- the field that contains the value of a tree nodeinfo
- 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
Clones this recordset.- Specified by:
clone
in interfaceIIvyDataObject
- Overrides:
clone
in classNestedObject
- Returns:
- A clone of this object.
- See Also:
- API:
- This public API is available in Java.
-
deepClone
Description copied from class:NestedObject
Creates a deep clone.- Specified by:
deepClone
in interfaceIIvyDataObject
- Overrides:
deepClone
in classNestedObject
- Returns:
- a deep clone.
- API:
- This public API is available in Java.
-