org.restlet.ext.odata
Class Query<T>

java.lang.Object
  extended by org.restlet.ext.odata.Query<T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>

public class Query<T>
extends Object
implements Iterable<T>

Specific query to a OData service, represents a particular HTTP request to a data service. This Java class is more or less equivalent to the WCF DataServiceQuery class.

Author:
Jerome Louvel
See Also:

Field Summary
static int TYPE_COMPLEX_TYPE_OR_PROPERTY
          Type of query: complex type or property.
static int TYPE_COMPLEX_TYPE_PROPERTY
          Type of query: property.
static int TYPE_COMPLEX_TYPE_PROPERTY5
          Type of query: property bis??
static int TYPE_ENTITY
          Type of query: entity.
static int TYPE_ENTITY_SET
          Type of query: entity set.
static int TYPE_LINKS
          Type of query: links.
static int TYPE_PROPERTY_VALUE
          Type of query: property value.
static int TYPE_UNKNOWN
          Type of query: unknown.
 
Constructor Summary
Query(Service service, String subpath, Class<T> entityClass)
          Constructor.
 
Method Summary
 Query<T> addParameter(String name, String value)
          Creates a new Query with the query parameter set in the URI generated by the returned query.
 Query<T> addParameters(Series<Parameter> params)
          Creates a new Query with the query parameter set in the URI generated by the returned query.
protected  String createTargetUri()
          Returns the complete target URI reference for this query.
 void execute()
          Executes the query.
 Query<T> expand(String path)
          Creates a new Query with the $expand option set in the URI generated by the returned query.
 Query<T> filter(String predicate)
          Creates a new Query with the $filter option set in the URI generated by the returned query.
 int getCount()
          Returns the total number of elements in the entity set, or -1 if it is available.
 Service getService()
          Returns the parent client service.
 String getSubpath()
          Returns the path of the targeted entity relatively to the data service URI.
 Query<T> inlineCount(boolean inlineCount)
          Creates a new Query with the $inlinecount option set in the URI generated by the returned query.
 Iterator<T> iterator()
          Returns an iterator over a set of elements of type T.
 Query<T> orderBy(String criteria)
          Creates a new Query with the $orderby option set in the URI generated by the returned query.
 Query<T> select(String select)
          Creates a new Query with the $select option set in the URI generated by the returned query.
 void setQuery(String query)
          Sets the query string of the request.
 Query<T> skip(int rowsCount)
          Creates a new Query with the $skip option set in the URI generated by the returned query.
 Query<T> skipToken(String token)
          Creates a new Query with the $skiptoken option set in the URI generated by the returned query.
 Query<T> top(int rowsCount)
          Creates a new Query with the $top option set in the URI generated by the returned query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_COMPLEX_TYPE_OR_PROPERTY

public static final int TYPE_COMPLEX_TYPE_OR_PROPERTY
Type of query: complex type or property.

See Also:
Constant Field Values

TYPE_COMPLEX_TYPE_PROPERTY

public static final int TYPE_COMPLEX_TYPE_PROPERTY
Type of query: property.

See Also:
Constant Field Values

TYPE_COMPLEX_TYPE_PROPERTY5

public static final int TYPE_COMPLEX_TYPE_PROPERTY5
Type of query: property bis??

See Also:
Constant Field Values

TYPE_ENTITY

public static final int TYPE_ENTITY
Type of query: entity.

See Also:
Constant Field Values

TYPE_ENTITY_SET

public static final int TYPE_ENTITY_SET
Type of query: entity set.

See Also:
Constant Field Values

TYPE_LINKS

public static final int TYPE_LINKS
Type of query: links.

See Also:
Constant Field Values

TYPE_PROPERTY_VALUE

public static final int TYPE_PROPERTY_VALUE
Type of query: property value.

See Also:
Constant Field Values

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN
Type of query: unknown.

See Also:
Constant Field Values
Constructor Detail

Query

public Query(Service service,
             String subpath,
             Class<T> entityClass)
Constructor.

Parameters:
service - The data service requested by the query.
subpath - The path of the targeted entity relatively to the data service URI.
entityClass - The class of the target entity.
Method Detail

addParameter

public Query<T> addParameter(String name,
                             String value)
Creates a new Query with the query parameter set in the URI generated by the returned query.

Parameters:
name - The string value that contains the name of the query string option to add.
value - The value of the query string option.
Returns:
A new Query with the query parameter set in the URI generated by the returned query.

addParameters

public Query<T> addParameters(Series<Parameter> params)
Creates a new Query with the query parameter set in the URI generated by the returned query.

Parameters:
params - the set of name/value pairs to add to the query string
Returns:
A new Query with the query parameter set in the URI generated by the returned query.

createTargetUri

protected String createTargetUri()
Returns the complete target URI reference for this query. It is composed of the data service base URI, the subpath and the query string.

Returns:
The complete target URI reference.

execute

public void execute()
             throws Exception
Executes the query.

Throws:
Exception

expand

public Query<T> expand(String path)
Creates a new Query with the $expand option set in the URI generated by the returned query.

Parameters:
path - A string value that contains the requesting URI.
Returns:
A new Query with the $expand option set in the URI generated by the returned query.

filter

public Query<T> filter(String predicate)
Creates a new Query with the $filter option set in the URI generated by the returned query.

Parameters:
predicate - A string value that contains the predicate used to filter the data.
Returns:
A new Query with the $filter option set in the URI generated by the returned query.

getCount

public int getCount()
Returns the total number of elements in the entity set, or -1 if it is available.

Returns:
The total number of elements in the entity set.
Throws:
Exception

getService

public Service getService()
Returns the parent client service.

Returns:
The parent client service.

getSubpath

public String getSubpath()
Returns the path of the targeted entity relatively to the data service URI.

Returns:
The path of the targeted entity relatively to the data service URI.

inlineCount

public Query<T> inlineCount(boolean inlineCount)
Creates a new Query with the $inlinecount option set in the URI generated by the returned query.

Parameters:
inlineCount - True if the total number of entities in the entity set must be returned.
Returns:
A new Query with the $inlinecount option set in the URI generated by the returned query.

iterator

public Iterator<T> iterator()
Returns an iterator over a set of elements of type T. It returns null if the query does not retrieve elements.

Specified by:
iterator in interface Iterable<T>
Returns:
an Iterator or null if the query does not retrieve elements.

orderBy

public Query<T> orderBy(String criteria)
Creates a new Query with the $orderby option set in the URI generated by the returned query.

Parameters:
criteria - A string value that contains the criteria used to order the results.
Returns:
A new Query with the $orderby option set in the URI generated by the returned query.

select

public Query<T> select(String select)
Creates a new Query with the $select option set in the URI generated by the returned query.

Parameters:
select - A string value that contains the requesting URI.
Returns:
A new Query with the $select option set in the URI generated by the returned query.

setQuery

public void setQuery(String query)
Sets the query string of the request.

Parameters:
query - The query string of the request.

skip

public Query<T> skip(int rowsCount)
Creates a new Query with the $skip option set in the URI generated by the returned query.

Parameters:
rowsCount - A number of rows to skip.
Returns:
A new Query with the $skip option set in the URI generated by the returned query.

skipToken

public Query<T> skipToken(String token)
Creates a new Query with the $skiptoken option set in the URI generated by the returned query.

Parameters:
token - A string value that contains the requesting URI.
Returns:
A new Query with the $skiptoken option set in the URI generated by the returned query.

top

public Query<T> top(int rowsCount)
Creates a new Query with the $top option set in the URI generated by the returned query.

Parameters:
rowsCount - A number of rows used to limit the number of results.
Returns:
A new Query with the $top option set in the URI generated by the returned query.


Copyright © 2005-2013 Restlet.