Class JpaQueryBuilder2
java.lang.Object
io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2
io.micronaut.data.model.query.builder.jpa.JpaQueryBuilder2
- All Implemented Interfaces:
QueryBuilder2
Builds JPA 1.0 String-based queries from the Query model.
- Since:
- 1.0
- Author:
- Graeme Rocher, Denis Stepanov
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2
AbstractSqlLikeQueryBuilder2.Placeholder, AbstractSqlLikeQueryBuilder2.QueryPosition, AbstractSqlLikeQueryBuilder2.QueryPropertyPath, AbstractSqlLikeQueryBuilder2.QueryState, AbstractSqlLikeQueryBuilder2.SqlPredicateVisitor, AbstractSqlLikeQueryBuilder2.SqlSelectionVisitor
Nested classes/interfaces inherited from interface io.micronaut.data.model.query.builder.QueryBuilder2
QueryBuilder2.BaseQueryDefinition, QueryBuilder2.DeleteQueryDefinition, QueryBuilder2.InsertQueryDefinition, QueryBuilder2.SelectQueryDefinition, QueryBuilder2.UpdateQueryDefinition
-
Field Summary
Fields inherited from class io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2
ALIAS_REPLACE_QUOTED, AND, AS_CLAUSE, CANNOT_QUERY_ON_ID_WITH_ENTITY_THAT_HAS_NO_ID, CLOSE_BRACKET, COMMA, DISTINCT, DOT, FROM_CLAUSE, LOGICAL_AND, LOGICAL_OR, NOT, OPEN_BRACKET, OR, ORDER_BY_CLAUSE, RETURNING, SELECT_CLAUSE, SPACE, WHERE_CLAUSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected @NonNull StringBuilder
appendDeleteClause
(StringBuilder queryString) Append the delete clause.protected String
buildAdditionalWhereClause
(AbstractSqlLikeQueryBuilder2.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Builds additional where clause if there isWhere
annotation on the entity.buildInsert
(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, QueryBuilder2.InsertQueryDefinition definition) Builds an insert statement for the given entity.protected void
buildJoin
(String joinType, StringBuilder query, AbstractSqlLikeQueryBuilder2.QueryState queryState, PersistentAssociationPath joinAssociation, PersistentEntity associationOwner, String currentJoinAlias, String lastJoinAlias) Build a join expression for the given alias, association, join type and builder.@NonNull QueryResult
buildPagination
(@NonNull Pageable pageable) Encode the pageable.protected boolean
Whether property path expressions require computation by the implementation.createSelectionVisitor
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder2.QueryState queryState, boolean distinct) Create a selection visitor.protected AbstractSqlLikeQueryBuilder2.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 NamingStrategy
getNamingStrategy
(PersistentEntity entity) GetsNamingStrategy
for the entity.protected NamingStrategy
getNamingStrategy
(PersistentPropertyPath propertyPath) GetsNamingStrategy
for the property path.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.Methods inherited from class io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2
appendExpression, appendForUpdate, appendOrder, appendPropertyRef, appendTransformed, appendUpdateSetParameter, asLiteral, asPath, asQueryPropertyPath, buildAdditionalWhereString, buildAdditionalWhereString, buildDelete, buildOrderBy, buildPropertyByName, buildSelect, buildSelect, buildUpdate, buildWhereClause, checkDialectSupportsJsonEntity, createPredicateVisitor, getAliasName, getColumnAlias, getDataTransformerReadValue, getDataTransformerWriteValue, getDialect, getMappedName, getMappedName, getMappedName, getPathOnlyAliasName, getTableAsKeyword, getUnescapedTableName, isJsonEntity, newBindingContext, resolveWhereForAnnotationMetadata, shouldEscape, traverseEmbedded
-
Constructor Details
-
JpaQueryBuilder2
public JpaQueryBuilder2()Default constructor.
-
-
Method Details
-
quote
Description copied from class:AbstractSqlLikeQueryBuilder2
Quote a column name for the dialect.- Overrides:
quote
in classAbstractSqlLikeQueryBuilder2
- Parameters:
persistedName
- The persisted name.- Returns:
- The quoted name
-
getAliasName
Description copied from class:AbstractSqlLikeQueryBuilder2
Get an alias name for the given entity.- Overrides:
getAliasName
in classAbstractSqlLikeQueryBuilder2
- Parameters:
entity
- The entity- Returns:
- The alias name
-
buildJoin
protected void buildJoin(String joinType, StringBuilder query, AbstractSqlLikeQueryBuilder2.QueryState queryState, PersistentAssociationPath joinAssociation, PersistentEntity associationOwner, String currentJoinAlias, String lastJoinAlias) Description copied from class:AbstractSqlLikeQueryBuilder2
Build a join expression for the given alias, association, join type and builder.- Overrides:
buildJoin
in classAbstractSqlLikeQueryBuilder2
- Parameters:
joinType
- The join typequery
- The query builderqueryState
- The statejoinAssociation
- The associationassociationOwner
- The associated ownercurrentJoinAlias
- The current join aliaslastJoinAlias
- The last join alias
-
buildAdditionalWhereClause
protected String buildAdditionalWhereClause(AbstractSqlLikeQueryBuilder2.QueryState queryState, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Description copied from class:AbstractSqlLikeQueryBuilder2
Builds additional where clause if there isWhere
annotation on the entity.- Overrides:
buildAdditionalWhereClause
in classAbstractSqlLikeQueryBuilder2
- 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:AbstractSqlLikeQueryBuilder2
Get the table name for the given entity.- Specified by:
getTableName
in classAbstractSqlLikeQueryBuilder2
- Parameters:
entity
- The entity- Returns:
- The table name
-
getColumnName
Description copied from class:AbstractSqlLikeQueryBuilder2
Get the column name for the given property.- Specified by:
getColumnName
in classAbstractSqlLikeQueryBuilder2
- Parameters:
persistentProperty
- The property- Returns:
- The column name
-
createSelectionVisitor
protected AbstractSqlLikeQueryBuilder2.SqlSelectionVisitor createSelectionVisitor(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlLikeQueryBuilder2.QueryState queryState, boolean distinct) Description copied from class:AbstractSqlLikeQueryBuilder2
Create a selection visitor.- Overrides:
createSelectionVisitor
in classAbstractSqlLikeQueryBuilder2
- Parameters:
annotationMetadata
- The annotation metadataqueryState
- The query statedistinct
- The distinct- Returns:
- The visitor
-
computePropertyPaths
protected boolean computePropertyPaths()Description copied from class:AbstractSqlLikeQueryBuilder2
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 classAbstractSqlLikeQueryBuilder2
- Returns:
- True if property path computation is required.
-
isAliasForBatch
protected boolean isAliasForBatch(PersistentEntity persistentEntity, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Description copied from class:AbstractSqlLikeQueryBuilder2
Should aliases be used in batch statements.- Specified by:
isAliasForBatch
in classAbstractSqlLikeQueryBuilder2
- Parameters:
persistentEntity
- the persistent entityannotationMetadata
- the method annotation metadata- Returns:
- True if they should
-
formatParameter
Description copied from class:AbstractSqlLikeQueryBuilder2
Format the parameter at the given index.- Specified by:
formatParameter
in classAbstractSqlLikeQueryBuilder2
- Parameters:
index
- The parameter- Returns:
- The index
-
resolveJoinType
Description copied from class:AbstractSqlLikeQueryBuilder2
Resolves the join type.- Specified by:
resolveJoinType
in classAbstractSqlLikeQueryBuilder2
- Parameters:
jt
- The join type- Returns:
- The join type.
-
buildInsert
public QueryResult buildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, QueryBuilder2.InsertQueryDefinition definition) Description copied from interface:QueryBuilder2
Builds an insert statement for the given entity.- Parameters:
repositoryMetadata
- The repository annotation metadatadefinition
- The definition- Returns:
- The insert statement or null if the implementation doesn't require insert statements
-
appendDeleteClause
Description copied from class:AbstractSqlLikeQueryBuilder2
Append the delete clause.- Overrides:
appendDeleteClause
in classAbstractSqlLikeQueryBuilder2
- Parameters:
queryString
- The query string- Returns:
- The delete clause
-
buildPagination
Description copied from interface:QueryBuilder2
Encode the pageable.- Parameters:
pageable
- The pageable- Returns:
- The encoded query
-
getNamingStrategy
Description copied from class:AbstractSqlLikeQueryBuilder2
GetsNamingStrategy
for the entity. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategy
in classAbstractSqlLikeQueryBuilder2
- Parameters:
entity
- the persistent entity- Returns:
- naming strategy for the entity
-
getNamingStrategy
Description copied from class:AbstractSqlLikeQueryBuilder2
GetsNamingStrategy
for the property path. Subclasses might override and potentially provide different strategy in some cases.- Overrides:
getNamingStrategy
in classAbstractSqlLikeQueryBuilder2
- Parameters:
propertyPath
- the property path representation- Returns:
- naming strategy for the property path
-