public class SqlQueryBuilder extends AbstractSqlLikeQueryBuilder implements QueryBuilder, SqlQueryConfiguration.DialectConfiguration
QueryBuilder that builds SQL queries.AbstractSqlLikeQueryBuilder.CriteriaContext, AbstractSqlLikeQueryBuilder.CriterionHandler<T extends QueryModel.Criterion>, AbstractSqlLikeQueryBuilder.Placeholder, AbstractSqlLikeQueryBuilder.QueryPosition, AbstractSqlLikeQueryBuilder.QueryPropertyPath, AbstractSqlLikeQueryBuilder.QueryState| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_POSITIONAL_PARAMETER_MARKER
The start of an IN expression.
|
static java.lang.String |
SQL_SERVER_FOR_UPDATE_CLAUSE |
static java.lang.String |
STANDARD_FOR_UPDATE_CLAUSE |
ALIAS_REPLACE, ALIAS_REPLACE_QUOTED, AND, AS_CLAUSE, AVG, CLOSE_BRACKET, COMMA, COUNT_DISTINCT, DELETE_CLAUSE, DISTINCT, DOT, EQUALS, 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 |
|---|---|
java.lang.Class<? extends java.lang.annotation.Annotation> |
annotationType() |
protected void |
appendForUpdate(AbstractSqlLikeQueryBuilder.QueryPosition queryPosition,
QueryModel query,
java.lang.StringBuilder queryBuilder)
Adds "forUpdate" pisimmistic locking.
|
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,
java.lang.Runnable appendParameter)
Appends the SET=? call to the query string.
|
protected java.lang.String |
asLiteral(java.lang.Object value)
Convert the literal value to it's SQL representation.
|
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()
Get dialect.
|
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 sb)
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.
|
addCriterionHandler, appendDeleteClause, appendTransformed, asPath, buildDelete, buildOrderBy, buildOrderBy, buildQuery, buildUpdate, buildUpdate, getAliasName, getDataTransformerReadValue, getDataTransformerWriteValue, getPathOnlyAliasName, getUnescapedTableName, handleSubQuery, traversePersistentProperties, traversePersistentProperties, traversePersistentPropertiesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildDelete, buildDelete, buildOrderBy, buildQuery, buildQuery, buildUpdate, buildUpdate, buildUpdate, buildUpdate, newQueryBuilderpublic static final java.lang.String DEFAULT_POSITIONAL_PARAMETER_MARKER
public static final java.lang.String STANDARD_FOR_UPDATE_CLAUSE
public static final java.lang.String SQL_SERVER_FOR_UPDATE_CLAUSE
@Creator public SqlQueryBuilder(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
annotationMetadata - The annotation metadatapublic SqlQueryBuilder()
public SqlQueryBuilder(Dialect dialect)
dialect - The dialectpublic Dialect getDialect()
AbstractSqlLikeQueryBuildergetDialect in class AbstractSqlLikeQueryBuilderprotected boolean shouldEscape(@NonNull
PersistentEntity entity)
AbstractSqlLikeQueryBuildershouldEscape in class AbstractSqlLikeQueryBuilderentity - The entityprotected java.lang.String asLiteral(java.lang.Object value)
AbstractSqlLikeQueryBuilderasLiteral in class AbstractSqlLikeQueryBuildervalue - The literal valuepublic 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 sb)
selectAllColumns in class AbstractSqlLikeQueryBuilderentity - The entityalias - The aliassb - 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 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 sb,
java.lang.String alias,
PersistentProperty prop,
java.lang.Runnable appendParameter)
AbstractSqlLikeQueryBuilderappendUpdateSetParameter in class AbstractSqlLikeQueryBuildersb - The string builderalias - The aliasprop - The propertyappendParameter - The append parameter actionprotected 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)
AbstractSqlLikeQueryBuilderappendForUpdate in class AbstractSqlLikeQueryBuilderqueryPosition - The query positionquery - The queryqueryBuilder - The builderprotected final boolean computePropertyPaths()
AbstractSqlLikeQueryBuildercomputePropertyPaths in class AbstractSqlLikeQueryBuilderprotected boolean isAliasForBatch()
AbstractSqlLikeQueryBuilderisAliasForBatch in class AbstractSqlLikeQueryBuilderpublic 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 QueryBuilderpublic 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