Class AbstractSqlLikeQueryBuilder
java.lang.Object
io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
- All Implemented Interfaces:
QueryBuilder
- Direct Known Subclasses:
JpaQueryBuilder
,SqlQueryBuilder
An abstract class for builders that build SQL-like queries.
- Since:
- 1.0.0
- Author:
- graemerocher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface
A criterion context.protected static interface
A criterion handler.static final class
Represents a placeholder in query.protected static enum
protected class
Represents a path to a property.protected final class
The state of the query. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final char
protected static final char
protected static final String
protected static final String
protected static final String
protected static final char
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final char
protected static final String
static final String
protected final Map<Class,
AbstractSqlLikeQueryBuilder.CriterionHandler> protected static final String
protected static final String
protected static final char
protected static final String
protected static final String
protected static final String
Fields inherited from interface io.micronaut.data.model.query.builder.QueryBuilder
VARIABLE_PATTERN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends QueryModel.Criterion>
voidaddCriterionHandler
(Class<T> clazz, AbstractSqlLikeQueryBuilder.CriterionHandler<T> handler) Adds criterion handler.protected boolean
appendAssociationProjection
(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath, String columnAlias) Appends selection projection for the property which is association.protected void
appendCompoundAssociationProjection
(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, Association association, PersistentPropertyPath propertyPath, String columnAlias) Appends the compound (part of entity or DTO) association projection.protected void
appendCompoundPropertyProjection
(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath, String columnAlias) Appends the compound (part of entity or DTO) property projection.protected @NonNull StringBuilder
appendDeleteClause
(StringBuilder queryString) Append the delete clause.protected void
appendForUpdate
(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition, QueryModel query, StringBuilder queryBuilder) Adds "forUpdate" pisimmistic locking.protected void
appendOrder
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query, AbstractSqlLikeQueryBuilder.QueryState queryState) Appends order to the query.protected abstract void
appendProjectionRowCount
(StringBuilder queryString, String logicalName) Appends a row count projection to the query string.protected abstract void
appendProjectionRowCountDistinct
(StringBuilder queryString, AbstractSqlLikeQueryBuilder.QueryState queryState, PersistentEntity entity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, String logicalName) Appends a row count distinct projection to the query string.protected final void
appendProperty
(StringBuilder sb, List<Association> associations, PersistentProperty property, NamingStrategy namingStrategy, String tableAlias, boolean escape) protected final void
appendPropertyProjection
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, StringBuilder sb, AbstractSqlLikeQueryBuilder.QueryPropertyPath propertyPath, String columnAlias) protected void
appendPropertyRef
(StringBuilder sb, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, AbstractSqlLikeQueryBuilder.QueryPropertyPath propertyPath) Appends property to the sql string builder.protected void
appendTransformed
(StringBuilder sb, String transformed, Runnable appendParameter) Appends custom query part.protected void
appendUpdateSetParameter
(StringBuilder sb, String alias, PersistentProperty prop, Runnable appendParameter) Appends the SET=? call to the query string.protected @NonNull String
Convert the literal value to it's SQL representation.protected void
asLiterals
(StringBuilder sb, @Nullable Object value) Appends values as literals to the sql query builder.protected String
asPath
(List<Association> associations, PersistentProperty property) Join associations and property as path.protected final AbstractSqlLikeQueryBuilder.QueryPropertyPath
asQueryPropertyPath
(String tableAlias, PersistentProperty persistentProperty) protected String
buildAdditionalWhereClause
(AbstractSqlLikeQueryBuilder.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds additional where clause if there isWhere
annotation on the entity.protected final String
buildAdditionalWhereString
(JoinPath joinPath, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds WHERE clause based onWhere
annotation on the metadata.protected String
buildAdditionalWhereString
(String alias, PersistentEntity entity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds WHERE clause for the entity and given alias ifIgnoreWhere
is not present.buildDelete
(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query) Encode the given query into the encoded query instance.protected abstract String[]
buildJoin
(String alias, JoinPath joinPath, String joinType, StringBuilder stringBuilder, Map<String, String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState) Build a join expression for the given alias, association, join type and builder.@NonNull QueryResult
buildOrderBy
(@NonNull PersistentEntity entity, @NonNull Sort sort) Encode the given query into the encoded query instance.@NonNull QueryResult
buildOrderBy
(String query, @NonNull PersistentEntity entity, @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull Sort sort) Deprecated, for removal: This API element is subject to removal in a future version.@NonNull QueryResult
buildOrderBy
(String query, @NonNull PersistentEntity entity, @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull Sort sort, boolean nativeQuery) Encode the given query into the encoded query instance.buildQuery
(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query) Encode the given query for the passed annotation metadata and query.protected void
buildSelect
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, List<QueryModel.Projection> projectionList, String tableAlias, PersistentEntity entity) Build select statement.buildUpdate
(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query, @NonNull List<String> propertiesToUpdate) Encode the given query into the encoded query instance.buildUpdate
(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query, @NonNull Map<String, Object> propertiesToUpdate) Encode the given query into the encoded query instance.protected void
buildWhereClause
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel.Junction criteria, AbstractSqlLikeQueryBuilder.QueryState queryState) Builds where clause.protected void
If and whenEntityRepresentation
annotation with JSON type is used for the repository method but dialect does not support JSON entity representations this will throwIllegalArgumentException
.protected abstract boolean
Whether property path expressions require computation by the implementation.protected void
concat
(StringBuilder writer, Collection<Runnable> partsWriters) protected abstract AbstractSqlLikeQueryBuilder.Placeholder
formatParameter
(int index) Format the parameter at the given index.protected String
getAliasName
(PersistentEntity entity) Get an alias name for the given entity.getAliasName
(JoinPath joinPath) Get the alias name.protected final String
getColumnAlias
(PersistentProperty property) Gets column alias if defined as alias field on MappedProperty annotation on the mapping field.protected abstract String
getColumnName
(PersistentProperty persistentProperty) Get the column name for the given property.getDataTransformerReadValue
(String alias, PersistentProperty prop) Returns transformed value if the data transformer id defined.getDataTransformerWriteValue
(String alias, PersistentProperty prop) Returns transformed value if the data transformer id defined.protected Dialect
Get dialect.protected @NonNull String
getMappedName
(@NonNull NamingStrategy namingStrategy, @NonNull Association association) Gets the mapped name from the association usingNamingStrategy
.protected @NonNull String
getMappedName
(@NonNull NamingStrategy namingStrategy, @NonNull PersistentProperty property) Gets the mapped name from the property usingNamingStrategy
.protected @NonNull String
getMappedName
(@NonNull NamingStrategy namingStrategy, @NonNull List<Association> associations, @NonNull 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 @NonNull String
getPathOnlyAliasName
(JoinPath joinPath) Get the alias name for just the join path.protected String
Get the AS keyword to use for table aliases.protected abstract String
getTableName
(PersistentEntity entity) Get the table name for the given entity.protected String
Get the table name for the given entity.protected void
handleSubQuery
(AbstractSqlLikeQueryBuilder.CriteriaContext ctx, QueryModel.SubqueryCriterion subqueryCriterion, String comparisonExpression) For handling subqueries.protected abstract boolean
isAliasForBatch
(PersistentEntity persistentEntity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Should aliases be used in batch statements.protected boolean
Should embedded queries by expanded by the implementation.protected boolean
isJsonEntity
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity) Checks whetherEntityRepresentation
annotation with JSON type is used for the repository method.protected BindingParameter.BindingContext
newBindingContext
(@Nullable PersistentPropertyPath ref) Creates new binding parameter context.protected String
Quote a column name for the dialect.abstract String
Resolves the join type.protected final String
resolveWhereForAnnotationMetadata
(String alias, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Resolves where clause if there isWhere
annotation on the entity.protected abstract void
selectAllColumns
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, String alias, StringBuilder queryBuffer) Selects all columns for the given entity and alias.protected abstract void
selectAllColumns
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer) Obtain the string that selects all columns from the entity.protected void
selectAllColumns
(PersistentEntity entity, String alias, StringBuilder queryBuffer) Selects all columns for the given entity and alias.protected void
selectAllColumnsFromJoinPaths
(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer, Collection<JoinPath> allPaths, @Nullable Map<JoinPath, String> joinAliasOverride) protected boolean
shouldEscape
(@NonNull PersistentEntity entity) Whether queries should be escaped for the given entity.protected void
traversePersistentProperties
(PersistentEntity persistentEntity, boolean includeIdentity, boolean includeVersion, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.protected void
traversePersistentProperties
(PersistentEntity persistentEntity, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.protected void
traversePersistentProperties
(PersistentProperty property, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.protected void
traversePersistentProperties
(List<Association> associations, PersistentProperty property, BiConsumer<List<Association>, PersistentProperty> consumerProperty) Traverses persistent properties.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, buildInsert, buildInsertReturning, buildPagination, buildUpdate, buildUpdate, shouldAliasProjections, supportsForUpdate
-
Field Details
-
ORDER_BY_CLAUSE
- See Also:
-
SELECT_CLAUSE
- See Also:
-
AS_CLAUSE
- See Also:
-
FROM_CLAUSE
- See Also:
-
WHERE_CLAUSE
- See Also:
-
COMMA
protected static final char COMMA- See Also:
-
CLOSE_BRACKET
protected static final char CLOSE_BRACKET- See Also:
-
OPEN_BRACKET
protected static final char OPEN_BRACKET- See Also:
-
SPACE
protected static final char SPACE- See Also:
-
DOT
protected static final char DOT- See Also:
-
NOT
- See Also:
-
AND
- See Also:
-
LOGICAL_AND
- See Also:
-
UPDATE_CLAUSE
- See Also:
-
DELETE_CLAUSE
- See Also:
-
RETURNING
- See Also:
-
OR
- See Also:
-
LOGICAL_OR
- See Also:
-
FUNCTION_COUNT
- See Also:
-
AVG
- See Also:
-
DISTINCT
- See Also:
-
SUM
- See Also:
-
MIN
- See Also:
-
MAX
- See Also:
-
COUNT_DISTINCT
- See Also:
-
IS_NOT_NULL
- See Also:
-
IS_EMPTY
- See Also:
-
IS_NOT_EMPTY
- See Also:
-
IS_NULL
- See Also:
-
EQUALS_TRUE
- See Also:
-
EQUALS_FALSE
- See Also:
-
GREATER_THAN_OR_EQUALS
- See Also:
-
LESS_THAN_OR_EQUALS
- See Also:
-
LESS_THAN
- See Also:
-
GREATER_THAN
- See Also:
-
EQUALS
- See Also:
-
NOT_EQUALS
- See Also:
-
ALIAS_REPLACE_QUOTED
- See Also:
-
JSON_COLUMN
- See Also:
-
CANNOT_QUERY_ON_ID_WITH_ENTITY_THAT_HAS_NO_ID
- See Also:
-
queryHandlers
-
-
Constructor Details
-
AbstractSqlLikeQueryBuilder
public AbstractSqlLikeQueryBuilder()
-
-
Method Details
-
getDialect
Get dialect.- Returns:
- dialect
-
asLiterals
Appends values as literals to the sql query builder.- Parameters:
sb
- the sql string buildervalue
- the value to be added
-
asLiteral
Convert the literal value to it's SQL representation.- Parameters:
value
- The literal value- Returns:
- converter value
-
asQueryPropertyPath
protected final AbstractSqlLikeQueryBuilder.QueryPropertyPath asQueryPropertyPath(String tableAlias, PersistentProperty persistentProperty) -
concat
- Parameters:
writer
- The writerpartsWriters
- The parts writers
-
buildQuery
public QueryResult buildQuery(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull QueryModel query) Description copied from interface:QueryBuilder
Encode the given query for the passed annotation metadata and query.- Specified by:
buildQuery
in interfaceQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The query model- Returns:
- The query result
-
getTableName
Get the table name for the given entity.- Parameters:
entity
- The entity- Returns:
- The table name
-
getUnescapedTableName
Get the table name for the given entity.- Parameters:
entity
- The entity- Returns:
- The table name
-
getAliasName
Get an alias name for the given entity.- Parameters:
entity
- The entity- Returns:
- The alias name
-
getAliasName
Get the alias name.- Parameters:
joinPath
- The join path- Returns:
- The alias
-
getPathOnlyAliasName
Get the alias name for just the join path.- Parameters:
joinPath
- The join path- Returns:
- The alias
-
buildJoin
protected abstract String[] buildJoin(String alias, JoinPath joinPath, String joinType, StringBuilder stringBuilder, Map<String, String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState) Build a join expression for the given alias, association, join type and builder.- Parameters:
alias
- The aliasjoinPath
- The join pathjoinType
- The join type stringstringBuilder
- The target builderappliedJoinPaths
- The applied joins pathsqueryState
- The query state- Returns:
- An array representing the aliases for each join association in the specified join path
-
getColumnName
Get the column name for the given property.- Parameters:
persistentProperty
- The property- Returns:
- The column name
-
selectAllColumns
protected abstract void selectAllColumns(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer) Obtain the string that selects all columns from the entity.- Parameters:
annotationMetadata
- The annotation metadataqueryState
- The query statequeryBuffer
-
-
selectAllColumns
Selects all columns for the given entity and alias.- Parameters:
entity
- The entityalias
- The aliasqueryBuffer
- The buffer to append the columns
-
selectAllColumns
protected abstract void selectAllColumns(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, String alias, StringBuilder queryBuffer) Selects all columns for the given entity and alias.- Parameters:
annotationMetadata
- The annotation metadataentity
- The entityalias
- The aliasqueryBuffer
- The buffer to append the columns
-
selectAllColumnsFromJoinPaths
@Internal protected void selectAllColumnsFromJoinPaths(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer, Collection<JoinPath> allPaths, @Nullable @Nullable Map<JoinPath, String> joinAliasOverride) -
appendProperty
protected final void appendProperty(StringBuilder sb, List<Association> associations, PersistentProperty property, NamingStrategy namingStrategy, String tableAlias, boolean escape) -
shouldEscape
Whether queries should be escaped for the given entity.- Parameters:
entity
- The entity- Returns:
- True if they should be escaped
-
getTableAsKeyword
Get the AS keyword to use for table aliases.- Returns:
- The AS keyword if any
-
quote
Quote a column name for the dialect.- Parameters:
persistedName
- The persisted name.- Returns:
- The quoted name
-
buildSelect
protected void buildSelect(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, List<QueryModel.Projection> projectionList, String tableAlias, PersistentEntity entity) Build select statement.- Parameters:
annotationMetadata
- the annotation metadataqueryState
- the query statequeryString
- the query string builderprojectionList
- projection list (can be empty, then selects all columns)tableAlias
- the table aliasentity
- the persistent entity
-
appendCompoundPropertyProjection
@Internal protected void appendCompoundPropertyProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath, String columnAlias) Appends the compound (part of entity or DTO) property projection.- Parameters:
queryState
- The query statequeryString
- The builderproperty
- The propertypropertyPath
- The property pathcolumnAlias
- The column alias
-
appendCompoundAssociationProjection
@Internal protected void appendCompoundAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, Association association, PersistentPropertyPath propertyPath, String columnAlias) Appends the compound (part of entity or DTO) association projection.- Parameters:
queryState
- The query statequeryString
- The builderassociation
- The associationpropertyPath
- The property pathcolumnAlias
- The column alias
-
appendPropertyProjection
protected final void appendPropertyProjection(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, StringBuilder sb, AbstractSqlLikeQueryBuilder.QueryPropertyPath propertyPath, String columnAlias) -
appendAssociationProjection
protected boolean appendAssociationProjection(AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryString, PersistentProperty property, PersistentPropertyPath propertyPath, String columnAlias) Appends selection projection for the property which is association.- Parameters:
queryState
- the query statequeryString
- the query string builderproperty
- the persistent propertypropertyPath
- the persistent property pathcolumnAlias
- the column alias- Returns:
- true if association projection is appended, otherwise false
-
getNamingStrategy
GetsNamingStrategy
for the property path. Subclasses might override and potentially provide different strategy in some cases.- Parameters:
propertyPath
- the property path representation- Returns:
- naming strategy for the property path
-
getNamingStrategy
GetsNamingStrategy
for the entity. Subclasses might override and potentially provide different strategy in some cases.- Parameters:
entity
- the persistent entity- Returns:
- naming strategy for the entity
-
getMappedName
@NonNull protected @NonNull String getMappedName(@NonNull @NonNull NamingStrategy namingStrategy, @NonNull @NonNull PersistentProperty property) Gets the mapped name from the property usingNamingStrategy
.- Parameters:
namingStrategy
- the naming strategy being usedproperty
- the persistent property- Returns:
- the mapped name for the property
-
getMappedName
@NonNull protected @NonNull String getMappedName(@NonNull @NonNull NamingStrategy namingStrategy, @NonNull @NonNull Association association) Gets the mapped name from the association usingNamingStrategy
.- Parameters:
namingStrategy
- the naming strategy being usedassociation
- the associatioon- Returns:
- the mapped name for the association
-
getMappedName
@NonNull protected @NonNull String getMappedName(@NonNull @NonNull NamingStrategy namingStrategy, @NonNull @NonNull List<Association> associations, @NonNull @NonNull PersistentProperty property) Gets the mapped name from for the list of associations and property usingNamingStrategy
.- 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
-
appendProjectionRowCount
Appends a row count projection to the query string.- Parameters:
queryString
- The query stringlogicalName
- The alias to the table name
-
appendProjectionRowCountDistinct
protected abstract void appendProjectionRowCountDistinct(StringBuilder queryString, AbstractSqlLikeQueryBuilder.QueryState queryState, PersistentEntity entity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, String logicalName) Appends a row count distinct projection to the query string.- Parameters:
queryString
- The query stringqueryState
- The query stateentity
- The persistent entityannotationMetadata
- The query annotation metadatalogicalName
- The alias to the table name
-
buildWhereClause
protected void buildWhereClause(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel.Junction criteria, AbstractSqlLikeQueryBuilder.QueryState queryState) Builds where clause.- Parameters:
annotationMetadata
- the annotation metadata for the methodcriteria
- the criteriaqueryState
- the query state
-
buildAdditionalWhereClause
protected String buildAdditionalWhereClause(AbstractSqlLikeQueryBuilder.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds additional where clause if there isWhere
annotation on the entity.- Parameters:
queryState
- the query stateannotationMetadata
- the annotation metadata- Returns:
- where clause if there was
Where
annotation on the entity (or joins for JPA implementation)
-
buildAdditionalWhereString
protected String buildAdditionalWhereString(String alias, PersistentEntity entity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds WHERE clause for the entity and given alias ifIgnoreWhere
is not present.- Parameters:
alias
- the entity aliasentity
- the entityannotationMetadata
- the entity metadata- Returns:
- the WHERE clause
-
buildAdditionalWhereString
protected final String buildAdditionalWhereString(JoinPath joinPath, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds WHERE clause based onWhere
annotation on the metadata.- Parameters:
joinPath
- the join pathannotationMetadata
- the annotation metadata- Returns:
- WHERE clause if
Where
annotation is declared andIgnoreWhere
is not present, otherwise empty string
-
resolveWhereForAnnotationMetadata
protected final String resolveWhereForAnnotationMetadata(String alias, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Resolves where clause if there isWhere
annotation on the entity.- Parameters:
alias
- the entity aliasannotationMetadata
- the entity annotation metadata- Returns:
- where clause with entity alias if entity has declared where annotation
-
appendOrder
protected void appendOrder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, QueryModel query, AbstractSqlLikeQueryBuilder.QueryState queryState) Appends order to the query.- Parameters:
annotationMetadata
- the annotation metadataquery
- the query modelqueryState
- the query state
-
appendForUpdate
protected void appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition, QueryModel query, StringBuilder queryBuilder) Adds "forUpdate" pisimmistic locking.- Parameters:
queryPosition
- The query positionquery
- The queryqueryBuilder
- The builder
-
appendPropertyRef
protected void appendPropertyRef(StringBuilder sb, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, AbstractSqlLikeQueryBuilder.QueryPropertyPath propertyPath) Appends property to the sql string builder.- Parameters:
sb
- the sql string builderannotationMetadata
- the annotation metadataentity
- the persistent entitypropertyPath
- the query property path
-
handleSubQuery
protected void handleSubQuery(AbstractSqlLikeQueryBuilder.CriteriaContext ctx, QueryModel.SubqueryCriterion subqueryCriterion, String comparisonExpression) For handling subqueries.- Parameters:
ctx
- The criteria contextsubqueryCriterion
- The subquery criterioncomparisonExpression
- The comparison expression
-
isExpandEmbedded
protected boolean isExpandEmbedded()Should embedded queries by expanded by the implementation.- Returns:
- True if they should
-
appendUpdateSetParameter
protected void appendUpdateSetParameter(StringBuilder sb, String alias, PersistentProperty prop, Runnable appendParameter) Appends the SET=? call to the query string.- Parameters:
sb
- The string builderalias
- The aliasprop
- The propertyappendParameter
- The append parameter action
-
appendTransformed
Appends custom query part.- Parameters:
sb
- The string buildertransformed
- The transformed query partappendParameter
- The append parameter action
-
computePropertyPaths
protected abstract boolean computePropertyPaths()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.- Returns:
- True if property path computation is required.
-
buildUpdate
public QueryResult buildUpdate(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull QueryModel query, @NonNull @NonNull List<String> propertiesToUpdate) Description copied from interface:QueryBuilder
Encode the given query into the encoded query instance.- Specified by:
buildUpdate
in interfaceQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The querypropertiesToUpdate
- The property names to update- Returns:
- The encoded query
-
buildUpdate
public QueryResult buildUpdate(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull QueryModel query, @NonNull @NonNull Map<String, Object> propertiesToUpdate) Description copied from interface:QueryBuilder
Encode the given query into the encoded query instance.- Specified by:
buildUpdate
in interfaceQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The querypropertiesToUpdate
- The property names to update- Returns:
- The encoded query
-
buildDelete
public QueryResult buildDelete(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull QueryModel query) Description copied from interface:QueryBuilder
Encode the given query into the encoded query instance.- Specified by:
buildDelete
in interfaceQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataquery
- The query- Returns:
- The encoded query
-
isAliasForBatch
protected abstract boolean isAliasForBatch(PersistentEntity persistentEntity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Should aliases be used in batch statements.- Parameters:
persistentEntity
- the persistent entityannotationMetadata
- the method annotation metadata- Returns:
- True if they should
-
appendDeleteClause
Append the delete clause.- Parameters:
queryString
- The query string- Returns:
- The delete clause
-
buildOrderBy
@NonNull public @NonNull QueryResult buildOrderBy(@NonNull @NonNull PersistentEntity entity, @NonNull @NonNull Sort sort) Description copied from interface:QueryBuilder
Encode the given query into the encoded query instance.- Specified by:
buildOrderBy
in interfaceQueryBuilder
- Parameters:
entity
- The root entitysort
- The sort- Returns:
- The encoded query
-
buildOrderBy
@NonNull @Deprecated(forRemoval=true, since="4.2.0") public @NonNull QueryResult buildOrderBy(String query, @NonNull @NonNull PersistentEntity entity, @NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull Sort sort) Deprecated, for removal: This API element is subject to removal in a future version.Encode the given query into the encoded query instance.- Parameters:
query
- The queryentity
- The root entityannotationMetadata
- The annotation metadatasort
- The sort- Returns:
- The encoded query
-
buildOrderBy
@NonNull public @NonNull QueryResult buildOrderBy(String query, @NonNull @NonNull PersistentEntity entity, @NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull Sort sort, boolean nativeQuery) Encode the given query into the encoded query instance.- Parameters:
query
- The queryentity
- The root entityannotationMetadata
- The annotation metadatasort
- The sortnativeQuery
- Whether the query is native query, in which case sort field names will be supplied by the user and not verified- Returns:
- The encoded query
-
asPath
Join associations and property as path.- Parameters:
associations
- The associationsproperty
- The property- Returns:
- joined path
-
traversePersistentProperties
protected void traversePersistentProperties(PersistentProperty property, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.- Parameters:
property
- The property to start traversing fromconsumer
- The function to invoke on every property
-
traversePersistentProperties
protected void traversePersistentProperties(PersistentEntity persistentEntity, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.- Parameters:
persistentEntity
- The persistent entityconsumer
- The function to invoke on every property
-
traversePersistentProperties
protected void traversePersistentProperties(PersistentEntity persistentEntity, boolean includeIdentity, boolean includeVersion, BiConsumer<List<Association>, PersistentProperty> consumer) Traverses persistent properties.- Parameters:
persistentEntity
- The persistent entityincludeIdentity
- Should be identifier includedincludeVersion
- Should be version includedconsumer
- The function to invoke on every property
-
traversePersistentProperties
protected void traversePersistentProperties(List<Association> associations, PersistentProperty property, BiConsumer<List<Association>, PersistentProperty> consumerProperty) Traverses persistent properties.- Parameters:
associations
- The association list being traversed with the propertyproperty
- The persistent propertyconsumerProperty
- The function to invoke on every property
-
newBindingContext
protected BindingParameter.BindingContext newBindingContext(@Nullable @Nullable PersistentPropertyPath ref) Creates new binding parameter context.- Parameters:
ref
- the persistent property reference- Returns:
- new binding parameter context
-
getDataTransformerReadValue
Returns transformed value if the data transformer id defined.- Parameters:
alias
- query table aliasprop
- a property- Returns:
- optional transformed value
-
getDataTransformerWriteValue
Returns transformed value if the data transformer id defined.- Parameters:
alias
- query table aliasprop
- a property- Returns:
- optional transformed value
-
formatParameter
Format the parameter at the given index.- Parameters:
index
- The parameter- Returns:
- The index
-
resolveJoinType
Resolves the join type.- Parameters:
jt
- The join type- Returns:
- The join type.
-
addCriterionHandler
protected <T extends QueryModel.Criterion> void addCriterionHandler(Class<T> clazz, AbstractSqlLikeQueryBuilder.CriterionHandler<T> handler) Adds criterion handler.- Type Parameters:
T
- The criterion type- Parameters:
clazz
- The handler classhandler
- The handler
-
getColumnAlias
Gets column alias if defined as alias field on MappedProperty annotation on the mapping field.- Parameters:
property
- the persistent property- Returns:
- column alias if defined, otherwise an empty string
-
checkDialectSupportsJsonEntity
If and whenEntityRepresentation
annotation with JSON type is used for the repository method but dialect does not support JSON entity representations this will throwIllegalArgumentException
.- Parameters:
entity
- the persistent entity
-
isJsonEntity
protected boolean isJsonEntity(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity) Checks whetherEntityRepresentation
annotation with JSON type is used for the repository method. If current dialect does not support handling JSON entity representations,IllegalArgumentException
is thrown.- Parameters:
annotationMetadata
- the annotation metadataentity
- the persistent entity- Returns:
- true if
EntityRepresentation
annotation with JSON type is used for the repository method
-
buildOrderBy(String, PersistentEntity, AnnotationMetadata, Sort, boolean)