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();

</code></pre></p>

Will generate the sql query:

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

}

</code></pre></p>

Constructor Summary

Constructor Description
QuerySpecificationBuilder(String selection, FromType fromType)

CONSTRUCTOR

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

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.

Constructor Details

QuerySpecificationBuilder

public QuerySpecificationBuilder(String selection, FromType fromType)

CONSTRUCTOR

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

Parameters:

selection -

theString 

</code> with the mandatory SELECT clause. It cannot be<code>null 

</code> or empty. </p>

fromType -

the QuerySpecificationBuilder.FromType with the mandatory FROM clause. It cannot benull 

</code> . </p>

Throws:

IllegalArgumentException - if one of the provided clauses is invalid.

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 -

theString 

</code> with the new clause `group by`. It can be<code>null 

</code> or empty. </p>

Returns:

The same instance of theQuerySpecificationBuilder 

</code> . </p>

where

public QuerySpecificationBuilder where(String where)

Setter for the `where` clause.

Parameters:

where -

theString 

</code> with the new clause `where`. It can be<code>null 

</code> or empty. </p>

Returns:

The same instance of theQuerySpecificationBuilder 

</code> . </p>

Applies to