Query Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.provisioning.service.Query

Implements

java.util.Iterator

public class Query
implements java.util.Iterator

The query iterator.

The Query iterator is the result of the query factory for

| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **IndividualEnrollment:** | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createIndividualEnrollmentQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification, int)"></xref>                                                    |
| **EnrollmentGroup:**      | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification, int)"></xref>                                                              |
| **RegistrationStatus:**   | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupRegistrationStatusQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,java.lang.String,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupRegistrationStatusQuery(QuerySpecification, String, int)"></xref> |

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

Constructor Summary

Modifier Constructor Description
protected Query(ContractApiHttp contractApiHttp, String targetPath, QuerySpecification querySpecification, int pageSize)

INTERNAL CONSTRUCTOR

Method Summary

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.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

Query

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

INTERNAL CONSTRUCTOR

Use one of the factories to create a new query.

| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **IndividualEnrollment:** | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createIndividualEnrollmentQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification, int)"></xref>                                                    |
| **EnrollmentGroup:**      | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification, int)"></xref>                                                              |
| **RegistrationStatus:**   | <xref uid="com.microsoft.azure.sdk.iot.provisioning.service.ProvisioningServiceClient.createEnrollmentGroupRegistrationStatusQuery(com.microsoft.azure.sdk.iot.provisioning.service.configs.QuerySpecification,java.lang.String,int)" data-throw-if-not-resolved="false" data-raw-source="ProvisioningServiceClient#createEnrollmentGroupRegistrationStatusQuery(QuerySpecification, String, int)"></xref> |

Parameters:

contractApiHttp - the ContractApiHttp that send request messages to the Device Provisioning Service. It cannot be null.
targetPath - the String with the path that will be part of the URL in the rest API. It cannot be null.
querySpecification - the QuerySpecification with the SQL query. It cannot be null.
pageSize - the int with the maximum number of items per iteration. It cannot be negative.

Method Details

getPageSize

public int getPageSize()

Getter for the pageSize.

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

Returns:

An int with the current pageSize.

hasNext

public boolean hasNext()

Getter for 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.

Returns:

Theboolean true if query is not finalize in the Service.

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.

next

public QueryResult next(String continuationToken)

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

Parameters:

continuationToken - the String with the previous continuationToken. It cannot be null or empty.

Returns:

A QueryResult with the next page of items for the query.

setPageSize

public void setPageSize(int pageSize)

Setter for the pageSize.

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

Parameters:

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.

Applies to