Class JpaQueryBuilder
java.lang.Object
io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
io.micronaut.data.model.query.builder.jpa.JpaQueryBuilder
- All Implemented Interfaces:
QueryBuilder
Builds JPA 1.0 String-based queries from the Query model.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
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.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, IS_NULL, JSON_COLUMN, 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
VARIABLE_PATTERN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected @NonNull StringBuilder
appendDeleteClause
(StringBuilder queryString) Append the delete clause.protected void
appendProjectionRowCount
(StringBuilder queryString, String logicalName) Appends a row count projection to the query string.protected String
buildAdditionalWhereClause
(AbstractSqlLikeQueryBuilder.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds additional where clause if there isWhere
annotation on the entity.@Nullable QueryResult
buildInsert
(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity) Builds an insert statement for the given entity.protected String[]
buildJoin
(String alias, JoinPath joinPath, String joinType, StringBuilder target, Map<String, String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState) Build a join expression for the given alias, association, join type and builder.@NonNull QueryResult
buildPagination
(@NonNull Pageable pageable) Encode the pageable.protected final boolean
Whether property path expressions require computation by the implementation.protected AbstractSqlLikeQueryBuilder.Placeholder
formatParameter
(int index) Format the parameter at the given index.getAliasName
(PersistentEntity entity) Get an alias name for the given entity.protected String
getColumnName
(PersistentProperty persistentProperty) Get the column name for the given property.protected String
getTableName
(PersistentEntity entity) Get the table name for the given entity.protected boolean
isAliasForBatch
(PersistentEntity persistentEntity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Should aliases be used in batch statements.protected String
Quote a column name for the dialect.Resolves the join type.protected void
selectAllColumns
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, String alias, StringBuilder queryBuffer) Selects all columns for the given entity and alias.protected void
selectAllColumns
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer) Obtain the string that selects all columns from the entity.Methods inherited from class io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
addCriterionHandler, appendAssociationProjection, appendForUpdate, appendOrder, appendPropertyRef, appendTransformed, appendUpdateSetParameter, asLiteral, asLiterals, asPath, buildAdditionalWhereString, buildAdditionalWhereString, buildDelete, buildOrderBy, buildOrderBy, buildQuery, buildSelect, buildUpdate, buildUpdate, buildWhereClause, checkDialectSupportsJsonEntity, concat, getAliasName, getColumnAlias, getDataTransformerReadValue, getDataTransformerWriteValue, getDialect, getMappedName, getMappedName, getMappedName, getNamingStrategy, getNamingStrategy, getPathOnlyAliasName, getTableAsKeyword, getUnescapedTableName, handleSubQuery, isExpandEmbedded, isJsonEntity, newBindingContext, resolveWhereForAnnotationMetadata, selectAllColumns, selectAllColumnsFromJoinPaths, shouldEscape, traversePersistentProperties, 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, buildUpdate, shouldAliasProjections, supportsForUpdate
-
Constructor Details
-
JpaQueryBuilder
public JpaQueryBuilder()Default constructor.
-
-
Method Details
-
quote
Description copied from class:AbstractSqlLikeQueryBuilder
Quote a column name for the dialect.- Overrides:
quote
in classAbstractSqlLikeQueryBuilder
- Parameters:
persistedName
- The persisted name.- Returns:
- The quoted name
-
getAliasName
Description copied from class:AbstractSqlLikeQueryBuilder
Get an alias name for the given entity.- Overrides:
getAliasName
in classAbstractSqlLikeQueryBuilder
- Parameters:
entity
- The entity- Returns:
- The alias name
-
buildJoin
protected String[] buildJoin(String alias, JoinPath joinPath, String joinType, StringBuilder target, Map<String, String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState) Description copied from class:AbstractSqlLikeQueryBuilder
Build a join expression for the given alias, association, join type and builder.- Specified by:
buildJoin
in classAbstractSqlLikeQueryBuilder
- Parameters:
alias
- The aliasjoinPath
- The join pathjoinType
- The join type stringtarget
- 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
-
buildAdditionalWhereClause
protected String buildAdditionalWhereClause(AbstractSqlLikeQueryBuilder.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Description copied from class:AbstractSqlLikeQueryBuilder
Builds additional where clause if there isWhere
annotation on the entity.- Overrides:
buildAdditionalWhereClause
in classAbstractSqlLikeQueryBuilder
- Parameters:
queryState
- the query stateannotationMetadata
- the annotation metadata- Returns:
- where clause if there was
Where
annotation on the entity (or joins for JPA implementation)
-
getTableName
Description copied from class:AbstractSqlLikeQueryBuilder
Get the table name for the given entity.- Specified by:
getTableName
in classAbstractSqlLikeQueryBuilder
- Parameters:
entity
- The entity- Returns:
- The table name
-
getColumnName
Description copied from class:AbstractSqlLikeQueryBuilder
Get the column name for the given property.- Specified by:
getColumnName
in classAbstractSqlLikeQueryBuilder
- Parameters:
persistentProperty
- The property- Returns:
- The column name
-
selectAllColumns
protected void selectAllColumns(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder.QueryState queryState, StringBuilder queryBuffer) Description copied from class:AbstractSqlLikeQueryBuilder
Obtain the string that selects all columns from the entity.- Specified by:
selectAllColumns
in classAbstractSqlLikeQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataqueryState
- The query state
-
selectAllColumns
protected void selectAllColumns(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, PersistentEntity entity, String alias, StringBuilder queryBuffer) Description copied from class:AbstractSqlLikeQueryBuilder
Selects all columns for the given entity and alias.- Specified by:
selectAllColumns
in classAbstractSqlLikeQueryBuilder
- Parameters:
annotationMetadata
- The annotation metadataentity
- The entityalias
- The aliasqueryBuffer
- The buffer to append the columns
-
appendProjectionRowCount
Description copied from class:AbstractSqlLikeQueryBuilder
Appends a row count projection to the query string.- Specified by:
appendProjectionRowCount
in classAbstractSqlLikeQueryBuilder
- Parameters:
queryString
- The query stringlogicalName
- The alias to the table name
-
computePropertyPaths
protected final 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.- Specified by:
computePropertyPaths
in classAbstractSqlLikeQueryBuilder
- Returns:
- True if property path computation is required.
-
isAliasForBatch
protected boolean isAliasForBatch(PersistentEntity persistentEntity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Description copied from class:AbstractSqlLikeQueryBuilder
Should aliases be used in batch statements.- Specified by:
isAliasForBatch
in classAbstractSqlLikeQueryBuilder
- Parameters:
persistentEntity
- the persistent entityannotationMetadata
- the method annotation metadata- Returns:
- True if they should
-
formatParameter
Description copied from class:AbstractSqlLikeQueryBuilder
Format the parameter at the given index.- Specified by:
formatParameter
in classAbstractSqlLikeQueryBuilder
- Parameters:
index
- The parameter- Returns:
- The index
-
resolveJoinType
Description copied from class:AbstractSqlLikeQueryBuilder
Resolves the join type.- Specified by:
resolveJoinType
in classAbstractSqlLikeQueryBuilder
- Parameters:
jt
- The join type- Returns:
- The join type.
-
buildInsert
@Nullable public @Nullable 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
- Parameters:
repositoryMetadata
- The repository annotation metadataentity
- The entity- Returns:
- The insert statement or null if the implementation doesn't require insert statements
-
appendDeleteClause
Description copied from class:AbstractSqlLikeQueryBuilder
Append the delete clause.- Overrides:
appendDeleteClause
in classAbstractSqlLikeQueryBuilder
- Parameters:
queryString
- The query string- Returns:
- The delete clause
-
buildPagination
Description copied from interface:QueryBuilder
Encode the pageable.- Specified by:
buildPagination
in interfaceQueryBuilder
- Parameters:
pageable
- The pageable- Returns:
- The encoded query
-