skipcheck

TM1 client · Docs · Queries

ODataQuery

import io.skipcheck.tm1.client.odata.ODataQuery;

Used in the walkthroughs Connect and list your cubes, Read and write cells, Run a process and read its result, Test your code against a real TM1, Add TM1 to a Spring Boot application.

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 ;.

Members

none staticNo options.
selectAdds properties to $select.
selectAdds properties to $select.
expandExpands a navigation property with no nested options.
expandExpands a navigation property, with nested options.
expandExpands a navigation property with no nested options.
expandExpands a navigation property, with nested options.
filterSets $filter.
orderByAdds an ascending $orderby key.
orderByDescendingAdds a descending $orderby key.
orderByAdds an ascending $orderby key.
orderByDescendingAdds a descending $orderby key.
topSets $top.
skipSets $skip.
withCountSets $count=true.
optionSets a custom query option, such as TM1's !sandbox.
aliasDefines a parameter alias for a function call.
isEmptyTrue if this query has no options.
toQueryStringThe encoded query string, without a leading ?; empty if there are no options.
toStringThe query unencoded, for logs and messages.
equals
hashCode
optionThe custom option's value, e.g.

none

static
static ODataQuery none()

No options: the server's default response.

Returns

the empty query

select

ODataQuery select(String... properties)

Adds properties to $select. Like every option here it's an instance method, so it works the same at the top level and inside expand.

Parameters

properties
the property paths, added after any already selected

Returns

a new query

select

ODataQuery select(ODataProperty... properties)

Adds properties to $select.

Parameters

properties
the properties, added after any already selected

Returns

a new query

expand

ODataQuery expand(String navigation)

Expands a navigation property with no nested options.

Parameters

navigation
the navigation property's name

Returns

a new query

expand

ODataQuery expand(String navigation, UnaryOperator<ODataQuery> options)

Expands a navigation property, with nested options: expand("Hierarchies", h -> h.select("Name")).

Parameters

navigation
the navigation property's name
options
adds the nested options to the query it's given: the empty query, or the nested options so far if navigation is already expanded

Returns

a new query

expand

ODataQuery expand(ODataProperty navigation)

Expands a navigation property with no nested options: expand(Cube.DIMENSIONS).

Parameters

navigation
the navigation property

Returns

a new query

expand

ODataQuery expand(ODataProperty navigation, UnaryOperator<ODataQuery> options)

Expands a navigation property, with nested options: expand(Dimension.HIERARCHIES, h -> h.select(Hierarchy.NAME)).

Parameters

navigation
the navigation property
options
adds the nested options to the query it's given, as for expand

Returns

a new query

filter

ODataQuery filter(Filter filter)

Sets $filter.

Parameters

filter
the filter, replacing any set before

Returns

a new query

orderBy

ODataQuery orderBy(String property)

Adds an ascending $orderby key.

Parameters

property
the property path, after any keys already added

Returns

a new query

orderByDescending

ODataQuery orderByDescending(String property)

Adds a descending $orderby key.

Parameters

property
the property path, after any keys already added

Returns

a new query

orderBy

ODataQuery orderBy(ODataProperty property)

Adds an ascending $orderby key: orderBy(Element.NAME).

Parameters

property
the property, after any keys already added

Returns

a new query

orderByDescending

ODataQuery orderByDescending(ODataProperty property)

Adds a descending $orderby key.

Parameters

property
the property, after any keys already added

Returns

a new query

top

ODataQuery top(int n)

Sets $top: at most this many items.

Parameters

n
the maximum number of items, zero or more

Returns

a new query

Throws

IllegalArgumentException
if n is negative

skip

ODataQuery skip(int n)

Sets $skip: skip this many items first.

Parameters

n
the number of items to skip, zero or more

Returns

a new query

Throws

IllegalArgumentException
if n is negative

withCount

ODataQuery withCount()

Sets $count=true: include the total number of matching items.

Returns

a new query

option

ODataQuery option(String name, String value)

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. !sandbox
value
the option's value, unencoded

Returns

a new query

Throws

IllegalArgumentException
if name isn't a valid custom option name

alias

ODataQuery alias(ODataPath.Alias alias, String literalOrJson)

Defines a parameter alias for a function call: @p=<literal or JSON>, written as given.

Parameters

alias
the alias, as used in the function call
literalOrJson
the alias's value, an OData literal or JSON, unencoded

Returns

a new query

isEmpty

boolean isEmpty()

True if this query has no options.

Returns

true if there are no options

toQueryString

String toQueryString()

The encoded query string, without a leading ?; empty if there are no options.

Returns

the encoded query string, or an empty string

toString

String toString()

The query unencoded, for logs and messages.

equals

boolean equals(Object o)

hashCode

int hashCode()

option

String option(String name)

The custom option's value, e.g. the current !sandbox, if set.

Parameters

name
the option's name

Returns

the option's value, unencoded, or null if it isn't set

Also in the Javadoc.