com.microsoft.azure.sdk.iot.provisioning.service.Query类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中com.microsoft.azure.sdk.iot.provisioning.service.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:com.microsoft.azure.sdk.iot.provisioning.service.Query
类名称:Query

Query介绍

[英]The query iterator.

The Query iterator is the result of the query factory for

Query factoriesIndividualEnrollment:ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification,int)EnrollmentGroup:ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification,int)RegistrationStatus:ProvisioningServiceClient#createEnrollmentGroupRegistrationStatusQuery(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, the QueryResult#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) providing the stored continuationToken to get the next page.
[中]

代码示例

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 * Return the next page of result for the query using a new continuationToken.
 *
 * @param continuationToken the {@code String} with the previous continuationToken. It cannot be {@code null} or empty.
 * @return A {@link QueryResult} with the next page of items for the query.
 * @throws NoSuchElementException if the query does no have more pages to return.
 */
public QueryResult next(String continuationToken)
{
  /* SRS_QUERY_21_018: [The next shall throw NoSuchElementException if the provided continuationToken is null or empty.] */
  if(Tools.isNullOrEmpty(continuationToken))
  {
    throw new NoSuchElementException("There is no Continuation Token to get pending elements,");
  }
  /* SRS_QUERY_21_019: [The next shall store the provided continuationToken.] */
  this.continuationToken = continuationToken;
  /* SRS_QUERY_21_020: [The next shall return the next page of results by calling the next().] */
  return next();
}

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 * Create a new enrollmentGroup query.
 *
 * @see ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification)
 * @see ProvisioningServiceClient#createEnrollmentGroupQuery(QuerySpecification, int)
 *
 * @param querySpecification is a {@code String} with the SQL query specification. It cannot be {@code null}.
 * @param pageSize the {@code int} with the maximum number of items per iteration. It can be 0 for default, but not negative.
 * @return A {@link Query} iterator.
 * @throws IllegalArgumentException if the provided parameter is not correct.
 */
Query createQuery(QuerySpecification querySpecification, int pageSize)
{
  /* SRS_ENROLLMENT_GROUP_MANAGER_21_038: [The createQuery shall throw IllegalArgumentException if the provided querySpecification is null.] */
  if(querySpecification == null)
  {
    throw new IllegalArgumentException("querySpecification cannot be null.");
  }
  /* SRS_ENROLLMENT_GROUP_MANAGER_21_039: [The createQuery shall throw IllegalArgumentException if the provided pageSize is negative.] */
  if(pageSize < 0)
  {
    throw new IllegalArgumentException("pageSize cannot be negative.");
  }
  /* SRS_ENROLLMENT_GROUP_MANAGER_21_040: [The createQuery shall create Query iterator with a Http path `enrollmentGroups`.] */
  String targetPath = EnrollmentGroupManager.getEnrollmentGroupsPath();
  /* SRS_ENROLLMENT_GROUP_MANAGER_21_041: [The createQuery shall create and return a new instance of the Query iterator.] */
  return new Query(contractApiHttp, targetPath, querySpecification, pageSize);
}

代码示例来源:origin: Azure/azure-iot-sdk-java

Query query = provisioningServiceClient.createIndividualEnrollmentQuery(querySpecification, QUERY_PAGE_SIZE);
while(query.hasNext())
  QueryResult queryResult = query.next();
  System.out.println(queryResult);

代码示例来源:origin: Azure/azure-iot-sdk-java

Query query = provisioningServiceClient.createEnrollmentGroupQuery(querySpecification);
while(query.hasNext())
  QueryResult queryResult = query.next();
  System.out.println(queryResult);

代码示例来源:origin: Azure/azure-iot-sdk-java

Query query = provisioningServiceClient.createIndividualEnrollmentQuery(querySpecification);
while(query.hasNext())
  QueryResult queryResult = query.next();
  System.out.println(queryResult);

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 * Create a new individualEnrollment query.
 *
 * @see ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification)
 * @see ProvisioningServiceClient#createIndividualEnrollmentQuery(QuerySpecification, int)
 *
 * @param querySpecification is a {@code String} with the SQL query specification. It cannot be {@code null}.
 * @param pageSize the {@code int} with the maximum number of items per iteration. It can be 0 for default, but not negative.
 * @return A {@link Query} iterator.
 * @throws IllegalArgumentException if the provided parameter is not correct.
 */
Query createQuery(QuerySpecification querySpecification, int pageSize)
{
  /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_038: [The createQuery shall throw IllegalArgumentException if the provided querySpecification is null.] */
  if(querySpecification == null)
  {
    throw new IllegalArgumentException("querySpecification cannot be null.");
  }
  /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_039: [The createQuery shall throw IllegalArgumentException if the provided pageSize is negative.] */
  if(pageSize < 0)
  {
    throw new IllegalArgumentException("pageSize cannot be negative.");
  }
  /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_040: [The createQuery shall create Query iterator with a Http path `enrollments`.] */
  String targetPath = IndividualEnrollmentManager.getEnrollmentsPath();
  /* SRS_INDIVIDUAL_ENROLLMENT_MANAGER_21_041: [The createQuery shall create and return a new instance of the Query iterator.] */
  return new Query(contractApiHttp, targetPath, querySpecification, pageSize);
}

代码示例来源:origin: Azure/azure-iot-sdk-java

return new Query(contractApiHttp, targetPath, querySpecification, pageSize);

相关文章

微信公众号

最新文章

更多