Module org.jooq
Package org.jooq

Interface ParseListener

All Superinterfaces:
EventListener
All Known Implementing Classes:
CallbackParseListener, DefaultParseListener

@Pro public interface ParseListener extends EventListener
A listener that allows for parsing custom SQL.

This listener will be called when syntactic context allows for specific types of objects to be parsed. Implementations must return null if they are unable to parse anything at the given location, in case of which default parser behaviour will apply.

Author:
Lukas Eder
  • Method Details

    • parseStart

      default void parseStart(ParseContext ctx) throws ParserException
      Callback method invoked before the parser starts parsing a SQL string.

      Use this to perform quick modifications to the SQL string where necessary, e.g. by removing unsupported (but irrelevant) syntax from the input string of ParseContext.characters().

      Parameters:
      ctx - The context containing information about the parsing, as well as API to interact with it.
      Throws:
      ParserException
    • parseEnd

      default void parseEnd(ParseContext ctx) throws ParserException
      Callback method invoked after the parser successfully completes parsing a SQL string.

      Use this to clean up resources or perform post-parsing validations.

      Parameters:
      ctx - The context containing information about the parsing, as well as API to interact with it.
      Throws:
      ParserException
    • parseField

      @Nullable default @Nullable Field<?> parseField(ParseContext ctx) throws ParserException
      Attempt to parse a Field expression.

      This parses a "term", meaning the callback does not interfere with any operators or operator precedence, but will be called only when a field term can appear. For example, with input SQL like A + B, the callback is called at the positions of A and B. Client code does not have to (and should not) handle the + operator, or its precedence.

      Parameters:
      ctx - The context containing information about the parsing, as well as API to interact with it.
      Returns:
      The Field expression if a field could be parsed, or null otherwise.
      Throws:
      ParserException - Any syntax error or other exception that may have occurred while attempting to parse a Field expression.
    • parseTable

      @Nullable default @Nullable Table<?> parseTable(ParseContext ctx) throws ParserException
      Attempt to parse a Table expression.

      This parses a "table factor", meaning the callback does not interfere with any operators or operator precedence, but will be called only when a condition term can appear. For example, with input SQL like A join B, the callback is called at the positions of A and B. Client code does not have to (and should not) handle the join operator, or its precedence.

      Parameters:
      ctx - The context containing information about the parsing, as well as API to interact with it.
      Returns:
      The Table expression if a table could be parsed, or null otherwise.
      Throws:
      ParserException - Any syntax error or other exception that may have occurred while attempting to parse a Table expression.
    • parseCondition

      @Nullable default @Nullable Condition parseCondition(ParseContext ctx) throws ParserException
      Attempt to parse a Condition expression.

      This parses a "predicate", meaning the callback does not interfere with any operators or operator precedence, but will be called only when a condition term can appear. For example, with input SQL like A or B, the callback is called at the positions of A and B. Client code does not have to (and should not) handle the or operator, or its precedence.

      Parameters:
      ctx - The context containing information about the parsing, as well as API to interact with it.
      Returns:
      The Condition expression if a condition could be parsed, or null otherwise.
      Throws:
      ParserException - Any syntax error or other exception that may have occurred while attempting to parse a Condition expression.
    • onParseStart

      static CallbackParseListener onParseStart(Consumer<? super ParseContext> onParseStart)
      Create a ParseListener with a parseStart(ParseContext) implementation.
    • onParseEnd

      static CallbackParseListener onParseEnd(Consumer<? super ParseContext> onParseEnd)
      Create a ParseListener with a parseEnd(ParseContext) implementation.
    • onParseField

      static CallbackParseListener onParseField(Function<? super ParseContext,? extends Field<?>> onParseField)
      Create a ParseListener with a parseField(ParseContext) implementation.
    • onParseTable

      static CallbackParseListener onParseTable(Function<? super ParseContext,? extends Table<?>> onParseTable)
      Create a ParseListener with a parseTable(ParseContext) implementation.
    • onParseCondition

      static CallbackParseListener onParseCondition(Function<? super ParseContext,? extends Condition> onParseCondition)
      Create a ParseListener with a parseCondition(ParseContext) implementation.