Class ProjectableSQLQuery<T,Q extends ProjectableSQLQuery<T,Q> & Query<Q>>

Type Parameters:
T - result type
Q - concrete subtype
All Implemented Interfaces:
Fetchable<T>, FetchableQuery<T,Q>, FilteredClause<Q>, Query<Q>, SimpleQuery<Q>, ExtendedSubQuery<T>, Expression<T>, SubQueryExpression<T>, SQLCommonQuery<Q>, Serializable
Direct Known Subclasses:
AbstractSQLQuery

public abstract class ProjectableSQLQuery<T,Q extends ProjectableSQLQuery<T,Q> & Query<Q>> extends FetchableSubQueryBase<T,Q> implements SQLCommonQuery<Q>, FetchableQuery<T,Q>
ProjectableSQLQuery is the base type for SQL query implementations
See Also:
  • Field Details

    • configuration

      protected final Configuration configuration
    • union

      @Nullable protected @Nullable Expression<?> union
    • firstUnionSubQuery

      protected SubQueryExpression<?> firstUnionSubQuery
    • unionAll

      protected boolean unionAll
  • Constructor Details

  • Method Details

    • accept

      public <R, C> R accept(Visitor<R,C> v, @Nullable C context)
      Specified by:
      accept in interface Expression<T>
      Overrides:
      accept in class FetchableSubQueryBase<T,Q extends ProjectableSQLQuery<T,Q> & Query<Q>>
    • addJoinFlag

      public Q addJoinFlag(String flag)
      Add the given String literal as a join flag to the last added join with the position BEFORE_TARGET
      Specified by:
      addJoinFlag in interface SQLCommonQuery<T>
      Parameters:
      flag - join flag
      Returns:
      the current object
    • addJoinFlag

      public Q addJoinFlag(String flag, JoinFlag.Position position)
      Add the given String literal as a join flag to the last added join
      Specified by:
      addJoinFlag in interface SQLCommonQuery<T>
      Parameters:
      flag - join flag
      position - position
      Returns:
      the current object
    • addFlag

      public Q addFlag(QueryFlag.Position position, String prefix, Expression<?> expr)
      Add the given prefix and expression as a general query flag
      Specified by:
      addFlag in interface SQLCommonQuery<T>
      Parameters:
      position - position of the flag
      prefix - prefix for the flag
      expr - expression of the flag
      Returns:
      the current object
    • addFlag

      public Q addFlag(QueryFlag flag)
      Add the given query flag
      Parameters:
      flag - query flag
      Returns:
      the current object
    • addFlag

      public Q addFlag(QueryFlag.Position position, String flag)
      Add the given String literal as query flag
      Specified by:
      addFlag in interface SQLCommonQuery<T>
      Parameters:
      position - position
      flag - query flag
      Returns:
      the current object
    • addFlag

      public Q addFlag(QueryFlag.Position position, Expression<?> flag)
      Add the given Expression as a query flag
      Specified by:
      addFlag in interface SQLCommonQuery<T>
      Parameters:
      position - position
      flag - query flag
      Returns:
      the current object
    • fetchCount

      public long fetchCount()
      Specified by:
      fetchCount in interface Fetchable<T>
    • from

      public Q from(Expression<?> arg)
    • from

      public Q from(Expression<?>... args)
      Description copied from interface: SQLCommonQuery
      Defines the sources of the query
      Specified by:
      from in interface SQLCommonQuery<T>
      Parameters:
      args - from
      Returns:
      the current object
    • from

      public Q from(SubQueryExpression<?> subQuery, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds a sub query source
      Specified by:
      from in interface SQLCommonQuery<T>
      Parameters:
      subQuery - sub query
      alias - alias
      Returns:
      the current object
    • fullJoin

      public Q fullJoin(EntityPath<?> target)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      fullJoin in interface SQLCommonQuery<T>
      Parameters:
      target - full join target
      Returns:
      the current object
    • fullJoin

      public <E> Q fullJoin(EntityPath<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      fullJoin in interface SQLCommonQuery<T>
      Parameters:
      target - full join target
      alias - alias
      Returns:
      the current object
    • fullJoin

      public <E> Q fullJoin(RelationalFunctionCall<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      fullJoin in interface SQLCommonQuery<T>
      Parameters:
      target - full join target
      alias - alias
      Returns:
      the current object
    • fullJoin

      public Q fullJoin(SubQueryExpression<?> target, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      fullJoin in interface SQLCommonQuery<T>
      Parameters:
      target - subquery
      alias - alias
      Returns:
      the current object
    • fullJoin

      public <E> Q fullJoin(ForeignKey<E> key, RelationalPath<E> entity)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      fullJoin in interface SQLCommonQuery<T>
      Parameters:
      key - foreign key for join
      entity - join target
      Returns:
      the current object
    • innerJoin

      public Q innerJoin(EntityPath<?> target)
      Description copied from interface: SQLCommonQuery
      Adds an inner join to the given target
      Specified by:
      innerJoin in interface SQLCommonQuery<T>
      Returns:
      the current object
    • innerJoin

      public <E> Q innerJoin(EntityPath<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds an inner join to the given target
      Specified by:
      innerJoin in interface SQLCommonQuery<T>
      Parameters:
      target - inner join target
      alias - alias
      Returns:
      the current object
    • innerJoin

      public <E> Q innerJoin(RelationalFunctionCall<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a inner join to the given target
      Specified by:
      innerJoin in interface SQLCommonQuery<T>
      Parameters:
      target - relational function call
      alias - alias
      Returns:
      the current object
    • innerJoin

      public Q innerJoin(SubQueryExpression<?> target, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds an inner join to the given target
      Specified by:
      innerJoin in interface SQLCommonQuery<T>
      Parameters:
      target - subquery
      alias - alias
      Returns:
      the current object
    • innerJoin

      public <E> Q innerJoin(ForeignKey<E> key, RelationalPath<E> entity)
      Description copied from interface: SQLCommonQuery
      Adds an inner join to the given target
      Specified by:
      innerJoin in interface SQLCommonQuery<T>
      Parameters:
      key - foreign key to use for join
      entity - join target
      Returns:
      the current object
    • join

      public Q join(EntityPath<?> target)
      Description copied from interface: SQLCommonQuery
      Adds a join to the given target
      Specified by:
      join in interface SQLCommonQuery<T>
      Parameters:
      target - join target
      Returns:
      the current object
    • join

      public <E> Q join(EntityPath<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a join to the given target
      Specified by:
      join in interface SQLCommonQuery<T>
      Parameters:
      target - join target
      alias - alias
      Returns:
      the current object
    • join

      public <E> Q join(RelationalFunctionCall<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a join to the given target
      Specified by:
      join in interface SQLCommonQuery<T>
      Parameters:
      target - join target
      alias - alias
      Returns:
      the current object
    • join

      public Q join(SubQueryExpression<?> target, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds a join to the given target
      Specified by:
      join in interface SQLCommonQuery<T>
      Parameters:
      target - subquery
      alias - alias
      Returns:
      the current object
    • join

      public <E> Q join(ForeignKey<E> key, RelationalPath<E> entity)
      Description copied from interface: SQLCommonQuery
      Adds a join to the given target
      Specified by:
      join in interface SQLCommonQuery<T>
      Parameters:
      key - foreign key to use for join
      entity - join target
      Returns:
      the current object
    • leftJoin

      public Q leftJoin(EntityPath<?> target)
      Description copied from interface: SQLCommonQuery
      Adds a left join to the given target
      Specified by:
      leftJoin in interface SQLCommonQuery<T>
      Parameters:
      target - join target
      Returns:
      the current object
    • leftJoin

      public <E> Q leftJoin(EntityPath<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a left join to the given target
      Specified by:
      leftJoin in interface SQLCommonQuery<T>
      Parameters:
      target - left join target
      alias - alias
      Returns:
      the current object
    • leftJoin

      public <E> Q leftJoin(RelationalFunctionCall<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a left join to the given target
      Specified by:
      leftJoin in interface SQLCommonQuery<T>
      Parameters:
      target - relational function call
      alias - alias
      Returns:
      the current object
    • leftJoin

      public Q leftJoin(SubQueryExpression<?> target, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds a left join to the given target
      Specified by:
      leftJoin in interface SQLCommonQuery<T>
      Parameters:
      target - subquery
      alias - alias
      Returns:
      the current object
    • leftJoin

      public <E> Q leftJoin(ForeignKey<E> key, RelationalPath<E> entity)
      Description copied from interface: SQLCommonQuery
      Adds a left join to the given target
      Specified by:
      leftJoin in interface SQLCommonQuery<T>
      Parameters:
      key - foreign key to use for join
      entity - join target
      Returns:
      the current object
    • rightJoin

      public Q rightJoin(EntityPath<?> target)
      Description copied from interface: SQLCommonQuery
      Adds a right join to the given target
      Specified by:
      rightJoin in interface SQLCommonQuery<T>
      Parameters:
      target - join target
      Returns:
      the current object
    • rightJoin

      public <E> Q rightJoin(EntityPath<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a right join to the given target
      Specified by:
      rightJoin in interface SQLCommonQuery<T>
      Parameters:
      target - right join target
      alias - alias
      Returns:
      the current object
    • rightJoin

      public <E> Q rightJoin(RelationalFunctionCall<E> target, Path<E> alias)
      Description copied from interface: SQLCommonQuery
      Adds a full join to the given target
      Specified by:
      rightJoin in interface SQLCommonQuery<T>
      Parameters:
      target - relational function call
      alias - alias
      Returns:
      the current object
    • rightJoin

      public Q rightJoin(SubQueryExpression<?> target, Path<?> alias)
      Description copied from interface: SQLCommonQuery
      Adds a right join to the given target
      Specified by:
      rightJoin in interface SQLCommonQuery<T>
      Parameters:
      target - subquery
      alias - alias
      Returns:
      the current object
    • rightJoin

      public <E> Q rightJoin(ForeignKey<E> key, RelationalPath<E> entity)
      Description copied from interface: SQLCommonQuery
      Adds a right join to the given target
      Specified by:
      rightJoin in interface SQLCommonQuery<T>
      Parameters:
      key - foreign key to use for join
      entity - join target
      Returns:
      the current object
    • on

      public Q on(Predicate condition)
    • on

      public Q on(Predicate... conditions)
      Description copied from interface: SQLCommonQuery
      Defines a filter to the last added join
      Specified by:
      on in interface SQLCommonQuery<T>
      Parameters:
      conditions - join conditions
      Returns:
      the current object
    • union

      public <RT> Union<RT> union(SubQueryExpression<RT>... sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      sq - subqueries
      Returns:
      union
    • union

      public <RT> Union<RT> union(List<SubQueryExpression<RT>> sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      sq - subqueries
      Returns:
      union
    • union

      public <RT> Q union(Path<?> alias, SubQueryExpression<RT>... sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      alias - alias for union
      sq - subqueries
      Returns:
      the current object
    • unionAll

      public <RT> Union<RT> unionAll(SubQueryExpression<RT>... sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      sq - subqueries
      Returns:
      union
    • unionAll

      public <RT> Union<RT> unionAll(List<SubQueryExpression<RT>> sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      sq - subqueries
      Returns:
      union
    • unionAll

      public <RT> Q unionAll(Path<?> alias, SubQueryExpression<RT>... sq)
      Creates an union expression for the given subqueries
      Type Parameters:
      RT -
      Parameters:
      alias - alias for union
      sq - subqueries
      Returns:
      the current object
    • fetchOne

      public T fetchOne() throws NonUniqueResultException
      Specified by:
      fetchOne in interface Fetchable<T>
      Throws:
      NonUniqueResultException
    • withRecursive

      public Q withRecursive(Path<?> alias, SubQueryExpression<?> query)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.withRecursive(alias, subQuery)
            .from(...)
       
      Specified by:
      withRecursive in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      query - subquery
      Returns:
      the current object
    • withRecursive

      public Q withRecursive(Path<?> alias, Expression<?> query)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.withRecursive(alias, subQuery)
            .from(...)
       
      Specified by:
      withRecursive in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      query - subquery
      Returns:
      the current object
    • withRecursive

      public WithBuilder<Q> withRecursive(Path<?> alias, Path<?>... columns)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.withRecursive(alias, columns...).as(subQuery)
            .from(...)
       
      Specified by:
      withRecursive in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      columns - columns to use
      Returns:
      builder for with part
    • with

      public Q with(Path<?> alias, SubQueryExpression<?> query)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.with(alias, subQuery)
            .from(...)
       
      Specified by:
      with in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      query - subquery
      Returns:
      the current object
    • with

      public Q with(Path<?> alias, Expression<?> query)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.with(alias, subQuery)
            .from(...)
       
      Specified by:
      with in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      query - subquery
      Returns:
      the current object
    • with

      public WithBuilder<Q> with(Path<?> alias, Path<?>... columns)
      Description copied from interface: SQLCommonQuery
      Adds a common table expression

      Usage

       query.with(alias, columns...).as(subQuery)
            .from(...)
       
      Specified by:
      with in interface SQLCommonQuery<T>
      Parameters:
      alias - alias for query
      columns - columns to use
      Returns:
      the current object
    • clone

      protected void clone(Q query)
    • clone

      public abstract Q clone()
      Overrides:
      clone in class Object
    • createSerializer

      protected abstract SQLSerializer createSerializer()
    • serialize

      protected SQLSerializer serialize(boolean forCountRow)
    • getSQL

      public SQLBindings getSQL()
      Get the query as an SQL query string and bindings
      Returns:
      SQL string and bindings
    • getSQL

      protected SQLBindings getSQL(SQLSerializer serializer)
    • toString

      public String toString()
      Overrides:
      toString in class QueryBase<Q extends ProjectableSQLQuery<T,Q> & Query<Q>>