Class NestedFilterToSQL

  • All Implemented Interfaces:
    ExpressionVisitor, FilterVisitor

    public class NestedFilterToSQL
    extends FilterToSQL
    FilterToSQL decorator capable of encoding filters on nested attributes.

    Currently, the filters that can be translated to SQL are:

    • BBOX
    • Contains
    • Touches
    • Intersects
    • Overlaps
    • Within
    • Crosses
    • Disjoint
    • Equals
    • Beyond
    • DWithin
    • PropertyIsEqualTo
    • PropertyIsNotEqualTo
    • PropertyIsLessThan
    • PropertyIsLessThanOrEqualTo
    • PropertyIsGreaterThan
    • PropertyIsGreaterThanOrEqualTo
    • PropertyIsLike
    • PropertyIsNull
    • PropertyIsBetween

    Note that, in order to be successfully encoded, the filter must not involve more than one nested attribute (i.e. comparing nested attributes is not supported), nor attributes that are chained via polymorphic mappings.

    If the visited filter does not involve nested attributes, its encoding is delegated to the wrapped FilterToSQL instance.

    Author:
    Mauro Bartolomeoli, GeoSolutions, Stefano Costa, GeoSolutions
    • Constructor Detail

      • NestedFilterToSQL

        public NestedFilterToSQL​(FeatureTypeMapping rootMapping,
                                 FilterToSQL original)
        Constructor.
        Parameters:
        rootMapping - the feature type being queried
        original - the wrapped filter-to-SQL encoder
    • Method Detail

      • visitNestedFilter

        protected Object visitNestedFilter​(Filter filter,
                                           Object extraData,
                                           String xpath)
      • visit

        public Object visit​(Or filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Write the SQL for an Or filter
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the filter to visit
        extraData - extra data (unused by this method)
      • visit

        protected Object visit​(BinaryLogicOperator filter,
                               Object extraData)
        If replaceOrWithUnion flag is enabled this method will build main OR condition in the form of UNION queries like: SELECT id, name FROM table WHERE name = "Alf" OR name = "Rick" -> SELECT id, name FROM table WHERE name = "Alf" UNION SELECT id, name FROM table WHERE name = "Rick"
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the logic statement to be turned into SQL.
        extraData - extra filter data. Not modified directly by this method.
      • visit

        public Object visit​(PropertyIsEqualTo filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Write the SQL for this kind of filter
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the filter to visit
        extraData - extra data (unused by this method)
      • visit

        public Object visit​(PropertyIsBetween filter,
                            Object extraData)
                     throws RuntimeException
        Description copied from class: FilterToSQL
        Writes the SQL for the PropertyIsBetween Filter.
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the Filter to be visited.
        Throws:
        RuntimeException - for io exception with writer
      • visit

        public Object visit​(PropertyIsLike filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Writes the SQL for the Like Filter. Assumes the current java implemented wildcards for the Like Filter: . for multi and .? for single. And replaces them with the SQL % and _, respectively.
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the Like Filter to be visited.
      • visit

        public Object visit​(PropertyIsGreaterThan filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Write the SQL for this kind of filter
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the filter to visit
        extraData - extra data (unused by this method)
      • visit

        public Object visit​(PropertyIsLessThan filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Write the SQL for this kind of filter
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the filter to visit
        extraData - extra data (unused by this method)
      • visit

        public Object visit​(PropertyIsNotEqualTo filter,
                            Object extraData)
        Description copied from class: FilterToSQL
        Write the SQL for this kind of filter
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the filter to visit
        extraData - extra data (unused by this method)
      • visit

        public Object visit​(PropertyIsNull filter,
                            Object extraData)
                     throws RuntimeException
        Description copied from class: FilterToSQL
        Writes the SQL for the Null Filter.
        Specified by:
        visit in interface FilterVisitor
        Overrides:
        visit in class FilterToSQL
        Parameters:
        filter - the null filter to be written to SQL.
        Throws:
        RuntimeException - for io exception with writer
      • isNestedFilter

        public static boolean isNestedFilter​(Filter filter)
        A filter is considered nested if it operates on at least one nested attribute.

        Technically, this means that at least one of the expressions in it is an instance of NestedAttributeExpression.

        Parameters:
        filter - the filter to test
        Returns:
        true if the filter involves at least one nested attribute, false otherwise
      • setSelectClause

        public void setSelectClause​(String selectClause)
      • isReplaceOrWithUnion

        public boolean isReplaceOrWithUnion()
      • setReplaceOrWithUnion

        public void setReplaceOrWithUnion​(boolean replaceOrWithUnion)