Package net.pricefx.formulaengine
Interface DatamartRowSet
public interface DatamartRowSet
Represents the data of a PA field collection (Data Feed, Data Source, Datamart, etc.) and provides methods to work with it.
Available in a PA DataLoad context only. If you need an alternative, see
DatamartContext.DataLoader
.
In order to get a valid instance of DatamartRowSet
, use api.getDatamartRowSet()
. Typically only
changes to the target DatamartRowSet
will actually be stored. And which field collection is actually
the source or the target depends on the Dataload configuration.
Example:
def sourceRows = api.getDatamartRowSet("source");
def targetRows = api.getDatamartRowSet("target");
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefaultValues
(Map<String, Object> defaultValues) Add default values to be used when creating new rows.boolean
Adds a row.boolean
Deletes the current row.boolean
Deletes a row.boolean
first()
Sets the current row index of thisDatamartRowSet
to the first row.Provides the list of all the fields.Returns the current row.Provides the list of the key fields.Get the row with the given key values.Collection
<? extends Map<String, Object>> getRows()
boolean
isEmpty()
Returnstrue
if thisDatamartRowSet
contains no rows.boolean
last()
Sets the current row index of thisDatamartRowSet
to the last row.void
loadRows
(DatamartRowSet otherRowset) Adds rows from anotherDatamartRowSet
.void
Add rows from a #Matrix2D.void
loadRows
(Matrix2D data, Collection<String> columns) Add rows from a #Matrix2D, possibly only a subset of the matrix columns.void
Add rows from a #Matrix2D, possibly only a subset of the matrix columns.void
merge
(DatamartRowSet otherSet) Updates rows in this set, for which a row with the same key exists in the other set.newRow()
Creates a representation of a new row, potentially populated with default values.boolean
next()
Sets the current row index of thisDatamartRowSet
to the next row.boolean
previous()
Sets the current row index of thisDatamartRowSet
to the previous row.void
reset()
Resets the current row index of thisDatamartRowSet
.void
setDefaultValues
(Map<String, Object> defaultValues) Set default values to be used when creating new rows.int
size()
Returns the number of rows in thisDatamartRowSet
.Converts the data toResultMatrix
Limited toRESULTMATRIX_MAXROWS
rows.toResultMatrix
(int maxRows) Converts the data toResultMatrix
Limited to user defined number of rows which cannot exceedRESULTMATRIX_MAXROWS
.boolean
Updates row values, only if a row already exists for the provided keys.
-
Field Details
-
RESULTMATRIX_MAXROWS
static final int RESULTMATRIX_MAXROWS- See Also:
-
-
Method Details
-
getKeyFields
Provides the list of the key fields. -
getAllFields
Collection<String> getAllFields()Provides the list of all the fields.- Returns:
- field names represented as a
Collection
ofString
-
addRow
Adds a row.target.addRow([ sku: obj.sku, // key field salesOrg: obj.attribute1, // key field quantity: 0 ])
- Parameters:
map
- represented asMap
- Returns:
- true if the row was added
-
updateRow
Updates row values, only if a row already exists for the provided keys.target.updateRow([ sku: obj.sku, // key field salesOrg: obj.attribute1, // key field quantity: 0 ])
- Parameters:
map
- row represented asMap
- Returns:
- true if the row was updated
-
deleteRow
Deletes a row. Note that only the key field values are relevant, the method does not verify that every single value matches.target.deleteRow([ txid: obj.txid ])
- Parameters:
map
- key fields represented asMap
- Returns:
- true if the row was deleted
- Since:
- 6.0 - Vesper
- See Also:
-
getRow
Get the row with the given key values. Always returns a copy.def rowKey = [ "SHIP_TO": obj.ship_to, "SALES_MANAGER": obj.sales_manager, "MATERIAL": obj.sku, "REPORT_MONTH": prPeriod] def rRow = target.getRow(rowKey)
-
setDefaultValues
Set default values to be used when creating new rows. This method will drop all previously set defaults. To add to the existing defaults, useaddDefaultValues(Map)
- See Also:
-
addDefaultValues
Add default values to be used when creating new rows. There can be only one default value per field, so previously set defaults may be replaced.- See Also:
-
newRow
Creates a representation of a new row, potentially populated with default values. Note that the row is not yet added to theDatamartRowSet
. UseaddRow(Map)
to add the row.- Returns:
- new row represented as
Map
- See Also:
-
loadRows
Adds rows from anotherDatamartRowSet
. Note that there is no check whether the fields of the rowsets are compatible, not even regarding the key fields.- Parameters:
otherRowset
-DatamartRowSet
containing the rows- Throws:
IllegalFieldValuesException
- if the key fields are not the same
-
getRows
Collection<? extends Map<String,Object>> getRows()- Returns:
- a
Collection
of all rows, each row represented as a #Map
-
isEmpty
boolean isEmpty()Returnstrue
if thisDatamartRowSet
contains no rows.- Returns:
true
if thisDatamartRowSet
contains no rows
-
size
int size()Returns the number of rows in thisDatamartRowSet
. If thisDatamartRowSet
contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Returns:
- the number of rows in this
DatamartRowSet
-
reset
void reset()Resets the current row index of thisDatamartRowSet
.- See Also:
-
first
Sets the current row index of thisDatamartRowSet
to the first row.- Throws:
SQLException
- See Also:
-
last
Sets the current row index of thisDatamartRowSet
to the last row.- Throws:
SQLException
- See Also:
-
previous
Sets the current row index of thisDatamartRowSet
to the previous row.- Throws:
SQLException
- See Also:
-
next
Sets the current row index of thisDatamartRowSet
to the next row.- Throws:
SQLException
- See Also:
-
getCurrentRow
Returns the current row.- Returns:
- current row represented as
Map
- See Also:
-
deleteCurrentRow
boolean deleteCurrentRow()Deletes the current row.- Returns:
- true if successful (row existed)
-
merge
Updates rows in this set, for which a row with the same key exists in the other set. Does not add any rows to this set!- Parameters:
otherSet
- otherDatamartRowSet
-
loadRows
Add rows from a #Matrix2D. If the #Matrix2D data does not contain allDatamartRowSet
key fields, then we assume auto-increment of the missing key fields is desired. If on the other hand, the fields are there, but the values are missing (for some rows), then we assume inserting empty #String("")
.- Parameters:
data
- the #Matrix2D holding the data to add- See Also:
-
loadRows
Add rows from a #Matrix2D, possibly only a subset of the matrix columns. If the #Matrix2D data does not contain allDatamartRowSet
key fields, then we assume auto-increment of the missing key fields is desired. If on the other hand, the fields are there, but the values are missing (for some rows), then we assume inserting empty #String("")
.- Parameters:
data
- the #Matrix2D holding the data to addcolumns
- name of the #Matrix2D columns to import- See Also:
-
loadRows
Add rows from a #Matrix2D, possibly only a subset of the matrix columns. If the #Matrix2D data does not contain allDatamartRowSet
key fields, then we assume auto-increment of the missing key fields is desired. If on the other hand, the fields are there, but the values are missing (for some rows), then we assume inserting empty #String("")
.- Parameters:
data
- the #Matrix2D holding the data to addfieldMapping
- key is theDatamartRowSet
field name, and value is the Matrix column name- See Also:
-
toResultMatrix
ResultMatrix toResultMatrix()Converts the data toResultMatrix
Limited toRESULTMATRIX_MAXROWS
rows.- Returns:
- converted to
ResultMatrix
-
toResultMatrix
Converts the data toResultMatrix
Limited to user defined number of rows which cannot exceedRESULTMATRIX_MAXROWS
.- Parameters:
maxRows
- maximum number of rows to be converted, capped toRESULTMATRIX_MAXROWS
- Returns:
- converted to
ResultMatrix
-