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.createEnrollmentGroupRegistrationStatusQuery(QuerySpecification,String,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupRegistrationStatusQuery(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 <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.configs.QueryResult.getItems()" data-throw-if-not-resolved="false" data-raw-source="QueryResult#getItems()"></xref> 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, the getContinuationToken() shall return it. 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.

public class Query
继承
java.lang.Object
Iterator
Query

构造函数

Query(ContractApiHttp contractApiHttp, String targetPath, QuerySpecification querySpecification, int pageSize)

INTERNAL CONSTRUCTOR

Use one of the factories to create a new query.

IndividualEnrollment:

createIndividualEnrollmentQuery(QuerySpecification querySpecification, int pageSize)

EnrollmentGroup:

createEnrollmentGroupQuery(QuerySpecification querySpecification, int pageSize)

RegistrationStatus:

createEnrollmentGroupRegistrationStatusQuery(QuerySpecification querySpecification, String enrollmentGroupId, int pageSize)

Query factories

方法

getPageSize()

Getter for the pageSize.

PageSize is the maximum number of items in the QueryResult per iteration.

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>

next()

Return the next page of result for the query.

next(String continuationToken)

Return the next page of result for the query using a new continuationToken.

setPageSize(int pageSize)

Setter for the pageSize.

PageSize is the maximum number of items in the QueryResult per iteration.

适用于