All Implemented Interfaces:
Expression

public final class ExtractExpression extends AbstractSingleEncapsulatedExpression
The EXTRACT function extracts a date part from a date/time value. The date part can be YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. Some databases may support other parts.
BNF: extract_expression ::= EXTRACT(date_part_literal [FROM] scalar_expression)

date_part_literal ::= { MICROSECOND | SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER | YEAR | SECOND_MICROSECOND | MINUTE_MICROSECOND | MINUTE_SECOND | HOUR_MICROSECOND | HOUR_SECOND | HOUR_MINUTE | DAY_MICROSECOND | DAY_SECOND | DAY_MINUTE | DAY_HOUR | YEAR_MONTH, etc }

Since:
2.4
Version:
2.5
  • Constructor Details

    • ExtractExpression

      public ExtractExpression(AbstractExpression parent)
      Creates a new ExtractExpression.
      Parameters:
      parent - The parent of this expression
  • Method Details

    • accept

      public void accept(ExpressionVisitor visitor)
      Description copied from interface: Expression
      Visits this Expression by the given visitor.
      Parameters:
      visitor - The ExpressionVisitor to visit this object
    • addOrderedEncapsulatedExpressionTo

      protected void addOrderedEncapsulatedExpressionTo(List<Expression> children)
      Description copied from class: AbstractEncapsulatedExpression
      Adds the Expressions representing the encapsulated Expression.
      Overrides:
      addOrderedEncapsulatedExpressionTo in class AbstractSingleEncapsulatedExpression
      Parameters:
      children - The list used to store the string representation of the encapsulated Expression
    • getEncapsulatedExpressionQueryBNFId

      public String getEncapsulatedExpressionQueryBNFId()
      Description copied from class: AbstractSingleEncapsulatedExpression
      Returns the BNF used to parse the encapsulated expression.
      Specified by:
      getEncapsulatedExpressionQueryBNFId in class AbstractSingleEncapsulatedExpression
      Returns:
      The BNF used to parse the encapsulated expression
    • getActualFromIdentifier

      public String getActualFromIdentifier()
      Returns the actual FROM identifier found in the string representation of the JPQL query, which has the actual case that was used.
      Returns:
      The FROM identifier that was actually parsed, or an empty string if it was not parsed
    • getDatePart

      public String getDatePart()
      Returns the date part that was parsed, it is used to extract a single part of a date/time, such as year, month, day, your, etc.
      Returns:
      The part of the date/time to retrieve
    • getQueryBNF

      public JPQLQueryBNF getQueryBNF()
      Description copied from interface: Expression
      Returns the BNF of this Expression.
      Returns:
      The JPQLQueryBNF, which represents the grammar of this Expression
    • hasDatePart

      public boolean hasDatePart()
      Determines whether the date part literal was parsed or not.
      Returns:
      true if the date part literal was parsed; false otherwise
    • hasEncapsulatedExpression

      public boolean hasEncapsulatedExpression()
      Description copied from class: AbstractEncapsulatedExpression
      Determines whether something was parsed after the left parenthesis.
      Overrides:
      hasEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
      Returns:
      true if something was parsed; false otherwise
    • hasFrom

      public boolean hasFrom()
      Determines whether the identifier FROM was part of the query.
      Returns:
      true if the identifier FROM was parsed; false otherwise
    • hasSpaceAfterDatePart

      public boolean hasSpaceAfterDatePart()
      Determines whether a whitespace was found after the date part literal.
      Returns:
      true if there was a whitespace after the date part literal; false otherwise
    • hasSpaceAfterFrom

      public boolean hasSpaceAfterFrom()
      Determines whether a whitespace was found after FROM.
      Returns:
      true if there was a whitespace after FROM; false otherwise
    • isParsingComplete

      protected boolean isParsingComplete(WordParser wordParser, String word, Expression expression)
      Description copied from class: AbstractExpression
      Determines whether the parsing is complete based on what is left in the given text. The text is never empty.
      Overrides:
      isParsingComplete in class AbstractEncapsulatedExpression
      Parameters:
      wordParser - The text to parse based on the current position of the cursor
      word - The word that was retrieved from the given text, which is the first word in the text
      expression - The Expression that has already been parsed
      Returns:
      true if the text no longer can't be parsed by the current expression; false if more can be parsed
    • parseEncapsulatedExpression

      protected void parseEncapsulatedExpression(WordParser wordParser, int whitespaceCount, boolean tolerant)
      Description copied from class: AbstractEncapsulatedExpression
      Parses the encapsulated expression by starting at the current position, which is part of the given WordParser.
      Overrides:
      parseEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
      Parameters:
      wordParser - The text to parse based on the current position of the cursor
      whitespaceCount - The number of whitespace characters that were parsed after '('
      tolerant - Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
    • removeEncapsulatedExpression

      protected void removeEncapsulatedExpression()
      Description copied from class: AbstractEncapsulatedExpression
      Removes the encapsulated Expression that was parsed, it should not be part of this one. This happens when the parsed information does not have both '(' and ')'.
      Overrides:
      removeEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
    • toParsedTextEncapsulatedExpression

      protected void toParsedTextEncapsulatedExpression(StringBuilder writer, boolean actual)
      Description copied from class: AbstractEncapsulatedExpression
      Generates a string representation of the encapsulated Expression.
      Overrides:
      toParsedTextEncapsulatedExpression in class AbstractSingleEncapsulatedExpression
      Parameters:
      writer - The buffer used to append the encapsulated Expression's string representation
      actual - Determines whether to include any characters that are considered virtual, i.e. that was parsed when the query is incomplete and is needed for functionality like content assist