Class SelectionClauseWriter

java.lang.Object
org.apache.sis.internal.filter.Visitor<AbstractFeature,SelectionClause>
org.apache.sis.internal.sql.feature.SelectionClauseWriter

public class SelectionClauseWriter extends Visitor<AbstractFeature,SelectionClause>
Converter from filters/expressions to the WHERE part of SQL statement. This base class handles ANSI compliant SQL. Subclasses can add database-specific syntax.

As soon as a filter or expression is not supported by this interpreter, the writing of the SQL statement stops and next filters operations will be executed with Java code.

Implementation notes

For now, we over-use parenthesis to ensure consistent operator priority. In the future, we could evolve this component to provide more elegant transcription of filter groups.

Thread-safety

Instances of this classes shall be unmodified after construction and thus thread-safe. Information about the state of a conversion to SQL is stored in SelectionClause.
Since:
1.1
Version:
1.1
Author:
Alexis Manin (Geomatys), Martin Desruisseaux (Geomatys)
  • Field Details

  • Constructor Details

    • SelectionClauseWriter

      protected SelectionClauseWriter(SelectionClauseWriter source)
      Creates a new converter initialized to the same handlers than the specified converter. The given source is usually DEFAULT.
      Parameters:
      source - the converter from which to copy the handlers.
  • Method Details

    • duplicate

      protected SelectionClauseWriter duplicate()
      Creates a new converter of the same class than this and initialized with the same data. This method is invoked before to remove handlers for functions that are unsupported on the target database software.
      Returns:
      a converter initialized to a copy of this.
    • typeNotFound

      protected final void typeNotFound(Enum<?> type, Filter<AbstractFeature> filter, SelectionClause sql)
      Invoked when an unsupported filter is found. The SQL string is marked as invalid and may be truncated (later) to the length that it has the last time that it was valid.
      Overrides:
      typeNotFound in class Visitor<AbstractFeature,SelectionClause>
      Parameters:
      type - the filter type which has not been found, or null if is null.
      filter - the filter (may be null).
      sql - where to write the result of all actions.
    • typeNotFound

      protected final void typeNotFound(String type, Expression<AbstractFeature,?> expression, SelectionClause sql)
      Invoked when an unsupported expression is found. The SQL string is marked as invalid and may be truncated (later) to the length that it has the last time that it was valid.
      Overrides:
      typeNotFound in class Visitor<AbstractFeature,SelectionClause>
      Parameters:
      type - the expression type which has not been found, or null if is null.
      expression - the expression (may be null).
      sql - where to write the result of all actions.
    • writeBinaryOperator

      protected final void writeBinaryOperator(SelectionClause sql, Filter<AbstractFeature> filter, String operator)
      Writes the expressions of a filter as a binary operator. The filter must have exactly two expressions, otherwise the SQL will be declared invalid.
      Parameters:
      sql - where to append the SQL clause.
      filter - the filter for which to append the expressions.
      operator - the operator to write between the expressions.