Class SelectRowsCommand

java.lang.Object
org.labkey.remoteapi.Command<ResponseType,org.apache.hc.client5.http.classic.methods.HttpPost>
org.labkey.remoteapi.PostCommand<ResponseType>
org.labkey.remoteapi.query.BaseQueryCommand<SelectRowsResponse>
org.labkey.remoteapi.query.SelectRowsCommand
All Implemented Interfaces:
HasRequiredVersion, BaseSelect

public class SelectRowsCommand extends BaseQueryCommand<SelectRowsResponse> implements BaseSelect
Command for selecting data from any LabKey schema/query exposed on the server identified by the Connection object supplied to the Command.execute(org.labkey.remoteapi.Connection, String) method.

All data exposed from a LabKey Server is organized into a set of queries contained in a set of schemas. A schema is simply a group of queries, identified by a name (e.g., 'lists' or 'study'). A query is a particular table or view within that schema (e.g., 'People' or 'Peptides'). For purposes of selecting, a query may be either a base table or a view that joins data between related tables.

To view the schemas and queries exposed in a given folder, add a Query web part to your portal page and choose the option "Show the list of tables in this schema" in the part configuration page. Alternatively, if it is exposed, click on the Query tab across the top of the main part of the page.

Example:

 
     Connection cn = new Connection("https://www.labkey.org");
     SelectRowsCommand cmd = new SelectRowsCommand("study", "Physical Exam");
     SelectRowsResponse response = cmd.execute(cn, "Home/Study/demo");
     for(Map<String, Object> row : response.getRows())
     {
         System.out.println(row.get("ParticipantId") + " weighs " + row.get("APXwtkg"));
     }
 
 
  • Constructor Details

    • SelectRowsCommand

      public SelectRowsCommand(String schemaName, String queryName)
      Constructs a new SelectRowsCommand for the given schema and query name.
      Parameters:
      schemaName - The schema name.
      queryName - The query name.
  • Method Details

    • setExtendedFormat

      public void setExtendedFormat(boolean extendedFormat)
      Set to true to request the extended response format, which includes URLs, Missing-Value indicators and display values in addition to the raw values. Use the getRowset() method on the response to iterate over the returned rows in a format-neutral manner.
      Parameters:
      extendedFormat - True to get the extended format.
    • isExtendedFormat

      public boolean isExtendedFormat()
      Returns whether the extended format will be requested. See setExtendedFormat() for details.
      Returns:
      true if extended format will be requested.
    • getSchemaName

      public String getSchemaName()
      Returns the current schema name this command will query.
      Returns:
      The schema name.
    • setSchemaName

      public void setSchemaName(String schemaName)
      Sets the schema name this command will query.
      Parameters:
      schemaName - The new schema name.
    • getQueryName

      public String getQueryName()
      Returns the query this command will request.
      Returns:
      The current query name.
    • setQueryName

      public void setQueryName(String queryName)
      Sets the query name this command will request.
      Parameters:
      queryName - The new query name.
    • getViewName

      public String getViewName()
      Returns the current saved view name this command will request.
      Returns:
      The view name, or null if the default view will be requested.
    • setViewName

      public void setViewName(String viewName)
      Sets a particular saved view to request. Users may create specific views of any given query and save them under a name. Calling this method with a particular name will cause the command to request the saved view instead of the query's default view.
      Parameters:
      viewName - The view name, or null to request the default view.
    • getColumns

      public List<String> getColumns()
      Returns the explicit column list to be requested, or null if the default set of columns will be requested.
      Returns:
      The column list or null.
    • setColumns

      public void setColumns(List<String> columns)
      Sets an explicit list of columns to request. To refer to columns in a related table, use the syntax foreign-key-column/related-column (e.g., 'RelatedPeptide/Protein'); The special column name '*' can be used to request all columns in the target query.
      Parameters:
      columns - The explicit column list, or null to request the default set of columns.
    • createResponse

      protected SelectRowsResponse createResponse(String text, int status, String contentType, org.json.JSONObject json)
      Overridden to create a SelectRowsResponse object.
      Overrides:
      createResponse in class Command<SelectRowsResponse,org.apache.hc.client5.http.classic.methods.HttpPost>
      Parameters:
      text - The response text
      status - The HTTP status code
      contentType - The Content-Type header value
      json - The parsed JSONObject (or null if JSON was not returned)
      Returns:
      A SelectRowsResponse object
    • getJsonObject

      public org.json.JSONObject getJsonObject()
      Description copied from class: PostCommand
      Returns the JSON object to post or null for no JSON. Override this method to provide parameters as JSON.
      Overrides:
      getJsonObject in class BaseQueryCommand<SelectRowsResponse>
      Returns:
      The JSON object to post.