Query Class
- java.
lang. Object - java.
util. Iterator<QueryResult> - com.
microsoft. azure. sdk. iot. provisioning. service. Query
- com.
- java.
public class Query
The query iterator.
TheQuery
</code> iterator is the result of the query factory for <table rows="3" cols="2"><caption>Query factories</caption><row><entry thead="no"><p><b>IndividualEnrollment:</b></p></entry><entry thead="no"><p><xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createIndividualEnrollmentQuery(QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification, int)"></xref></p></entry></row><row><entry thead="no"><p><b>EnrollmentGroup:</b></p></entry><entry thead="no"><p><xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupQuery(QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification, int)"></xref></p></entry></row><row><entry thead="no"><p><b>RegistrationStatus:</b></p></entry><entry thead="no"><p><xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupRegistrationStateQuery(QuerySpecification,String,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupRegistrationStateQuery(QuerySpecification, String, int)"></xref></p></entry></row></table></p>
On all cases, the QuerySpecification contains a SQL query that must follow the Query Language for the Device Provisioning Service.
Optionally, anInteger
</code> with the <b>pageSize</b>, can determine the maximum number of the items in the <xref uid="" data-throw-if-not-resolved="false" data-raw-source="QueryResult"></xref> returned by the <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref>. It must be any positive integer, and if it contains 0, the Device Provisioning Service will ignore it and use a standard page size.</p>
You can use this Object as a standard Iterator, just using the hasNext() and next() in a while
</code> loop, up to the point where the <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.hasNext()" data-throw-if-not-resolved="false" data-raw-source="hasNext()"></xref> return<code>false
</code> . But, keep in mind that the <xref uid="" data-throw-if-not-resolved="false" data-raw-source="QueryResult"></xref> can contain a empty list, even if the <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.hasNext()" data-throw-if-not-resolved="false" data-raw-source="hasNext()"></xref> returned<code>true
</code> . For example, image that you have 10 IndividualEnrollment in the Device Provisioning Service and you created new query with the<code>pageSize
</code> equals 5. The first<code>hasNext()
</code> will return<code>true
</code> , and the first<code>next()
</code> will return a<code>QueryResult
</code> with 5 items. After that you call the<code>hasNext
</code> , which will returns<code>true
</code> . Now, before you get the next page, somebody delete all the IndividualEnrollment, What happened, when you call the<code>next()
</code> , it will return a valid<code>QueryResult
</code> , but the QueryResult.getItems() will return a empty list.</p>
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 continuationToken) providing the stored continuationToken to get the next page.
Method Summary
Modifier and Type
Method and Description
int
getPageSize()
Getter for the pageSize.
PageSize is the maximum number of items in the QueryResult per iteration.
boolean
hasNext()
Getter for hasNext.
It will returntrue
</code> if the query is not finished in the Device Provisioning Service, and another iteration with <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> may return more items. Call <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> after receive a<code>hasNext
</code><code>true
</code> will result in a <xref uid="" data-throw-if-not-resolved="false" data-raw-source="QueryResult"></xref> that can or cannot contains elements. And call <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> after receive a<code>hasNext
</code><code>false
</code> will result in a exception.</p>
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.
PageSize is the maximum number of items in the QueryResult per iteration.
Method Details
getPageSize
public int getPageSize()
Getter for the pageSize.
PageSize is the maximum number of items in the QueryResult per iteration.
Returns:
Anint
</code> with the current pageSize. </p>
hasNext
public boolean hasNext()
Getter for hasNext.
It will returntrue
</code> if the query is not finished in the Device Provisioning Service, and another iteration with <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> may return more items. Call <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> after receive a<code>hasNext
</code><code>true
</code> will result in a <xref uid="" data-throw-if-not-resolved="false" data-raw-source="QueryResult"></xref> that can or cannot contains elements. And call <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.Query.next()" data-throw-if-not-resolved="false" data-raw-source="next()"></xref> after receive a<code>hasNext
</code><code>false
</code> will result in a exception.</p>
Returns:
Theboolean
</code><code>true
</code> if query is not finalize in the Service. </p>
next
public QueryResult next()
Return the next page of result for the query.
Returns:
A QueryResult with the next page of items for the query.
Throws:
NoSuchElementException
- if the query does no have more pages to return.
next
public QueryResult next(String continuationToken)
Return the next page of result for the query using a new continuationToken.
Parameters:
continuationToken
- theString
</code> with the previous continuationToken. It cannot be<code>null
</code> or empty. </p>
Returns:
A QueryResult with the next page of items for the query.
Throws:
NoSuchElementException
- if the query does no have more pages to return.
setPageSize
public void setPageSize(int pageSize)
Setter for the pageSize.
PageSize is the maximum number of items in the QueryResult per iteration.
Parameters:
pageSize
- anint
</code> with the new pageSize. It cannot be negative. The Device Service Client will use its own default pageSize if it is <b>0</b>. </p>
Throws:
IllegalArgumentException
- if the provided pageSize is negative.
Applies to
Azure SDK for Java