public class SqlQueryBuilder extends AbstractSqlLikeQueryBuilder implements QueryBuilder, SqlQueryConfiguration.DialectConfiguration
QueryBuilder
that builds SQL queries.AbstractSqlLikeQueryBuilder.Placeholder, AbstractSqlLikeQueryBuilder.PropertyPath, AbstractSqlLikeQueryBuilder.QueryHandler, AbstractSqlLikeQueryBuilder.QueryPosition, AbstractSqlLikeQueryBuilder.QueryState
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_POSITIONAL_PARAMETER_MARKER
The start of an IN expression.
|
ALIAS_REPLACE, ALIAS_REPLACE_QUOTED, AND, AS_CLAUSE, AVG, CLOSE_BRACKET, COMMA, COUNT_DISTINCT, DELETE_CLAUSE, DISTINCT, DOT, 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_CLAUSE, NOT_EQUALS, OPEN_BRACKET, OR, ORDER_BY_CLAUSE, queryHandlers, SELECT_CLAUSE, SPACE, SUM, UPDATE_CLAUSE, WHERE_CLAUSE
IN_VARIABLES_PATTERN, VARIABLE_PATTERN
Constructor and Description |
---|
SqlQueryBuilder()
Default constructor.
|
SqlQueryBuilder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Constructor with annotation metadata.
|
SqlQueryBuilder(Dialect dialect) |
Modifier and Type | Method and Description |
---|---|
java.lang.Class<? extends java.lang.annotation.Annotation> |
annotationType() |
protected void |
appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition,
QueryModel query,
java.lang.StringBuilder queryBuilder) |
protected 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,
AbstractSqlLikeQueryBuilder.Placeholder param)
Appends the SET=? call to the query string.
|
java.lang.String |
buildBatchCreateTableStatement(PersistentEntity... entities)
Builds a batch create tables statement.
|
java.lang.String |
buildBatchDropTableStatement(PersistentEntity... entities)
Builds a batch drop tables statement.
|
java.lang.String[] |
buildCreateTableStatements(PersistentEntity entity)
Builds the create table statement.
|
java.lang.String[] |
buildDropTableStatements(PersistentEntity entity)
Builds the drop table statement.
|
QueryResult |
buildInsert(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.
|
java.lang.String |
buildJoinTableInsert(PersistentEntity entity,
Association association)
Builds a join table insert statement for a given entity and association.
|
QueryResult |
buildPagination(Pageable pageable)
Encode the pageable.
|
protected boolean |
computePropertyPaths()
Whether property path expressions require computation by the implementation.
|
Dialect |
dialect() |
boolean |
escapeQueries() |
protected java.lang.String |
formatEndsWith() |
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() |
protected java.lang.String |
getAliasName(PersistentEntity entity)
Get an alias name for the given entity.
|
java.lang.String |
getColumnName(PersistentProperty persistentProperty)
Get the column name for the given property.
|
Dialect |
getDialect() |
protected java.lang.String |
getTableAsKeyword()
Get the AS keyword to use for table aliases.
|
java.lang.String |
getTableName(PersistentEntity entity)
Get the table name for the given entity.
|
protected boolean |
isAliasForBatch()
Should aliases be used in batch statements.
|
protected boolean |
isExpandEmbedded()
Should embedded queries by expanded by the implementation.
|
static boolean |
isForeignKeyWithJoinTable(Association association)
Is the given association a foreign key reference that requires a join table.
|
java.lang.String |
positionalParameterFormat() |
java.util.regex.Pattern |
positionalParameterPattern() |
protected java.lang.String |
quote(java.lang.String persistedName)
Quote a column name for the dialect.
|
java.lang.String |
resolveJoinType(Join.Type jt)
Resolves the join type.
|
protected void |
selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState,
java.lang.StringBuilder queryBuffer)
Obtain the string that selects all columns from the entity.
|
void |
selectAllColumns(PersistentEntity entity,
java.lang.String alias,
java.lang.StringBuilder stringBuffer)
Selects all columns for the given entity and alias.
|
protected GeneratedValue.Type |
selectAutoStrategy(PersistentProperty property)
Selects the default fallback strategy.
|
boolean |
shouldAliasProjections()
Whether projections should be aliased.
|
protected boolean |
shouldEscape(PersistentEntity entity)
Whether queries should be escaped for the given entity.
|
boolean |
supportsForUpdate()
Whether FOR UPDATE queries are supported.
|
appendDeleteClause, buildDelete, buildOrderBy, buildQuery, buildUpdate, computeEmbeddedName, encodeInExpression, getAliasName, getDataTransformerReadValue, getDataTransformerWriteValue, getPathOnlyAliasName, getUnescapedTableName, handleSubQuery
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
buildDelete, buildDelete, buildOrderBy, buildQuery, buildQuery, buildUpdate, buildUpdate, newQueryBuilder
public static final java.lang.String DEFAULT_POSITIONAL_PARAMETER_MARKER
@Creator public SqlQueryBuilder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
annotationMetadata
- The annotation metadatapublic SqlQueryBuilder()
public SqlQueryBuilder(Dialect dialect)
dialect
- The dialectpublic Dialect getDialect()
protected boolean shouldEscape(@NonNull PersistentEntity entity)
AbstractSqlLikeQueryBuilder
shouldEscape
in class AbstractSqlLikeQueryBuilder
entity
- The entitypublic boolean shouldAliasProjections()
QueryBuilder
shouldAliasProjections
in interface QueryBuilder
protected boolean isExpandEmbedded()
AbstractSqlLikeQueryBuilder
isExpandEmbedded
in class AbstractSqlLikeQueryBuilder
@NonNull public java.lang.String buildBatchCreateTableStatement(@NonNull PersistentEntity... entities)
entities
- the entities@NonNull public java.lang.String buildBatchDropTableStatement(@NonNull PersistentEntity... entities)
entities
- the entities@NonNull public java.lang.String[] buildDropTableStatements(@NonNull PersistentEntity entity)
entity
- The entity@NonNull public java.lang.String buildJoinTableInsert(@NonNull PersistentEntity entity, @NonNull Association association)
entity
- The entityassociation
- The associationpublic static boolean isForeignKeyWithJoinTable(@NonNull Association association)
association
- The association.@NonNull public java.lang.String[] buildCreateTableStatements(@NonNull PersistentEntity entity)
entity
- The entityprotected java.lang.String getTableAsKeyword()
AbstractSqlLikeQueryBuilder
getTableAsKeyword
in class AbstractSqlLikeQueryBuilder
protected void selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)
AbstractSqlLikeQueryBuilder
selectAllColumns
in class AbstractSqlLikeQueryBuilder
queryState
- The query statepublic void selectAllColumns(PersistentEntity entity, java.lang.String alias, java.lang.StringBuilder stringBuffer)
selectAllColumns
in class AbstractSqlLikeQueryBuilder
entity
- The entityalias
- The aliasstringBuffer
- The builder to add the columnspublic java.lang.String resolveJoinType(Join.Type jt)
AbstractSqlLikeQueryBuilder
resolveJoinType
in class AbstractSqlLikeQueryBuilder
jt
- The join type@NonNull public QueryResult buildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)
QueryBuilder
buildInsert
in interface QueryBuilder
repositoryMetadata
- The repository annotation metadataentity
- The entity@NonNull public QueryResult buildPagination(@NonNull Pageable pageable)
QueryBuilder
buildPagination
in interface QueryBuilder
pageable
- The pageableprotected java.lang.String getAliasName(PersistentEntity entity)
AbstractSqlLikeQueryBuilder
getAliasName
in class AbstractSqlLikeQueryBuilder
entity
- The entitypublic java.lang.String getTableName(PersistentEntity entity)
AbstractSqlLikeQueryBuilder
getTableName
in class AbstractSqlLikeQueryBuilder
entity
- The entityprotected java.lang.String formatStartsWith()
formatStartsWith
in class AbstractSqlLikeQueryBuilder
protected java.lang.String formEndsWithEnd()
formEndsWithEnd
in class AbstractSqlLikeQueryBuilder
protected java.lang.String formatEndsWith()
formatEndsWith
in class AbstractSqlLikeQueryBuilder
protected java.lang.String formatStartsWithBeginning()
formatStartsWithBeginning
in class AbstractSqlLikeQueryBuilder
protected void appendUpdateSetParameter(java.lang.StringBuilder sb, java.lang.String alias, PersistentProperty prop, AbstractSqlLikeQueryBuilder.Placeholder param)
AbstractSqlLikeQueryBuilder
appendUpdateSetParameter
in class AbstractSqlLikeQueryBuilder
sb
- The string builderalias
- The aliasprop
- The propertyparam
- the parameterprotected 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)
AbstractSqlLikeQueryBuilder
buildJoin
in class AbstractSqlLikeQueryBuilder
alias
- The aliasjoinPath
- The join pathjoinType
- The join type stringtarget
- The target builderappliedJoinPaths
- The applied joins pathsqueryState
- The query stateprotected java.lang.String quote(java.lang.String persistedName)
quote
in class AbstractSqlLikeQueryBuilder
persistedName
- The persisted name.public java.lang.String getColumnName(PersistentProperty persistentProperty)
AbstractSqlLikeQueryBuilder
getColumnName
in class AbstractSqlLikeQueryBuilder
persistentProperty
- The propertyprotected void appendProjectionRowCount(java.lang.StringBuilder queryString, java.lang.String logicalName)
AbstractSqlLikeQueryBuilder
appendProjectionRowCount
in class AbstractSqlLikeQueryBuilder
queryString
- The query stringlogicalName
- The alias to the table nameprotected void appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition, QueryModel query, java.lang.StringBuilder queryBuilder)
appendForUpdate
in class AbstractSqlLikeQueryBuilder
protected final boolean computePropertyPaths()
AbstractSqlLikeQueryBuilder
computePropertyPaths
in class AbstractSqlLikeQueryBuilder
protected boolean isAliasForBatch()
AbstractSqlLikeQueryBuilder
isAliasForBatch
in class AbstractSqlLikeQueryBuilder
public AbstractSqlLikeQueryBuilder.Placeholder formatParameter(int index)
AbstractSqlLikeQueryBuilder
formatParameter
in class AbstractSqlLikeQueryBuilder
index
- The parameterprotected GeneratedValue.Type selectAutoStrategy(PersistentProperty property)
property
- The Persistent propertypublic boolean supportsForUpdate()
QueryBuilder
supportsForUpdate
in interface QueryBuilder
public Dialect dialect()
public java.lang.String positionalParameterFormat()
public java.util.regex.Pattern positionalParameterPattern()
public boolean escapeQueries()
public java.lang.Class<? extends java.lang.annotation.Annotation> annotationType()
annotationType
in interface java.lang.annotation.Annotation