public abstract class AbstractSqlLikeQueryBuilder extends java.lang.Object implements QueryBuilder
Modifier and Type | Class and Description |
---|---|
protected static interface |
AbstractSqlLikeQueryBuilder.CriteriaContext
A criterion context.
|
protected static interface |
AbstractSqlLikeQueryBuilder.CriterionHandler<T extends QueryModel.Criterion>
A criterion handler.
|
static class |
AbstractSqlLikeQueryBuilder.Placeholder
Represents a placeholder in query.
|
protected static class |
AbstractSqlLikeQueryBuilder.QueryPosition |
protected class |
AbstractSqlLikeQueryBuilder.QueryPropertyPath
Represents a path to a property.
|
protected class |
AbstractSqlLikeQueryBuilder.QueryState
The state of the query.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
ALIAS_REPLACE |
protected static java.lang.String |
ALIAS_REPLACE_QUOTED |
protected static java.lang.String |
AND |
protected static java.lang.String |
AS_CLAUSE |
static java.lang.String |
AUTO_POPULATED_PARAMETER_PREFIX |
protected static java.lang.String |
AVG |
protected static char |
CLOSE_BRACKET |
protected static char |
COMMA |
protected static java.lang.String |
COUNT_DISTINCT |
protected static java.lang.String |
DELETE_CLAUSE |
protected static java.lang.String |
DISTINCT |
protected static char |
DOT |
protected static java.lang.String |
EQUALS |
protected static java.lang.String |
EQUALS_FALSE |
protected static java.lang.String |
EQUALS_TRUE |
protected static java.lang.String |
FROM_CLAUSE |
protected static java.lang.String |
FUNCTION_COUNT |
protected static java.lang.String |
GREATER_THAN |
protected static java.lang.String |
GREATER_THAN_OR_EQUALS |
protected static java.lang.String |
IS_EMPTY |
protected static java.lang.String |
IS_NOT_EMPTY |
protected static java.lang.String |
IS_NOT_NULL |
protected static java.lang.String |
IS_NULL |
protected static java.lang.String |
LESS_THAN |
protected static java.lang.String |
LESS_THAN_OR_EQUALS |
protected static java.lang.String |
LOGICAL_AND |
protected static java.lang.String |
LOGICAL_OR |
protected static java.lang.String |
MAX |
protected static java.lang.String |
MIN |
protected static java.lang.String |
NOT_CLAUSE |
protected static java.lang.String |
NOT_EQUALS |
protected static char |
OPEN_BRACKET |
protected static java.lang.String |
OR |
static java.lang.String |
ORDER_BY_CLAUSE |
protected java.util.Map<java.lang.Class,AbstractSqlLikeQueryBuilder.CriterionHandler> |
queryHandlers |
protected static java.lang.String |
SELECT_CLAUSE |
protected static char |
SPACE |
protected static java.lang.String |
SUM |
protected static java.lang.String |
UPDATE_CLAUSE |
protected static java.lang.String |
WHERE_CLAUSE |
IN_VARIABLES_PATTERN, VARIABLE_PATTERN
Constructor and Description |
---|
AbstractSqlLikeQueryBuilder() |
Modifier and Type | Method and Description |
---|---|
protected <T extends QueryModel.Criterion> |
addCriterionHandler(java.lang.Class<T> clazz,
AbstractSqlLikeQueryBuilder.CriterionHandler<T> handler)
Adds criterion handler.
|
protected java.lang.StringBuilder |
appendDeleteClause(java.lang.StringBuilder queryString)
Append the delete clause.
|
protected void |
appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition,
QueryModel query,
java.lang.StringBuilder queryBuilder) |
protected abstract void |
appendProjectionRowCount(java.lang.StringBuilder queryString,
java.lang.String logicalName)
Appends a row count projection to the query string.
|
protected void |
appendUpdateSetParameter(java.lang.StringBuilder sb,
java.lang.String alias,
PersistentProperty prop,
java.lang.String placeholder)
Appends the SET=? call to the query string.
|
protected java.lang.String |
asPath(java.util.List<Association> associations,
PersistentProperty property)
Join associations and property as path.
|
QueryResult |
buildDelete(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
QueryModel query)
Encode the given query into the encoded query instance.
|
protected abstract java.lang.String[] |
buildJoin(java.lang.String alias,
JoinPath joinPath,
java.lang.String joinType,
java.lang.StringBuilder stringBuilder,
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.
|
QueryResult |
buildOrderBy(PersistentEntity entity,
Sort sort)
Encode the given query into the encoded query instance.
|
QueryResult |
buildQuery(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
QueryModel query)
Encode the given query for the passed annotation metadata and query.
|
QueryResult |
buildUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
QueryModel query,
java.util.List<java.lang.String> propertiesToUpdate)
Encode the given query into the encoded query instance.
|
protected abstract boolean |
computePropertyPaths()
Whether property path expressions require computation by the implementation.
|
protected java.lang.String |
formatEndsWith() |
protected abstract AbstractSqlLikeQueryBuilder.Placeholder |
formatParameter(int index)
Format the parameter at the given index.
|
protected java.lang.String |
formatStartsWith() |
protected java.lang.String |
formatStartsWithBeginning() |
protected java.lang.String |
formEndsWithEnd() |
java.lang.String |
getAliasName(JoinPath joinPath)
Get the alias name.
|
protected java.lang.String |
getAliasName(PersistentEntity entity)
Get an alias name for the given entity.
|
protected abstract java.lang.String |
getColumnName(PersistentProperty persistentProperty)
Get the column name for the given property.
|
protected java.util.Optional<java.lang.String> |
getDataTransformerReadValue(java.lang.String alias,
PersistentProperty prop)
Returns transformed value if the data transformer id defined.
|
protected java.util.Optional<java.lang.String> |
getDataTransformerWriteValue(java.lang.String alias,
PersistentProperty prop)
Returns transformed value if the data transformer id defined.
|
protected java.lang.String |
getPathOnlyAliasName(JoinPath joinPath)
Get the alias name for just the join path.
|
protected java.lang.String |
getTableAsKeyword()
Get the AS keyword to use for table aliases.
|
protected abstract java.lang.String |
getTableName(PersistentEntity entity)
Get the table name for the given entity.
|
protected java.lang.String |
getUnescapedTableName(PersistentEntity entity)
Get the table name for the given entity.
|
protected void |
handleSubQuery(AbstractSqlLikeQueryBuilder.CriteriaContext ctx,
QueryModel.SubqueryCriterion subqueryCriterion,
java.lang.String comparisonExpression)
For handling subqueries.
|
protected abstract boolean |
isAliasForBatch()
Should aliases be used in batch statements.
|
protected boolean |
isExpandEmbedded()
Should embedded queries by expanded by the implementation.
|
protected java.lang.String |
quote(java.lang.String persistedName)
Quote a column name for the dialect.
|
abstract java.lang.String |
resolveJoinType(Join.Type jt)
Resolves the join type.
|
protected abstract void |
selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState,
java.lang.StringBuilder queryBuffer)
Obtain the string that selects all columns from the entity.
|
protected abstract void |
selectAllColumns(PersistentEntity entity,
java.lang.String alias,
java.lang.StringBuilder queryBuffer)
Selects all columns for the given entity and alias.
|
protected boolean |
shouldEscape(PersistentEntity entity)
Whether queries should be escaped for the given entity.
|
protected void |
traversePersistentProperties(PersistentEntity persistentEntity,
java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
Traverses properties that should be persisted.
|
protected void |
traversePersistentProperties(PersistentEntity persistentEntity,
boolean includeIdentity,
boolean includeVersion,
java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
Traverses properties that should be persisted.
|
protected void |
traversePersistentProperties(PersistentProperty property,
java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
Traverses properties that should be persisted.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
buildDelete, buildInsert, buildPagination, buildQuery, buildUpdate, newQueryBuilder, shouldAliasProjections, supportsForUpdate
public static final java.lang.String AUTO_POPULATED_PARAMETER_PREFIX
public static final java.lang.String ORDER_BY_CLAUSE
protected static final java.lang.String SELECT_CLAUSE
protected static final java.lang.String AS_CLAUSE
protected static final java.lang.String FROM_CLAUSE
protected static final java.lang.String WHERE_CLAUSE
protected static final char COMMA
protected static final char CLOSE_BRACKET
protected static final char OPEN_BRACKET
protected static final char SPACE
protected static final char DOT
protected static final java.lang.String NOT_CLAUSE
protected static final java.lang.String AND
protected static final java.lang.String LOGICAL_AND
protected static final java.lang.String UPDATE_CLAUSE
protected static final java.lang.String DELETE_CLAUSE
protected static final java.lang.String OR
protected static final java.lang.String LOGICAL_OR
protected static final java.lang.String FUNCTION_COUNT
protected static final java.lang.String AVG
protected static final java.lang.String DISTINCT
protected static final java.lang.String SUM
protected static final java.lang.String MIN
protected static final java.lang.String MAX
protected static final java.lang.String COUNT_DISTINCT
protected static final java.lang.String IS_NOT_NULL
protected static final java.lang.String IS_EMPTY
protected static final java.lang.String IS_NOT_EMPTY
protected static final java.lang.String IS_NULL
protected static final java.lang.String EQUALS_TRUE
protected static final java.lang.String EQUALS_FALSE
protected static final java.lang.String GREATER_THAN_OR_EQUALS
protected static final java.lang.String LESS_THAN_OR_EQUALS
protected static final java.lang.String LESS_THAN
protected static final java.lang.String GREATER_THAN
protected static final java.lang.String EQUALS
protected static final java.lang.String NOT_EQUALS
protected static final java.lang.String ALIAS_REPLACE
protected static final java.lang.String ALIAS_REPLACE_QUOTED
protected final java.util.Map<java.lang.Class,AbstractSqlLikeQueryBuilder.CriterionHandler> queryHandlers
protected java.lang.String formEndsWithEnd()
protected java.lang.String formatStartsWithBeginning()
protected java.lang.String formatEndsWith()
protected java.lang.String formatStartsWith()
public QueryResult buildQuery(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query)
QueryBuilder
buildQuery
in interface QueryBuilder
annotationMetadata
- The annotation metadataquery
- The query modelprotected abstract java.lang.String getTableName(PersistentEntity entity)
entity
- The entityprotected java.lang.String getUnescapedTableName(PersistentEntity entity)
entity
- The entityprotected java.lang.String getAliasName(PersistentEntity entity)
entity
- The entitypublic java.lang.String getAliasName(JoinPath joinPath)
joinPath
- The join path@NonNull protected java.lang.String getPathOnlyAliasName(JoinPath joinPath)
joinPath
- The join pathprotected abstract java.lang.String[] buildJoin(java.lang.String alias, JoinPath joinPath, java.lang.String joinType, java.lang.StringBuilder stringBuilder, java.util.Map<java.lang.String,java.lang.String> appliedJoinPaths, AbstractSqlLikeQueryBuilder.QueryState queryState)
alias
- The aliasjoinPath
- The join pathjoinType
- The join type stringstringBuilder
- The target builderappliedJoinPaths
- The applied joins pathsqueryState
- The query stateprotected abstract java.lang.String getColumnName(PersistentProperty persistentProperty)
persistentProperty
- The propertyprotected abstract void selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)
queryState
- The query statequeryBuffer
- protected abstract void selectAllColumns(PersistentEntity entity, java.lang.String alias, java.lang.StringBuilder queryBuffer)
entity
- The entityalias
- The aliasqueryBuffer
- The buffer to append the columnsprotected boolean shouldEscape(@NonNull PersistentEntity entity)
entity
- The entityprotected java.lang.String getTableAsKeyword()
protected java.lang.String quote(java.lang.String persistedName)
persistedName
- The persisted name.protected abstract void appendProjectionRowCount(java.lang.StringBuilder queryString, java.lang.String logicalName)
queryString
- The query stringlogicalName
- The alias to the table nameprotected void appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition, QueryModel query, java.lang.StringBuilder queryBuilder)
protected void handleSubQuery(AbstractSqlLikeQueryBuilder.CriteriaContext ctx, QueryModel.SubqueryCriterion subqueryCriterion, java.lang.String comparisonExpression)
ctx
- The criteria contextsubqueryCriterion
- The subquery criterioncomparisonExpression
- The comparison expressionprotected boolean isExpandEmbedded()
protected void appendUpdateSetParameter(java.lang.StringBuilder sb, java.lang.String alias, PersistentProperty prop, java.lang.String placeholder)
sb
- The string builderalias
- The aliasprop
- The propertyplaceholder
- The parameterprotected abstract boolean computePropertyPaths()
public QueryResult buildUpdate(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query, @NonNull java.util.List<java.lang.String> propertiesToUpdate)
QueryBuilder
buildUpdate
in interface QueryBuilder
annotationMetadata
- The annotation metadataquery
- The querypropertiesToUpdate
- The property names to updatepublic QueryResult buildDelete(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull QueryModel query)
QueryBuilder
buildDelete
in interface QueryBuilder
annotationMetadata
- The annotation metadataquery
- The queryprotected abstract boolean isAliasForBatch()
@NonNull protected java.lang.StringBuilder appendDeleteClause(java.lang.StringBuilder queryString)
queryString
- The query string@NonNull public QueryResult buildOrderBy(@NonNull PersistentEntity entity, @NonNull Sort sort)
QueryBuilder
buildOrderBy
in interface QueryBuilder
entity
- The root entitysort
- The sortprotected java.lang.String asPath(java.util.List<Association> associations, PersistentProperty property)
associations
- The associationsproperty
- The propertyprotected void traversePersistentProperties(PersistentProperty property, java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
property
- The property to start traversing fromconsumer
- The function to invoke on every propertyprotected void traversePersistentProperties(PersistentEntity persistentEntity, java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
persistentEntity
- The persistent entityconsumer
- The function to invoke on every propertyprotected void traversePersistentProperties(PersistentEntity persistentEntity, boolean includeIdentity, boolean includeVersion, java.util.function.BiConsumer<java.util.List<Association>,PersistentProperty> consumer)
persistentEntity
- The persistent entityincludeIdentity
- Should be identifier includedincludeVersion
- Should be version includedconsumer
- The function to invoke on every propertyprotected java.util.Optional<java.lang.String> getDataTransformerReadValue(java.lang.String alias, PersistentProperty prop)
alias
- query table aliasprop
- a propertyprotected java.util.Optional<java.lang.String> getDataTransformerWriteValue(java.lang.String alias, PersistentProperty prop)
alias
- query table aliasprop
- a propertyprotected abstract AbstractSqlLikeQueryBuilder.Placeholder formatParameter(int index)
index
- The parameterpublic abstract java.lang.String resolveJoinType(Join.Type jt)
jt
- The join typeprotected <T extends QueryModel.Criterion> void addCriterionHandler(java.lang.Class<T> clazz, AbstractSqlLikeQueryBuilder.CriterionHandler<T> handler)
T
- The criterion typeclazz
- The handler classhandler
- The handler