Class JpaQueryBuilder
- java.lang.Object
-
- io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder
-
- io.micronaut.data.model.query.builder.jpa.JpaQueryBuilder
-
- All Implemented Interfaces:
QueryBuilder
@Internal public class JpaQueryBuilder extends AbstractSqlLikeQueryBuilder implements 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, 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 JpaQueryBuilder()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.QueryResultbuildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)Builds an insert statement for the given entity.protected java.lang.String[]buildJoin(java.lang.String alias, JoinPath joinPath, java.lang.String joinType, java.lang.StringBuilder target, java.util.Map<java.lang.String,java.lang.String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState)Build a join expression for the given alias, association, join type and builder.QueryResultbuildPagination(Pageable pageable)Encode the pageable.protected booleancomputePropertyPaths()Whether property path expressions require computation by the implementation.protected AbstractSqlLikeQueryBuilder.PlaceholderformatParameter(int index)Format the parameter at the given index.java.lang.StringgetAliasName(PersistentEntity entity)Get an alias name for the given entity.protected java.lang.StringgetColumnName(PersistentProperty persistentProperty)Get the column name for the given property.protected java.lang.StringgetTableName(PersistentEntity entity)Get the table name for the given entity.protected booleanisAliasForBatch()Should aliases be used in batch statements.protected java.lang.Stringquote(java.lang.String persistedName)Quote a column name for the dialect.java.lang.StringresolveJoinType(Join.Type jt)Resolves the join type.protected voidselectAllColumns(PersistentEntity entity, java.lang.String alias, java.lang.StringBuilder queryBuffer)Selects all columns for the given entity and alias.protected voidselectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.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, buildDelete, buildOrderBy, buildOrderBy, buildQuery, buildSelect, buildUpdate, buildUpdate, buildWhereClause, concat, getAliasName, getColumnAlias, getDataTransformerReadValue, getDataTransformerWriteValue, getDialect, getMappedName, getMappedName, getMappedName, getNamingStrategy, getNamingStrategy, getPathOnlyAliasName, getTableAsKeyword, getUnescapedTableName, handleSubQuery, isExpandEmbedded, newBindingContext, 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, buildQuery, buildUpdate, buildUpdate, buildUpdate, buildUpdate, shouldAliasProjections, supportsForUpdate
-
-
-
-
Method Detail
-
quote
protected java.lang.String quote(java.lang.String persistedName)
Description copied from class:AbstractSqlLikeQueryBuilderQuote a column name for the dialect.- Overrides:
quotein classAbstractSqlLikeQueryBuilder- Parameters:
persistedName- The persisted name.- Returns:
- The quoted name
-
getAliasName
public java.lang.String getAliasName(PersistentEntity entity)
Description copied from class:AbstractSqlLikeQueryBuilderGet an alias name for the given entity.- Overrides:
getAliasNamein classAbstractSqlLikeQueryBuilder- Parameters:
entity- The entity- Returns:
- The alias name
-
buildJoin
protected java.lang.String[] buildJoin(java.lang.String alias, JoinPath joinPath, java.lang.String joinType, java.lang.StringBuilder target, java.util.Map<java.lang.String,java.lang.String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState)Description copied from class:AbstractSqlLikeQueryBuilderBuild a join expression for the given alias, association, join type and builder.- Specified by:
buildJoinin 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
-
getTableName
protected java.lang.String getTableName(PersistentEntity entity)
Description copied from class:AbstractSqlLikeQueryBuilderGet the table name for the given entity.- Specified by:
getTableNamein classAbstractSqlLikeQueryBuilder- Parameters:
entity- The entity- Returns:
- The table name
-
getColumnName
protected java.lang.String getColumnName(PersistentProperty persistentProperty)
Description copied from class:AbstractSqlLikeQueryBuilderGet the column name for the given property.- Specified by:
getColumnNamein classAbstractSqlLikeQueryBuilder- Parameters:
persistentProperty- The property- Returns:
- The column name
-
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.- Specified by:
selectAllColumnsin classAbstractSqlLikeQueryBuilder- Parameters:
queryState- The query state
-
selectAllColumns
protected void selectAllColumns(PersistentEntity entity, java.lang.String alias, java.lang.StringBuilder queryBuffer)
Description copied from class:AbstractSqlLikeQueryBuilderSelects all columns for the given entity and alias.- Specified by:
selectAllColumnsin classAbstractSqlLikeQueryBuilder- Parameters:
entity- The entityalias- The aliasqueryBuffer- The buffer to append the columns
-
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.- Specified by:
appendProjectionRowCountin classAbstractSqlLikeQueryBuilder- Parameters:
queryString- The query stringlogicalName- The alias to the table name
-
computePropertyPaths
protected final 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.- Specified by:
computePropertyPathsin classAbstractSqlLikeQueryBuilder- Returns:
- True if property path computation is required.
-
isAliasForBatch
protected boolean isAliasForBatch()
Description copied from class:AbstractSqlLikeQueryBuilderShould aliases be used in batch statements.- Specified by:
isAliasForBatchin classAbstractSqlLikeQueryBuilder- Returns:
- True if they should
-
formatParameter
protected AbstractSqlLikeQueryBuilder.Placeholder formatParameter(int index)
Description copied from class:AbstractSqlLikeQueryBuilderFormat the parameter at the given index.- Specified by:
formatParameterin classAbstractSqlLikeQueryBuilder- Parameters:
index- The parameter- Returns:
- The index
-
resolveJoinType
public java.lang.String resolveJoinType(Join.Type jt)
Description copied from class:AbstractSqlLikeQueryBuilderResolves the join type.- Specified by:
resolveJoinTypein classAbstractSqlLikeQueryBuilder- Parameters:
jt- The join type- Returns:
- The join type.
-
buildInsert
@Nullable 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- Parameters:
repositoryMetadata- The repository annotation metadataentity- The entity- Returns:
- The insert statement or null if the implementation doesn't require insert statements
-
appendDeleteClause
@NonNull 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
-
buildPagination
@NonNull public QueryResult buildPagination(@NonNull Pageable pageable)
Description copied from interface:QueryBuilderEncode the pageable.- Specified by:
buildPaginationin interfaceQueryBuilder- Parameters:
pageable- The pageable- Returns:
- The encoded query
-
-