All Implemented Interfaces:
Serializable, Cloneable

public class SubSelectExpression extends BaseExpression
This is used to support subselects. The subselect represents a mostly independent (has own expression builder) query using a report query. Subselects can be used for, in (single column), exists (empty or non-empty), comparisons (single value).
See Also:
  • Field Details

    • hasBeenNormalized

      protected boolean hasBeenNormalized
    • subQuery

      protected ReportQuery subQuery
    • attribute

      protected String attribute
    • returnType

      protected Class<?> returnType
    • criteriaBase

      protected Expression criteriaBase
  • Constructor Details

    • SubSelectExpression

      public SubSelectExpression()
    • SubSelectExpression

      public SubSelectExpression(ReportQuery query, Expression baseExpression)
  • Method Details

    • equals

      public boolean equals(Object object)
      INTERNAL: Return if the expression is equal to the other. This is used to allow dynamic expression's SQL to be cached.
      Overrides:
      equals in class Expression
    • descriptionOfNodeType

      public String descriptionOfNodeType()
      INTERNAL: Used in debug printing of this node.
      Overrides:
      descriptionOfNodeType in class Expression
    • getSubQuery

      public ReportQuery getSubQuery()
    • initializeCountSubQuery

      protected void initializeCountSubQuery()
      INTERNAL: This method creates a report query that counts the number of values in baseExpression.anyOf(attribute) For most queries, a ReportQuery will be created that does a simple count using an anonymous query. In the case of a DirectCollectionMapping, the ReportQuery will use the baseExpression to create a join to the table containing the Direct fields and count based on that join.
    • isSubSelectExpression

      public boolean isSubSelectExpression()
      INTERNAL:
      Overrides:
      isSubSelectExpression in class Expression
    • iterateOn

      public void iterateOn(ExpressionIterator iterator)
      INTERNAL: For iterating using an inner class
      Overrides:
      iterateOn in class Expression
    • normalize

      public Expression normalize(ExpressionNormalizer normalizer)
      INTERNAL: The subquery must be normalized with the knowledge of the outer statement for outer references and correct aliasing. For CR#4223 it will now be normalized after the outer statement is, rather than somewhere in the middle of the outer statement's normalize.
      Overrides:
      normalize in class Expression
    • normalizeSubSelect

      public Expression normalizeSubSelect(ExpressionNormalizer normalizer, Map clonedExpressions)
      INTERNAL: Normalize this expression now that the parent statement has been normalized. For CR#4223
    • postCopyIn

      protected void postCopyIn(Map alreadyDone)
      The query must be cloned, and the sub-expression must be cloned using the same outer expression identity.
      Overrides:
      postCopyIn in class BaseExpression
    • printCustomSQL

      protected void printCustomSQL(ExpressionSQLPrinter printer)
      Print the sub query to the printer.
    • printSQL

      public void printSQL(ExpressionSQLPrinter printer)
      Print the sub query to the printer.
      Specified by:
      printSQL in class Expression
    • rebuildOn

      public Expression rebuildOn(Expression newBase)
      Should not rebuild as has its on expression builder.
      Specified by:
      rebuildOn in class Expression
      See Also:
    • resetPlaceHolderBuilder

      public void resetPlaceHolderBuilder(ExpressionBuilder queryBuilder)
      INTERNAL: Search the tree for any expressions (like SubSelectExpressions) that have been built using a builder that is not attached to the query. This happens in case of an Exists call using a new ExpressionBuilder(). This builder needs to be replaced with one from the query.
      Overrides:
      resetPlaceHolderBuilder in class BaseExpression
    • setSubQuery

      public void setSubQuery(ReportQuery subQuery)
    • twistedForBaseAndContext

      public Expression twistedForBaseAndContext(Expression newBase, Expression context, Expression oldBase)
      Description copied from class: Expression
      INTERNAL: Rebuild myself against the base, with the values of parameters supplied by the context expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) into part of some larger expression. You normally would not call this directly, instead calling twist See the comment there for more details"
      Overrides:
      twistedForBaseAndContext in class Expression
    • writeDescriptionOn

      public void writeDescriptionOn(BufferedWriter writer) throws IOException
      INTERNAL: Used to print a debug form of the expression tree.
      Overrides:
      writeDescriptionOn in class Expression
      Throws:
      IOException
    • writeSubexpressionsTo

      public void writeSubexpressionsTo(BufferedWriter writer, int indent) throws IOException
      INTERNAL: Used in SQL printing.
      Overrides:
      writeSubexpressionsTo in class Expression
      Throws:
      IOException
    • writeFields

      public void writeFields(ExpressionSQLPrinter printer, List<DatabaseField> newFields, SQLSelectStatement statement)
      INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...) This allows a sub query in the select clause.
      Overrides:
      writeFields in class Expression
    • createSubSelectExpressionForCount

      public static SubSelectExpression createSubSelectExpressionForCount(Expression outerQueryBaseExpression, Expression outerQueryCriteria, String attribute, Class<?> returnType)
      INTERNAL: This factory method is used to build a subselect that will do a count. It will count the number of items in baseExpression.anyOf(attribute).