public class Query extends Object implements Iterator<QueryResult>
The Query
iterator is the result of the query factory for
IndividualEnrollment: | ProvisioningServiceClient.createIndividualEnrollmentQuery(QuerySpecification, int) |
EnrollmentGroup: | ProvisioningServiceClient.createEnrollmentGroupQuery(QuerySpecification, int) |
RegistrationStatus: | ProvisioningServiceClient.createEnrollmentGroupRegistrationStateQuery(QuerySpecification, String, int) |
On all cases, the QuerySpecification contains a SQL query that must follow the Query Language for the Device Provisioning Service.
Optionally, an Integer
with the pageSize, can determine the maximum number of the items in the
QueryResult
returned by the next()
. It must be any positive integer, and if it contains 0,
the Device Provisioning Service will ignore it and use a standard page size.
You can use this Object as a standard Iterator, just using the hasNext()
and next()
in a
while
loop, up to the point where the hasNext()
return false
. But, keep in mind
that the QueryResult
can contain a empty list, even if the hasNext()
returned true
.
For example, image that you have 10 IndividualEnrollment in the Device Provisioning Service and you created
new query with the pageSize
equals 5. The first hasNext()
will return true
, and the
first next()
will return a QueryResult
with 5 items. After that you call the hasNext
,
which will returns true
. Now, before you get the next page, somebody delete all the IndividualEnrollment,
What happened, when you call the next()
, it will return a valid QueryResult
, but the
QueryResult.getItems() will return a empty list.
You can also store a query context (QuerySpecification + ContinuationToken) and restart it in the future, from the point where you stopped.
Besides the Items, the queryResult contains the continuationToken. In any point in the future, you may recreate
the query using the same query factories that you used for the first time, and call
next(String)
providing the stored continuationToken to get the next page.
Modifier and Type | Method and Description |
---|---|
int |
getPageSize()
Getter for the pageSize.
|
boolean |
hasNext()
Getter for hasNext.
|
QueryResult |
next()
Return the next page of result for the query.
|
QueryResult |
next(String continuationToken)
Return the next page of result for the query using a new continuationToken.
|
void |
setPageSize(int pageSize)
Setter for the pageSize.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining, remove
public boolean hasNext()
It will return true
if the query is not finished in the Device Provisioning Service, and another
iteration with next()
may return more items. Call next()
after receive a hasNext
true
will result in a QueryResult
that can or cannot contains elements. And call
next()
after receive a hasNext
false
will result in a exception.
hasNext
in interface Iterator<QueryResult>
boolean
true
if query is not finalize in the Service.public QueryResult next()
next
in interface Iterator<QueryResult>
QueryResult
with the next page of items for the query.NoSuchElementException
- if the query does no have more pages to return.public QueryResult next(String continuationToken)
continuationToken
- the String
with the previous continuationToken. It cannot be null
or empty.QueryResult
with the next page of items for the query.NoSuchElementException
- if the query does no have more pages to return.public int getPageSize()
PageSize is the maximum number of items in the QueryResult
per iteration.
int
with the current pageSize.public void setPageSize(int pageSize)
PageSize is the maximum number of items in the QueryResult
per iteration.
pageSize
- an int
with the new pageSize. It cannot be negative. The Device Service Client
will use its own default pageSize if it is 0.IllegalArgumentException
- if the provided pageSize is negative.Copyright © 2022. All rights reserved.