public class SqlQueryBuilder extends AbstractSqlLikeQueryBuilder implements QueryBuilder
QueryBuilder
that builds SQL queries.AbstractSqlLikeQueryBuilder.Placeholder, AbstractSqlLikeQueryBuilder.PropertyPath, AbstractSqlLikeQueryBuilder.QueryHandler, AbstractSqlLikeQueryBuilder.QueryState
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IN_EXPRESSION_START
The start of an IN expression.
|
AS_CLAUSE, CLOSE_BRACKET, COMMA, DELETE_CLAUSE, DOT, FROM_CLAUSE, FUNCTION_COUNT, LOGICAL_AND, LOGICAL_OR, NOT_CLAUSE, OPEN_BRACKET, ORDER_BY_CLAUSE, queryHandlers, SELECT_CLAUSE, SPACE, UPDATE_CLAUSE, WHERE_CLAUSE
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 |
---|---|
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 queryString,
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.
|
protected void |
encodeInExpression(java.lang.StringBuilder whereClause,
AbstractSqlLikeQueryBuilder.Placeholder placeholder)
Placeholders for IN queries in SQL require special treatment.
|
protected java.lang.String |
formatEndsWith() |
protected 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.
|
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.
|
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)
Obtain the string that selects all columns from the entity.
|
java.lang.String |
selectAllColumns(PersistentEntity entity,
java.lang.String alias)
Selects all columns for the given entity and alias.
|
protected GeneratedValue.Type |
selectAutoStrategy()
Selects the default fallback strategy.
|
boolean |
shouldAliasProjections()
Whether projections should be aliased.
|
appendDeleteClause, buildDelete, buildOrderBy, buildQuery, buildUpdate, getAliasName, getPathOnlyAliasName, getUnescapedTableName, handleSubQuery, shouldEscape
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 IN_EXPRESSION_START
@Creator public SqlQueryBuilder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
annotationMetadata
- The annotation metadatapublic SqlQueryBuilder()
public SqlQueryBuilder(Dialect dialect)
dialect
- The dialectpublic 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)
AbstractSqlLikeQueryBuilder
selectAllColumns
in class AbstractSqlLikeQueryBuilder
queryState
- The query statepublic java.lang.String selectAllColumns(PersistentEntity entity, java.lang.String alias)
entity
- The entityalias
- The aliaspublic 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 void encodeInExpression(java.lang.StringBuilder whereClause, AbstractSqlLikeQueryBuilder.Placeholder placeholder)
AbstractSqlLikeQueryBuilder
encodeInExpression
in class AbstractSqlLikeQueryBuilder
whereClause
- The where clauseplaceholder
- The placeholderprotected 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 queryString, PersistentProperty prop, AbstractSqlLikeQueryBuilder.Placeholder param)
AbstractSqlLikeQueryBuilder
appendUpdateSetParameter
in class AbstractSqlLikeQueryBuilder
queryString
- The query stringprop
- 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 final boolean computePropertyPaths()
AbstractSqlLikeQueryBuilder
computePropertyPaths
in class AbstractSqlLikeQueryBuilder
protected boolean isAliasForBatch()
AbstractSqlLikeQueryBuilder
isAliasForBatch
in class AbstractSqlLikeQueryBuilder
protected AbstractSqlLikeQueryBuilder.Placeholder formatParameter(int index)
AbstractSqlLikeQueryBuilder
formatParameter
in class AbstractSqlLikeQueryBuilder
index
- The parameterprotected GeneratedValue.Type selectAutoStrategy()