public class SqlQueryBuilder extends AbstractSqlLikeQueryBuilder implements QueryBuilder
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 |
IN_EXPRESSION_START
The start of an IN expression.
|
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_CLAUSEIN_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 |
|---|---|
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 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,
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.
|
boolean |
supportsForUpdate()
Whether FOR UPDATE queries are supported.
|
appendDeleteClause, buildDelete, buildOrderBy, buildQuery, buildUpdate, computeEmbeddedName, getAliasName, getPathOnlyAliasName, getUnescapedTableName, handleSubQuery, shouldEscapeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildDelete, buildDelete, buildOrderBy, buildQuery, buildQuery, buildUpdate, buildUpdate, newQueryBuilderpublic 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()
QueryBuildershouldAliasProjections in interface QueryBuilderprotected boolean isExpandEmbedded()
AbstractSqlLikeQueryBuilderisExpandEmbedded 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()
AbstractSqlLikeQueryBuildergetTableAsKeyword in class AbstractSqlLikeQueryBuilderprotected void selectAllColumns(AbstractSqlLikeQueryBuilder.QueryState queryState, java.lang.StringBuilder queryBuffer)
AbstractSqlLikeQueryBuilderselectAllColumns in class AbstractSqlLikeQueryBuilderqueryState - The query statepublic void selectAllColumns(PersistentEntity entity, java.lang.String alias, java.lang.StringBuilder stringBuffer)
selectAllColumns in class AbstractSqlLikeQueryBuilderentity - The entityalias - The aliasstringBuffer - The builder to add the columnspublic java.lang.String resolveJoinType(Join.Type jt)
AbstractSqlLikeQueryBuilderresolveJoinType in class AbstractSqlLikeQueryBuilderjt - The join type@NonNull public QueryResult buildInsert(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata, PersistentEntity entity)
QueryBuilderbuildInsert in interface QueryBuilderrepositoryMetadata - The repository annotation metadataentity - The entity@NonNull public QueryResult buildPagination(@NonNull Pageable pageable)
QueryBuilderbuildPagination in interface QueryBuilderpageable - The pageableprotected void encodeInExpression(java.lang.StringBuilder whereClause,
AbstractSqlLikeQueryBuilder.Placeholder placeholder)
AbstractSqlLikeQueryBuilderencodeInExpression in class AbstractSqlLikeQueryBuilderwhereClause - The where clauseplaceholder - The placeholderprotected java.lang.String getAliasName(PersistentEntity entity)
AbstractSqlLikeQueryBuildergetAliasName in class AbstractSqlLikeQueryBuilderentity - The entitypublic java.lang.String getTableName(PersistentEntity entity)
AbstractSqlLikeQueryBuildergetTableName in class AbstractSqlLikeQueryBuilderentity - The entityprotected java.lang.String formatStartsWith()
formatStartsWith in class AbstractSqlLikeQueryBuilderprotected java.lang.String formEndsWithEnd()
formEndsWithEnd in class AbstractSqlLikeQueryBuilderprotected java.lang.String formatEndsWith()
formatEndsWith in class AbstractSqlLikeQueryBuilderprotected java.lang.String formatStartsWithBeginning()
formatStartsWithBeginning in class AbstractSqlLikeQueryBuilderprotected void appendUpdateSetParameter(java.lang.StringBuilder queryString,
PersistentProperty prop,
AbstractSqlLikeQueryBuilder.Placeholder param)
AbstractSqlLikeQueryBuilderappendUpdateSetParameter in class AbstractSqlLikeQueryBuilderqueryString - 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)
AbstractSqlLikeQueryBuilderbuildJoin in class AbstractSqlLikeQueryBuilderalias - 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 AbstractSqlLikeQueryBuilderpersistedName - The persisted name.public java.lang.String getColumnName(PersistentProperty persistentProperty)
AbstractSqlLikeQueryBuildergetColumnName in class AbstractSqlLikeQueryBuilderpersistentProperty - The propertyprotected void appendProjectionRowCount(java.lang.StringBuilder queryString,
java.lang.String logicalName)
AbstractSqlLikeQueryBuilderappendProjectionRowCount in class AbstractSqlLikeQueryBuilderqueryString - The query stringlogicalName - The alias to the table nameprotected void appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition, QueryModel query, java.lang.StringBuilder queryBuilder)
appendForUpdate in class AbstractSqlLikeQueryBuilderprotected final boolean computePropertyPaths()
AbstractSqlLikeQueryBuildercomputePropertyPaths in class AbstractSqlLikeQueryBuilderprotected boolean isAliasForBatch()
AbstractSqlLikeQueryBuilderisAliasForBatch in class AbstractSqlLikeQueryBuilderprotected AbstractSqlLikeQueryBuilder.Placeholder formatParameter(int index)
AbstractSqlLikeQueryBuilderformatParameter in class AbstractSqlLikeQueryBuilderindex - The parameterprotected GeneratedValue.Type selectAutoStrategy(PersistentProperty property)
property - The Persistent propertypublic boolean supportsForUpdate()
QueryBuildersupportsForUpdate in interface QueryBuilder