Class CosmosSqlQueryBuilder
- java.lang.Object
-
- io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
-
- io.micronaut.data.model.query.builder.sql.SqlQueryBuilder
-
- io.micronaut.data.document.model.query.builder.CosmosSqlQueryBuilder
-
- All Implemented Interfaces:
QueryBuilder
,java.lang.annotation.Annotation
public final class CosmosSqlQueryBuilder extends SqlQueryBuilder
The Azure Cosmos DB sql query builder.- Since:
- 3.9.0
- Author:
- radovanradic
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
AbstractSqlLikeQueryBuilder.CriteriaContext, AbstractSqlLikeQueryBuilder.CriterionHandler<T extends QueryModel.Criterion>, AbstractSqlLikeQueryBuilder.Placeholder, AbstractSqlLikeQueryBuilder.QueryPosition, AbstractSqlLikeQueryBuilder.QueryPropertyPath, AbstractSqlLikeQueryBuilder.QueryState
-
-
Field Summary
-
Fields inherited from class io.micronaut.data.model.query.builder.sql.SqlQueryBuilder
DEFAULT_POSITIONAL_PARAMETER_MARKER, SQL_SERVER_FOR_UPDATE_CLAUSE, STANDARD_FOR_UPDATE_CLAUSE
-
Fields inherited from class io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
ALIAS_REPLACE, ALIAS_REPLACE_QUOTED, AND, AS_CLAUSE, AVG, CLOSE_BRACKET, COMMA, COUNT_DISTINCT, DELETE_CLAUSE, DISTINCT, DOT, EQUALS, EQUALS_FALSE, EQUALS_TRUE, FROM_CLAUSE, FUNCTION_COUNT, GREATER_THAN, GREATER_THAN_OR_EQUALS, IS_EMPTY, IS_NOT_EMPTY, IS_NOT_NULL, LESS_THAN, LESS_THAN_OR_EQUALS, LOGICAL_AND, LOGICAL_OR, MAX, MIN, NOT, NOT_EQUALS, OPEN_BRACKET, OR, ORDER_BY_CLAUSE, queryHandlers, SELECT_CLAUSE, SPACE, SUM, UPDATE_CLAUSE, WHERE_CLAUSE
-
Fields inherited from interface io.micronaut.data.model.query.builder.QueryBuilder
IN_VARIABLES_PATTERN, VARIABLE_PATTERN
-
-
Constructor Summary
Constructors Constructor Description CosmosSqlQueryBuilder()
Default constructor.CosmosSqlQueryBuilder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
appendAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath)
Appends selection projection for the property which is association.protected java.lang.StringBuilder
appendDeleteClause(java.lang.StringBuilder queryString)
Append the delete clause.protected void
appendProjectionRowCount(java.lang.StringBuilder queryString, java.lang.String logicalName)
Appends a row count projection to the query string.protected java.lang.String
asLiteral(java.lang.Object value)
Convert the literal value to it's SQL representation.QueryResult
buildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)
Builds an insert statement for the given entity.protected void
buildJoin(java.lang.String joinType, java.lang.StringBuilder sb, AbstractSqlLikeQueryBuilder.QueryState queryState, java.util.List<Association> joinAssociationsPath, java.lang.String joinAlias, Association association, PersistentEntity associatedEntity, PersistentEntity associationOwner, java.lang.String currentJoinAlias)
Builds join, adding fields and criteria.QueryResult
buildPagination(Pageable pageable)
Encode the pageable.QueryResult
buildQuery(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query)
Encode the given query for the passed annotation metadata and query.QueryResult
buildUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query, java.util.Map<java.lang.String,java.lang.Object> propertiesToUpdate)
Encode the given query into the encoded query instance.protected boolean
computePropertyPaths()
Whether property path expressions require computation by the implementation.protected java.lang.String
getMappedName(NamingStrategy namingStrategy, Association association)
Gets the mapped name from the association usingNamingStrategy
.protected java.lang.String
getMappedName(NamingStrategy namingStrategy, PersistentProperty property)
Gets the mapped name from the property usingNamingStrategy
.protected java.lang.String
getMappedName(NamingStrategy namingStrategy, java.util.List<Association> associations, PersistentProperty property)
Gets the mapped name from for the list of associations and property usingNamingStrategy
.protected NamingStrategy
getNamingStrategy(PersistentEntity entity)
GetsNamingStrategy
for the entity.protected NamingStrategy
getNamingStrategy(PersistentPropertyPath propertyPath)
GetsNamingStrategy
for the property path.protected boolean
isAliasForBatch()
Should aliases be used in batch statements.protected void
selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)
Obtain the string that selects all columns from the entity.protected void
selectAllColumnsFromJoinPaths(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer, java.util.Collection<JoinPath> allPaths, java.util.Map<JoinPath,java.lang.String> joinAliasOverride)
protected void
traversePersistentProperties(java.util.List<Association> associations, PersistentProperty property, java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumerProperty)
Traverses persistent properties.-
Methods inherited from class io.micronaut.data.model.query.builder.sql.SqlQueryBuilder
annotationType, appendForUpdate, appendUpdateSetParameter, buildBatchCreateTableStatement, buildBatchDropTableStatement, buildCreateTableStatements, buildDropTableStatements, buildJoin, buildJoinTableInsert, concat, dialect, escapeQueries, formatParameter, getAliasName, getColumnName, getDialect, getTableAsKeyword, getTableName, isExpandEmbedded, isForeignKeyWithJoinTable, positionalParameterFormat, positionalParameterName, positionalParameterPattern, quote, resolveJoinType, selectAllColumns, selectAutoStrategy, shouldAliasProjections, shouldEscape, supportsForUpdate
-
Methods inherited from class io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
addCriterionHandler, appendOrder, appendPropertyRef, appendTransformed, asLiterals, asPath, buildDelete, buildOrderBy, buildOrderBy, buildSelect, buildUpdate, buildWhereClause, getAliasName, getColumnAlias, getDataTransformerReadValue, getDataTransformerWriteValue, getPathOnlyAliasName, getUnescapedTableName, handleSubQuery, newBindingContext, traversePersistentProperties, traversePersistentProperties, traversePersistentProperties
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.data.model.query.builder.QueryBuilder
buildDelete, buildDelete, buildOrderBy, buildQuery, buildUpdate, buildUpdate, buildUpdate
-
-
-
-
Method Detail
-
asLiteral
protected java.lang.String asLiteral(java.lang.Object value)
Description copied from class:AbstractSqlLikeQueryBuilder
Convert the literal value to it's SQL representation.- Overrides:
asLiteral
in classSqlQueryBuilder
- Parameters:
value
- The literal value- Returns:
- converter value
-
appendProjectionRowCount
protected void appendProjectionRowCount(java.lang.StringBuilder queryString, java.lang.String logicalName)
Description copied from class:AbstractSqlLikeQueryBuilder
Appends a row count projection to the query string.- Overrides:
appendProjectionRowCount
in classSqlQueryBuilder
- Parameters:
queryString
- The query stringlogicalName
- The alias to the table name
-
getNamingStrategy
protected NamingStrategy getNamingStrategy(PersistentEntity entity)
Description copied from class:AbstractSqlLikeQueryBuilder
GetsNamingStrategy
for the entity. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategy
in classAbstractSqlLikeQueryBuilder
- Parameters:
entity
- the persistent entity- Returns:
- naming strategy for the entity
-
getNamingStrategy
protected NamingStrategy getNamingStrategy(PersistentPropertyPath propertyPath)
Description copied from class:AbstractSqlLikeQueryBuilder
GetsNamingStrategy
for the property path. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategy
in classAbstractSqlLikeQueryBuilder
- Parameters:
propertyPath
- the property path representation- Returns:
- naming strategy for the property path
-
getMappedName
protected java.lang.String getMappedName(NamingStrategy namingStrategy, PersistentProperty property)
Description copied from class:AbstractSqlLikeQueryBuilder
Gets the mapped name from the property usingNamingStrategy
.- Overrides:
getMappedName
in classAbstractSqlLikeQueryBuilder
- Parameters:
namingStrategy
- the naming strategy being usedproperty
- the persistent property- Returns:
- the mapped name for the property
-
getMappedName
protected java.lang.String getMappedName(NamingStrategy namingStrategy, Association association)
Description copied from class:AbstractSqlLikeQueryBuilder
Gets the mapped name from the association usingNamingStrategy
.- Overrides:
getMappedName
in classAbstractSqlLikeQueryBuilder
- Parameters:
namingStrategy
- the naming strategy being usedassociation
- the associatioon- Returns:
- the mapped name for the association
-
getMappedName
protected java.lang.String getMappedName(NamingStrategy namingStrategy, java.util.List<Association> associations, PersistentProperty property)
Description copied from class:AbstractSqlLikeQueryBuilder
Gets the mapped name from for the list of associations and property usingNamingStrategy
.- Overrides:
getMappedName
in classAbstractSqlLikeQueryBuilder
- Parameters:
namingStrategy
- the naming strategyassociations
- the association listproperty
- the property- Returns:
- the mappen name for the list of associations and property using given naming strategy
-
traversePersistentProperties
protected void traversePersistentProperties(java.util.List<Association> associations, PersistentProperty property, java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumerProperty)
Description copied from class:AbstractSqlLikeQueryBuilder
Traverses persistent properties.- Overrides:
traversePersistentProperties
in classAbstractSqlLikeQueryBuilder
- Parameters:
associations
- The association list being traversed with the propertyproperty
- The persistent propertyconsumerProperty
- The function to invoke on every property
-
buildQuery
public QueryResult buildQuery(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query)
Description copied from interface:QueryBuilder
Encode the given query for the passed annotation metadata and query.- Specified by:
buildQuery
in interfaceQueryBuilder
- Overrides:
buildQuery
in classAbstractSqlLikeQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The query model- Returns:
- The query result
-
selectAllColumnsFromJoinPaths
@Internal protected void selectAllColumnsFromJoinPaths(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer, java.util.Collection<JoinPath> allPaths, @Nullable java.util.Map<JoinPath,java.lang.String> joinAliasOverride)
- Overrides:
selectAllColumnsFromJoinPaths
in classSqlQueryBuilder
-
appendAssociationProjection
protected boolean appendAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath)
Description copied from class:AbstractSqlLikeQueryBuilder
Appends selection projection for the property which is association.- Overrides:
appendAssociationProjection
in classAbstractSqlLikeQueryBuilder
- Parameters:
queryState
- the query statequeryString
- the query string builderproperty
- the persistent propertypropertyPath
- the persistent property path- Returns:
- true if association projection is appended, otherwise false
-
selectAllColumns
protected void selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)
Description copied from class:AbstractSqlLikeQueryBuilder
Obtain the string that selects all columns from the entity.- Overrides:
selectAllColumns
in classSqlQueryBuilder
- Parameters:
queryState
- The query state
-
buildJoin
protected void buildJoin(java.lang.String joinType, java.lang.StringBuilder sb, AbstractSqlLikeQueryBuilder.QueryState queryState, java.util.List<Association> joinAssociationsPath, java.lang.String joinAlias, Association association, PersistentEntity associatedEntity, PersistentEntity associationOwner, java.lang.String currentJoinAlias)
Description copied from class:SqlQueryBuilder
Builds join, adding fields and criteria.- Overrides:
buildJoin
in classSqlQueryBuilder
- Parameters:
joinType
- the join typesb
- string builder that join will be added toqueryState
- the query statejoinAssociationsPath
- the list of associationsjoinAlias
- the join aliasassociation
- the associationassociatedEntity
- the associated entityassociationOwner
- the association ownercurrentJoinAlias
- the current join alias
-
appendDeleteClause
protected java.lang.StringBuilder appendDeleteClause(java.lang.StringBuilder queryString)
Description copied from class:AbstractSqlLikeQueryBuilder
Append the delete clause.- Overrides:
appendDeleteClause
in classAbstractSqlLikeQueryBuilder
- Parameters:
queryString
- The query string- Returns:
- The delete clause
-
isAliasForBatch
protected boolean isAliasForBatch()
Description copied from class:AbstractSqlLikeQueryBuilder
Should aliases be used in batch statements.- Overrides:
isAliasForBatch
in classSqlQueryBuilder
- Returns:
- True if they should
-
computePropertyPaths
protected boolean computePropertyPaths()
Description copied from class:AbstractSqlLikeQueryBuilder
Whether property path expressions require computation by the implementation. In a certain query dialects property paths are supported (such as JPA-QL where you can do select foo.bar) whilst for explicit SQL queries paths like this have to be computed into aliases / column name references.- Overrides:
computePropertyPaths
in classSqlQueryBuilder
- Returns:
- True if property path computation is required.
-
buildInsert
public QueryResult buildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)
Description copied from interface:QueryBuilder
Builds an insert statement for the given entity.- Specified by:
buildInsert
in interfaceQueryBuilder
- Overrides:
buildInsert
in classSqlQueryBuilder
- Parameters:
repositoryMetadata
- The repository annotation metadataentity
- The entity- Returns:
- The insert statement or null if the implementation doesn't require insert statements
-
buildUpdate
public QueryResult buildUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query, java.util.Map<java.lang.String,java.lang.Object> propertiesToUpdate)
Description copied from interface:QueryBuilder
Encode the given query into the encoded query instance.- Specified by:
buildUpdate
in interfaceQueryBuilder
- Overrides:
buildUpdate
in classAbstractSqlLikeQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The querypropertiesToUpdate
- The property names to update- Returns:
- The encoded query
-
buildPagination
@NonNull public QueryResult buildPagination(@NonNull Pageable pageable)
Description copied from interface:QueryBuilder
Encode the pageable.- Specified by:
buildPagination
in interfaceQueryBuilder
- Overrides:
buildPagination
in classSqlQueryBuilder
- Parameters:
pageable
- The pageable- Returns:
- The encoded query
-
-