public class QuerySpecificationBuilder extends Object
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`"
}
Modifier and Type | Class and Description |
---|---|
static class |
QuerySpecificationBuilder.FromType
From clause for Query
|
Constructor and Description |
---|
QuerySpecificationBuilder(String selection,
QuerySpecificationBuilder.FromType fromType)
CONSTRUCTOR
|
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.
|
public QuerySpecificationBuilder(String selection, QuerySpecificationBuilder.FromType fromType)
Creates a new instance of the builder, receiving the mandatory parameters.
selection
- the String
with the mandatory SELECT clause. It cannot be null
or empty.fromType
- the QuerySpecificationBuilder.FromType
with the mandatory FROM clause. It cannot be null
.IllegalArgumentException
- if one of the provided clauses is invalid.public QuerySpecificationBuilder where(String where)
where
- the String
with the new clause `where`. It can be null
or empty.QuerySpecificationBuilder
.public QuerySpecificationBuilder groupBy(String groupBy)
groupBy
- the String
with the new clause `group by`. It can be null
or empty.QuerySpecificationBuilder
.public QuerySpecification createSqlQuery()
QuerySpecification
using the provided clauses to make the sql query.QuerySpecification
that contains a sql query with the provided clauses.Copyright © 2022. All rights reserved.