Class SqlQueryBuilder

    • Field Detail

      • DEFAULT_POSITIONAL_PARAMETER_MARKER

        public static final java.lang.String DEFAULT_POSITIONAL_PARAMETER_MARKER
        The start of an IN expression.
        See Also:
        Constant Field Values
      • STANDARD_FOR_UPDATE_CLAUSE

        public static final java.lang.String STANDARD_FOR_UPDATE_CLAUSE
        See Also:
        Constant Field Values
      • SQL_SERVER_FOR_UPDATE_CLAUSE

        public static final java.lang.String SQL_SERVER_FOR_UPDATE_CLAUSE
        See Also:
        Constant Field Values
    • Constructor Detail

      • SqlQueryBuilder

        @Creator
        public SqlQueryBuilder​(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
        Constructor with annotation metadata.
        Parameters:
        annotationMetadata - The annotation metadata
      • SqlQueryBuilder

        public SqlQueryBuilder()
        Default constructor.
      • SqlQueryBuilder

        public SqlQueryBuilder​(Dialect dialect)
        Parameters:
        dialect - The dialect
    • Method Detail

      • asLiteral

        protected java.lang.String asLiteral​(java.lang.Object value)
        Description copied from class: AbstractSqlLikeQueryBuilder
        Convert the literal value to it's SQL representation.
        Overrides:
        asLiteral in class AbstractSqlLikeQueryBuilder
        Parameters:
        value - The literal value
        Returns:
        converter value
      • shouldAliasProjections

        public boolean shouldAliasProjections()
        Description copied from interface: QueryBuilder
        Whether projections should be aliased.
        Specified by:
        shouldAliasProjections in interface QueryBuilder
        Returns:
        True if they should
      • buildBatchCreateTableStatement

        @NonNull
        public java.lang.String buildBatchCreateTableStatement​(@NonNull
                                                               PersistentEntity... entities)
        Builds a batch create tables statement. Designed for testing and not production usage. For production a SQL migration tool such as Flyway or Liquibase is recommended.
        Parameters:
        entities - the entities
        Returns:
        The table
      • buildBatchDropTableStatement

        @NonNull
        public java.lang.String buildBatchDropTableStatement​(@NonNull
                                                             PersistentEntity... entities)
        Builds a batch drop tables statement. Designed for testing and not production usage. For production a SQL migration tool such as Flyway or Liquibase is recommended.
        Parameters:
        entities - the entities
        Returns:
        The table
      • buildDropTableStatements

        @NonNull
        public java.lang.String[] buildDropTableStatements​(@NonNull
                                                           PersistentEntity entity)
        Builds the drop table statement. Designed for testing and not production usage. For production a SQL migration tool such as Flyway or Liquibase is recommended.
        Parameters:
        entity - The entity
        Returns:
        The tables for the give entity
      • buildJoinTableInsert

        @NonNull
        public java.lang.String buildJoinTableInsert​(@NonNull
                                                     PersistentEntity entity,
                                                     @NonNull
                                                     Association association)
        Builds a join table insert statement for a given entity and association.
        Parameters:
        entity - The entity
        association - The association
        Returns:
        The join table insert statement
      • isForeignKeyWithJoinTable

        public static boolean isForeignKeyWithJoinTable​(@NonNull
                                                        Association association)
        Is the given association a foreign key reference that requires a join table.
        Parameters:
        association - The association.
        Returns:
        True if it is.
      • buildCreateTableStatements

        @NonNull
        public java.lang.String[] buildCreateTableStatements​(@NonNull
                                                             PersistentEntity entity)
        Builds the create table statement. Designed for testing and not production usage. For production a SQL migration tool such as Flyway or Liquibase is recommended.
        Parameters:
        entity - The entity
        Returns:
        The tables for the give entity
      • selectAllColumns

        public void selectAllColumns​(PersistentEntity entity,
                                     java.lang.String alias,
                                     java.lang.StringBuilder sb)
        Selects all columns for the given entity and alias.
        Specified by:
        selectAllColumns in class AbstractSqlLikeQueryBuilder
        Parameters:
        entity - The entity
        alias - The alias
        sb - The builder to add the columns
      • buildInsert

        @NonNull
        public QueryResult buildInsert​(io.micronaut.core.annotation.AnnotationMetadata repositoryMetadata,
                                       PersistentEntity entity)
        Description copied from interface: QueryBuilder
        Builds an insert statement for the given entity.
        Specified by:
        buildInsert in interface QueryBuilder
        Parameters:
        repositoryMetadata - The repository annotation metadata
        entity - The entity
        Returns:
        The insert statement or null if the implementation doesn't require insert statements
      • concat

        protected void concat​(java.lang.StringBuilder writer,
                              java.util.Collection<java.lang.Runnable> partsWriters)
        Overrides:
        concat in class AbstractSqlLikeQueryBuilder
        Parameters:
        partsWriters - The parts writers
        writer - The writer
      • appendUpdateSetParameter

        protected void appendUpdateSetParameter​(java.lang.StringBuilder sb,
                                                java.lang.String alias,
                                                PersistentProperty prop,
                                                java.lang.Runnable appendParameter)
        Description copied from class: AbstractSqlLikeQueryBuilder
        Appends the SET=? call to the query string.
        Overrides:
        appendUpdateSetParameter in class AbstractSqlLikeQueryBuilder
        Parameters:
        sb - The string builder
        alias - The alias
        prop - The property
        appendParameter - The append parameter action
      • buildJoin

        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)
        Description copied from class: AbstractSqlLikeQueryBuilder
        Build a join expression for the given alias, association, join type and builder.
        Specified by:
        buildJoin in class AbstractSqlLikeQueryBuilder
        Parameters:
        alias - The alias
        joinPath - The join path
        joinType - The join type string
        target - The target builder
        appliedJoinPaths - The applied joins paths
        queryState - The query state
        Returns:
        An array representing the aliases for each join association in the specified join path
      • buildJoin

        protected void buildJoin​(java.lang.String joinType,
                                 java.lang.StringBuilder sb,
                                 AbstractSqlLikeQueryBuilder.QueryState queryState,
                                 java.util.List<Association> joinAssociationsPath,
                                 java.lang.String joinAlias,
                                 Association association,
                                 PersistentEntity associatedEntity,
                                 PersistentEntity associationOwner,
                                 java.lang.String currentJoinAlias)
        Builds join, adding fields and criteria.
        Parameters:
        joinType - the join type
        sb - string builder that join will be added to
        queryState - the query state
        joinAssociationsPath - the list of associations
        joinAlias - the join alias
        association - the association
        associatedEntity - the associated entity
        associationOwner - the association owner
        currentJoinAlias - the current join alias
      • quote

        protected java.lang.String quote​(java.lang.String persistedName)
        Quote a column name for the dialect.
        Overrides:
        quote in class AbstractSqlLikeQueryBuilder
        Parameters:
        persistedName - The persisted name.
        Returns:
        The quoted name
      • appendProjectionRowCount

        protected void appendProjectionRowCount​(java.lang.StringBuilder queryString,
                                                java.lang.String logicalName)
        Description copied from class: AbstractSqlLikeQueryBuilder
        Appends a row count projection to the query string.
        Specified by:
        appendProjectionRowCount in class AbstractSqlLikeQueryBuilder
        Parameters:
        queryString - The query string
        logicalName - The alias to the table name
      • computePropertyPaths

        protected boolean computePropertyPaths()
        Description copied from class: AbstractSqlLikeQueryBuilder
        Whether property path expressions require computation by the implementation. In a certain query dialects property paths are supported (such as JPA-QL where you can do select foo.bar) whilst for explicit SQL queries paths like this have to be computed into aliases / column name references.
        Specified by:
        computePropertyPaths in class AbstractSqlLikeQueryBuilder
        Returns:
        True if property path computation is required.
      • selectAutoStrategy

        protected GeneratedValue.Type selectAutoStrategy​(PersistentProperty property)
        Selects the default fallback strategy. For a generated value.
        Parameters:
        property - The Persistent property
        Returns:
        The generated value
      • supportsForUpdate

        public boolean supportsForUpdate()
        Description copied from interface: QueryBuilder
        Whether FOR UPDATE queries are supported.
        Specified by:
        supportsForUpdate in interface QueryBuilder
        Returns:
        True if FOR UPDATE queries are supported
      • dialect

        public Dialect dialect()
      • positionalParameterFormat

        public java.lang.String positionalParameterFormat()
      • positionalParameterName

        public java.lang.String positionalParameterName()
      • positionalParameterPattern

        public java.util.regex.Pattern positionalParameterPattern()
        Returns:
        The regex pattern for positional parameters.
      • escapeQueries

        public boolean escapeQueries()
      • annotationType

        public java.lang.Class<? extends java.lang.annotation.Annotation> annotationType()
        Specified by:
        annotationType in interface java.lang.annotation.Annotation