Class SelectRowsResponse

java.lang.Object
org.labkey.remoteapi.CommandResponse
org.labkey.remoteapi.query.SelectRowsResponse

public class SelectRowsResponse extends CommandResponse
The command response class returned from the Command.execute(org.labkey.remoteapi.Connection, String) method. This class provides helpful methods for obtaining specific bits of the parsed response data.
See Also:
  • Constructor Details

    • SelectRowsResponse

      public SelectRowsResponse(String text, int statusCode, String contentType, org.json.JSONObject json, Command<? extends SelectRowsResponse,?> sourceCommand)
      Constructs a new SelectRowsResponse given the response text and HTTP status code.
      Parameters:
      text - The response text.
      statusCode - The HTTP status code.
      contentType - The Content-Type header value.
      json - The parsed JSONObject (or null if no JSON was returned
      sourceCommand - A copy of the command that created this response
  • Method Details

    • getRowCount

      public Number getRowCount()
      Returns the number of rows this query could return. If a maximum row limit was set on the SelectRowsCommand, this value may be higher than the actual number of rows returned. This value allows clients that page results to know the total number of possible rows, even if only a page of them was returned.
      Returns:
      The total number of rows, or null if this value was not returned by the server.
    • getRowset

      public Rowset getRowset()
      Returns an iterable Rowset. Use this to iterate over the rows, working with the Row interface, which hides the differences between the normal (<9.1) and extended (>=9.1) response formats.
      Returns:
      An iterable Rowset.
    • getMetaData

      public Map<String,Object> getMetaData()
      Returns the meta-data section of the response. This map contains the following entries:
      • id = the column name that contains the primary key for the row.
      • fields = a List of Maps, one for each result column. Each map contains the following properties:
        • name = the name of the column.
        • type = the JSON type name of the column ('string', 'boolean', 'date', 'int', or 'float').
      Returns:
      The meta-data section of the response, or null if no section was returned by the server.
    • getMetaData

      public Map<String,Object> getMetaData(String columnName)
      Returns the meta-data for a given column name. See getMetaData() for more information on the contents of this map.
      Parameters:
      columnName - The requested column name.
      Returns:
      The meta-data for that column or null if that column was not found.
    • getColumnDataType

      public SelectRowsResponse.ColumnDataType getColumnDataType(String columnName)
      Returns the data type for the requested column name.
      Parameters:
      columnName - The column name.
      Returns:
      The column's data type, or null if the column was not found.
    • getIdColumn

      public String getIdColumn()
      Returns the name of the column containing the primary key value for each row.
      Returns:
      The name of the primary key column, or null if that information was not returned by the server.
    • getColumnModel

      public List<Map<String,Object>> getColumnModel()
      Returns the column model section of the response. The column model contains user-interface-related information about the column, such as its header caption, whether it is editable or required, etc.

      This method will return a List of Maps, one for each column in the resultset. Each Map will contain the following properties:

      • hidden = whether this column should be hidden (Boolean).
      • sortable = whether this column can be used for sorting (Boolean).
      • align = the horizontal alignment for this column (String, 'left'|'center'|'right').
      • width = the default width (in CSS width units) for this column (String).
      • dataIndex = the name of the column (String).
      • required = whether this column is required (Boolean).
      • editable = whether this column should be editable (Boolean).
      • header = the header caption for this column (String).
      Returns:
      The column model, or null if none was returned by the server.
    • getColumnModel

      public Map<String,Object> getColumnModel(String columnName)
      Returns the column properties for the specified column name. See getColumnModel() for more information.
      Parameters:
      columnName - The column name.
      Returns:
      The properties for the specified column, or null if the column was not found.
    • getRows

      public List<Map<String,Object>> getRows()
      Returns the list of rows from the parsed response data. Note that numbers in the map values will be either of type Double or type Long depending on the presence of a decimal point. The most reliable way to work with them is to use the Number class. For example:
      
       for (Map<String, Object> row : response.getRows())
       {
           Number key = (Number)row.get("Key");
           // use Number.intValue(), doubleValue(), longValue(), etc to get various primitive types
       }
       
      Returns:
      The list of rows (each row is a Map), or null if the rows list was not included in the response.