Class ExtractExpression

  • 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 }

    Version:
    2.5
    Author:
    James Sutherland
    Since:
    2.4
    • Constructor Detail

      • ExtractExpression

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

      • getActualFromIdentifier

        public java.lang.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 java.lang.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
      • 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
      • 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,
                                            java.lang.String word,
                                            Expression expression)
        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)
        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
      • toParsedTextEncapsulatedExpression

        protected void toParsedTextEncapsulatedExpression​(java.lang.StringBuilder writer,
                                                          boolean actual)
        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