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 booleanappendAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath)Appends selection projection for the property which is association.protected java.lang.StringBuilderappendDeleteClause(java.lang.StringBuilder queryString)Append the delete clause.protected voidappendProjectionRowCount(java.lang.StringBuilder queryString, java.lang.String logicalName)Appends a row count projection to the query string.protected java.lang.StringasLiteral(java.lang.Object value)Convert the literal value to it's SQL representation.QueryResultbuildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)Builds an insert statement for the given entity.protected voidbuildJoin(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.QueryResultbuildPagination(Pageable pageable)Encode the pageable.QueryResultbuildQuery(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query)Encode the given query for the passed annotation metadata and query.QueryResultbuildUpdate(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 booleancomputePropertyPaths()Whether property path expressions require computation by the implementation.protected java.lang.StringgetMappedName(NamingStrategy namingStrategy, Association association)Gets the mapped name from the association usingNamingStrategy.protected java.lang.StringgetMappedName(NamingStrategy namingStrategy, PersistentProperty property)Gets the mapped name from the property usingNamingStrategy.protected java.lang.StringgetMappedName(NamingStrategy namingStrategy, java.util.List<Association> associations, PersistentProperty property)Gets the mapped name from for the list of associations and property usingNamingStrategy.protected NamingStrategygetNamingStrategy(PersistentEntity entity)GetsNamingStrategyfor the entity.protected NamingStrategygetNamingStrategy(PersistentPropertyPath propertyPath)GetsNamingStrategyfor the property path.protected booleanisAliasForBatch()Should aliases be used in batch statements.protected voidselectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)Obtain the string that selects all columns from the entity.protected voidselectAllColumnsFromJoinPaths(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer, java.util.Collection<JoinPath> allPaths, java.util.Map<JoinPath,java.lang.String> joinAliasOverride)protected voidtraversePersistentProperties(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:AbstractSqlLikeQueryBuilderConvert the literal value to it's SQL representation.- Overrides:
asLiteralin 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:AbstractSqlLikeQueryBuilderAppends a row count projection to the query string.- Overrides:
appendProjectionRowCountin classSqlQueryBuilder- Parameters:
queryString- The query stringlogicalName- The alias to the table name
-
getNamingStrategy
protected NamingStrategy getNamingStrategy(PersistentEntity entity)
Description copied from class:AbstractSqlLikeQueryBuilderGetsNamingStrategyfor the entity. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategyin classAbstractSqlLikeQueryBuilder- Parameters:
entity- the persistent entity- Returns:
- naming strategy for the entity
-
getNamingStrategy
protected NamingStrategy getNamingStrategy(PersistentPropertyPath propertyPath)
Description copied from class:AbstractSqlLikeQueryBuilderGetsNamingStrategyfor the property path. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategyin 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:AbstractSqlLikeQueryBuilderGets the mapped name from the property usingNamingStrategy.- Overrides:
getMappedNamein 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:AbstractSqlLikeQueryBuilderGets the mapped name from the association usingNamingStrategy.- Overrides:
getMappedNamein 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:AbstractSqlLikeQueryBuilderGets the mapped name from for the list of associations and property usingNamingStrategy.- Overrides:
getMappedNamein 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:AbstractSqlLikeQueryBuilderTraverses persistent properties.- Overrides:
traversePersistentPropertiesin 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:QueryBuilderEncode the given query for the passed annotation metadata and query.- Specified by:
buildQueryin interfaceQueryBuilder- Overrides:
buildQueryin 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:
selectAllColumnsFromJoinPathsin classSqlQueryBuilder
-
appendAssociationProjection
protected boolean appendAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath)
Description copied from class:AbstractSqlLikeQueryBuilderAppends selection projection for the property which is association.- Overrides:
appendAssociationProjectionin 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:AbstractSqlLikeQueryBuilderObtain the string that selects all columns from the entity.- Overrides:
selectAllColumnsin 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:SqlQueryBuilderBuilds join, adding fields and criteria.- Overrides:
buildJoinin 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:AbstractSqlLikeQueryBuilderAppend the delete clause.- Overrides:
appendDeleteClausein classAbstractSqlLikeQueryBuilder- Parameters:
queryString- The query string- Returns:
- The delete clause
-
isAliasForBatch
protected boolean isAliasForBatch()
Description copied from class:AbstractSqlLikeQueryBuilderShould aliases be used in batch statements.- Overrides:
isAliasForBatchin classSqlQueryBuilder- Returns:
- True if they should
-
computePropertyPaths
protected boolean computePropertyPaths()
Description copied from class:AbstractSqlLikeQueryBuilderWhether 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:
computePropertyPathsin 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:QueryBuilderBuilds an insert statement for the given entity.- Specified by:
buildInsertin interfaceQueryBuilder- Overrides:
buildInsertin 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:QueryBuilderEncode the given query into the encoded query instance.- Specified by:
buildUpdatein interfaceQueryBuilder- Overrides:
buildUpdatein 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:QueryBuilderEncode the pageable.- Specified by:
buildPaginationin interfaceQueryBuilder- Overrides:
buildPaginationin classSqlQueryBuilder- Parameters:
pageable- The pageable- Returns:
- The encoded query
-
-