Package org.labkey.remoteapi.query
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
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"));
}
-
Nested Class Summary
Nested classes/interfaces inherited from class org.labkey.remoteapi.Command
Command.CommonParameters, Command.Response
-
Field Summary
Fields inherited from class org.labkey.remoteapi.query.BaseQueryCommand
_containerFilter, _filters, _maxRows, _offset, _sorts
Fields inherited from class org.labkey.remoteapi.Command
CONTENT_TYPE_JSON
-
Constructor Summary
ConstructorsConstructorDescriptionSelectRowsCommand
(String schemaName, String queryName) Constructs a new SelectRowsCommand for the given schema and query name. -
Method Summary
Modifier and TypeMethodDescriptionprotected SelectRowsResponse
createResponse
(String text, int status, String contentType, org.json.JSONObject json) Overridden to create a SelectRowsResponse object.Returns the explicit column list to be requested, or null if the default set of columns will be requested.org.json.JSONObject
Returns the JSON object to post or null for no JSON.Returns the query this command will request.Returns the current schema name this command will query.Returns the current saved view name this command will request.boolean
Returns whether the extended format will be requested.void
setColumns
(List<String> columns) Sets an explicit list of columns to request.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.void
setQueryName
(String queryName) Sets the query name this command will request.void
setSchemaName
(String schemaName) Sets the schema name this command will query.void
setViewName
(String viewName) Sets a particular saved view to request.Methods inherited from class org.labkey.remoteapi.query.BaseQueryCommand
addFilter, addFilter, addSort, addSort, getContainerFilter, getFilters, getMaxRows, getOffset, getQueryParameters, getSorts, isIgnoreFilter, isIncludeMetadata, isIncludeTotalCount, setContainerFilter, setFilters, setIgnoreFilter, setIncludeMetadata, setIncludeTotalCount, setMaxRows, setOffset, setQueryParameters, setSorts
Methods inherited from class org.labkey.remoteapi.PostCommand
createRequest
Methods inherited from class org.labkey.remoteapi.Command
_execute, createParameterMap, execute, getActionName, getControllerName, getHttpRequest, getParameters, getParamValueAsString, getRequiredVersion, getTimeout, setRequiredVersion, setTimeout
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.labkey.remoteapi.query.BaseSelect
execute, getContainerFilter, getMaxRows, getOffset, getRequiredVersion, setContainerFilter, setMaxRows, setOffset, setRequiredVersion
-
Constructor Details
-
SelectRowsCommand
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
Returns the current schema name this command will query.- Returns:
- The schema name.
-
setSchemaName
Sets the schema name this command will query.- Parameters:
schemaName
- The new schema name.
-
getQueryName
Returns the query this command will request.- Returns:
- The current query name.
-
setQueryName
Sets the query name this command will request.- Parameters:
queryName
- The new query name.
-
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
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
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
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 classCommand<SelectRowsResponse,
org.apache.hc.client5.http.classic.methods.HttpPost> - Parameters:
text
- The response textstatus
- The HTTP status codecontentType
- The Content-Type header valuejson
- 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 classBaseQueryCommand<SelectRowsResponse>
- Returns:
- The JSON object to post.
-