Interface DataTable
-
- All Superinterfaces:
DataDictionary
public interface DataTable extends DataDictionary
Provides script functionality to allow direct control over a Data Table by a Virtual User.In cases when a data table has multiple rows of data assigned to each Virtual User, it is set to automatically advance on each iteration. Sometimes it can be useful for auto advance to be switched off. This allows the Virtual User to directly control row advancement through the assigned data rows (a section). A named Data Table allows such control.
e.g.
// obtain a named Data Table DataTable dt = getDataTable("actors.txt"); // loop through all rows in the Data Table while (dt.hasNext()) { dt.next(); // write out to the event log the current value of the column 'surname' writeMessage("Surname: " + dt.getString("surname")); } writeMessage("No more rows");
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
hasNext()
Returnstrue
if there are any more rows in a named Data Table.boolean
isControlled()
Returnstrue
if the Data Table is automatically advanced to the next row at the end of each iteration.void
next()
Moves the named Data Table row pointer to the next row.void
reset()
Resets the Data Table row pointer to an uninitialised state.int
size()
Gets the number of rows in the DataTable that are available to the Virtual User.-
Methods inherited from interface com.facilita.fc.runtime.DataDictionary
add, get, get, getBoolean, getBoolean, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getInteger, getInteger, getList, getList, getLong, getLong, getMap, getName, getString, getString, hasKey, isReadOnly, keys, set, setBoolean, setDouble, setFloat, setInt, setInteger, setList, setLong, setName, setString, toString
-
-
-
-
Method Detail
-
hasNext
boolean hasNext()
Returnstrue
if there are any more rows in a named Data Table.This method can be used to ensure that an exception is not raised when attempting to advance to the next row within a named Data Table.
e.g.
// obtain a named Data Table DataTable dt = getDataTable("actors"); // loop through all rows in the Data Table while (dt.hasNext()) { dt.next(); // write out to the event log the current value of the column 'surname' writeMessage("Surname: " + dt.getString("surname")); } writeMessage("No more rows");
- Returns:
true
if more rows exists- See Also:
isControlled()
,next()
-
next
void next() throws java.lang.Exception
Moves the named Data Table row pointer to the next row.This method is used for advancing the current row of data in a named Data Table i.e. where the row is not advanced automatically upon each iteration. This allows the Virtual User full control of a Data Table section.
next()
raises anException
if no more rows exist in the Data Table section.Note that when first declared the Data Table is uninitialised and must be initialised by moving to the first row using
next()
.e.g.
// obtain a named Data Table DataTable dt = getDataTable("actors"); // advance the row pointer to the next row dt.next(); // write out to the event log the current value of the column 'surname' writeMessage("Surname: " + dt.getString("surname"));
- Throws:
java.lang.Exception
- An error has occurred- See Also:
hasNext()
,isControlled()
-
isControlled
boolean isControlled()
Returnstrue
if the Data Table is automatically advanced to the next row at the end of each iteration.Data Table row advancement is determined by a runtime setting. If set to Move to next row on each iteration this method returns
true
.
-
reset
void reset() throws java.lang.Exception
Resets the Data Table row pointer to an uninitialised state.When a DataTable reference is initially obtained through
VirtualUserScript.getDataTable(String)
the row pointer is uninitialised i.e. it does not point to a row. Callingnext()
for the first time moves the pointer to the first row. Calling this method will reset the pointer to an uninitialised state.e.g.
// obtain a named Data Table DataTable dt = getDataTable("actors"); // loop through all rows in the Data Table section twice for (int i = 0; i < 2; i++) { // loop through all rows in the Data Table while (dt.hasNext()) { dt.next(); // write out to the event log the current value of the column 'surname' writeMessage("Surname: " + dt.getString("surname")); } writeMessage("No more rows"); dt.reset(); }
-
size
int size()
Gets the number of rows in the DataTable that are available to the Virtual User.Note that this method returns the number of rows that have been assigned to the Virtual User, NOT the total number of rows in the table.
- Returns:
- the number of rows in the DataTable that are available to the Virtual User
-
-