Partilhar via


QuerySpecificationBuilder Class

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

public class QuerySpecificationBuilder

This is a helper to create a new instance of the QuerySpecification.

This helper will create a query forcing the correct sql format. It expects the SELECT and FROM, but optionally accepts WHERE and GROUP BY. As a result, it will return a QuerySpecification object, accepted by the provisioning service.

Sample:

The follow line will create a QuerySpecification.

QuerySpecification querySpecification = new QuerySpecificationBuilder("*", QuerySpecificationBuilder.FromType.ENROLLMENTS)
             .where("iotHubHostName=`ContosoIoTHub.azure-devices.net`").createSqlQuery();

Will generate the sql query:

{
     "query":"select * from enrollments where iotHubHostName=`ContosoIoTHub.azure-devices.net`"
 }

Constructor Summary

Constructor Description
QuerySpecificationBuilder(String selection, QuerySpecificationBuilder.FromType fromType)

CONSTRUCTOR

Method Summary

Modifier and Type Method and Description
QuerySpecification createSqlQuery()

Creates a new instance of the QuerySpecification using the provided clauses to make the sql query.

QuerySpecificationBuilder groupBy(String groupBy)

Setter for the `groupBy` clause.

QuerySpecificationBuilder where(String where)

Setter for the `where` clause.

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

QuerySpecificationBuilder

public QuerySpecificationBuilder(String selection, QuerySpecificationBuilder.FromType fromType)

CONSTRUCTOR

Creates a new instance of the builder, receiving the mandatory parameters.

Parameters:

selection - the String with the mandatory SELECT clause. It cannot be null or empty.
fromType - the FromType with the mandatory FROM clause. It cannot be null.

Method Details

createSqlQuery

public QuerySpecification createSqlQuery()

Creates a new instance of the QuerySpecification using the provided clauses to make the sql query.

Returns:

A QuerySpecification that contains a sql query with the provided clauses.

groupBy

public QuerySpecificationBuilder groupBy(String groupBy)

Setter for the `groupBy` clause.

Parameters:

groupBy - the String with the new clause group by. It can be null or empty.

Returns:

The same instance of the QuerySpecificationBuilder.

where

public QuerySpecificationBuilder where(String where)

Setter for the `where` clause.

Parameters:

where - the String with the new clause where. It can be null or empty.

Returns:

The same instance of the QuerySpecificationBuilder.

Applies to