Class ODataQuery
java.lang.Object
io.skipcheck.tm1.client.odata.ODataQuery
OData query options:
$select, $expand (with nested options),
$filter, $orderby, $top, $skip, $count, custom
options such as TM1's !sandbox, and parameter aliases. Immutable: each method
returns a new query.
String query = ODataQuery.none()
.select("Name", "Type")
.expand("Hierarchies", h -> h.select("Name").top(5))
.filter(Filter.startsWith(ODataProperty.of("Name"), "Q"))
.toQueryString();
// $select=Name,Type&$expand=Hierarchies($select=Name;$top=5)&$filter=startswith(Name,'Q'),
// each value encoded
Options are written in a fixed order, lowercase with $ as OData 4.0 requires,
and each value is percent-encoded once by toQueryString(). Nested options
inside $expand are separated by ;.
-
Method Summary
Modifier and TypeMethodDescriptionalias(ODataPath.Alias alias, String literalOrJson) Defines a parameter alias for a function call:@p=<literal or JSON>, written as given.booleanexpand(ODataProperty navigation) Expands a navigation property with no nested options:expand(Cube.DIMENSIONS).expand(ODataProperty navigation, UnaryOperator<ODataQuery> options) Expands a navigation property, with nested options:expand(Dimension.HIERARCHIES, h -> h.select(Hierarchy.NAME)).Expands a navigation property with no nested options.expand(String navigation, UnaryOperator<ODataQuery> options) Expands a navigation property, with nested options:expand("Hierarchies", h -> h.select("Name")).Sets$filter.inthashCode()booleanisEmpty()True if this query has no options.static ODataQuerynone()No options: the server's default response.@Nullable StringThe custom option's value, e.g.Sets a custom query option, such as TM1's!sandbox.orderBy(ODataProperty property) Adds an ascending$orderbykey:orderBy(Element.NAME).Adds an ascending$orderbykey.orderByDescending(ODataProperty property) Adds a descending$orderbykey.orderByDescending(String property) Adds a descending$orderbykey.select(ODataProperty... properties) Adds properties to$select.Adds properties to$select.skip(int n) Sets$skip: skip this many items first.top(int n) Sets$top: at most this many items.The encoded query string, without a leading?; empty if there are no options.toString()The query unencoded, for logs and messages.Sets$count=true: include the total number of matching items.
-
Method Details
-
none
-
select
Adds properties to$select. Like every option here it's an instance method, so it works the same at the top level and insideexpand(String, UnaryOperator).- Parameters:
properties- the property paths, added after any already selected- Returns:
- a new query
-
select
Adds properties to$select.- Parameters:
properties- the properties, added after any already selected- Returns:
- a new query
-
expand
Expands a navigation property with no nested options.- Parameters:
navigation- the navigation property's name- Returns:
- a new query
-
expand
Expands a navigation property, with nested options:expand("Hierarchies", h -> h.select("Name")).- Parameters:
navigation- the navigation property's nameoptions- adds the nested options to the query it's given: the empty query, or the nested options so far ifnavigationis already expanded- Returns:
- a new query
-
expand
Expands a navigation property with no nested options:expand(Cube.DIMENSIONS).- Parameters:
navigation- the navigation property- Returns:
- a new query
-
expand
Expands a navigation property, with nested options:expand(Dimension.HIERARCHIES, h -> h.select(Hierarchy.NAME)).- Parameters:
navigation- the navigation propertyoptions- adds the nested options to the query it's given, as forexpand(String, UnaryOperator)- Returns:
- a new query
-
filter
Sets$filter.- Parameters:
filter- the filter, replacing any set before- Returns:
- a new query
-
orderBy
Adds an ascending$orderbykey.- Parameters:
property- the property path, after any keys already added- Returns:
- a new query
-
orderByDescending
Adds a descending$orderbykey.- Parameters:
property- the property path, after any keys already added- Returns:
- a new query
-
orderBy
Adds an ascending$orderbykey:orderBy(Element.NAME).- Parameters:
property- the property, after any keys already added- Returns:
- a new query
-
orderByDescending
Adds a descending$orderbykey.- Parameters:
property- the property, after any keys already added- Returns:
- a new query
-
top
Sets$top: at most this many items.- Parameters:
n- the maximum number of items, zero or more- Returns:
- a new query
- Throws:
IllegalArgumentException- ifnis negative
-
skip
Sets$skip: skip this many items first.- Parameters:
n- the number of items to skip, zero or more- Returns:
- a new query
- Throws:
IllegalArgumentException- ifnis negative
-
withCount
Sets$count=true: include the total number of matching items.- Returns:
- a new query
-
option
Sets a custom query option, such as TM1's!sandbox. Custom options must not start with$or@. Setting one again replaces it.- Parameters:
name- the option's name, e.g.!sandboxvalue- the option's value, unencoded- Returns:
- a new query
- Throws:
IllegalArgumentException- ifnameisn't a valid custom option name
-
alias
Defines a parameter alias for a function call:@p=<literal or JSON>, written as given.- Parameters:
alias- the alias, as used in the function callliteralOrJson- the alias's value, an OData literal or JSON, unencoded- Returns:
- a new query
-
isEmpty
public boolean isEmpty()True if this query has no options.- Returns:
trueif there are no options
-
toQueryString
The encoded query string, without a leading?; empty if there are no options.- Returns:
- the encoded query string, or an empty string
-
toString
-
equals
-
hashCode
-
option
-