Package org.geotools.appschema.jdbc
Class NestedFilterToSQL
- Object
-
- FilterToSQL
-
- 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class FilterToSQL
FilterToSQL.FieldEncoder
-
-
Field Summary
-
Fields inherited from class FilterToSQL
capabilities, currentDimension, currentGeometry, currentSRID, databaseSchema, encodingFunction, escapeBackslash, featureType, fieldEncoder, filterFactory, inEncodingEnabled, inline, IO_ERROR, LOGGER, out, primaryKey, sqlNameEscape
-
-
Constructor Summary
Constructors Constructor Description NestedFilterToSQL(FeatureTypeMapping rootMapping, FilterToSQL original)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
encode(Filter filter)
Performs the encoding, sends the encoded sql to the writer passed in.static boolean
isNestedFilter(Filter filter)
A filter is considered nested if it operates on at least one nested attribute.boolean
isReplaceOrWithUnion()
void
setReplaceOrWithUnion(boolean replaceOrWithUnion)
void
setSelectClause(String selectClause)
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"Object
visit(Or filter, Object extraData)
Write the SQL for an Or filterObject
visit(PropertyIsBetween filter, Object extraData)
Writes the SQL for the PropertyIsBetween Filter.Object
visit(PropertyIsEqualTo filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsGreaterThan filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsLessThanOrEqualTo filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsLessThan filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsLike filter, Object extraData)
Writes the SQL for the Like Filter.Object
visit(PropertyIsNotEqualTo filter, Object extraData)
Write the SQL for this kind of filterObject
visit(PropertyIsNull filter, Object extraData)
Writes the SQL for the Null Filter.Object
visit(BBOX filter, Object extraData)
Object
visit(Beyond filter, Object extraData)
Object
visit(Contains filter, Object extraData)
Object
visit(Crosses filter, Object extraData)
Object
visit(Disjoint filter, Object extraData)
Object
visit(DWithin filter, Object extraData)
Object
visit(Equals filter, Object extraData)
Object
visit(Intersects filter, Object extraData)
Object
visit(Overlaps filter, Object extraData)
Object
visit(Touches filter, Object extraData)
Object
visit(Within filter, Object extraData)
protected Object
visitNestedFilter(Filter filter, Object extraData, String xpath)
-
Methods inherited from class FilterToSQL
cast, createFilterCapabilities, encode, encodeBinaryComparisonOperator, encodeToString, encodeToString, escapeLiteral, escapeName, evaluateLiteral, getCapabilities, getDatabaseSchema, getDistanceInNativeUnits, getExpressionType, getFeatureType, getFunctionName, getFunctionReturnType, getParameter, getPrimaryKey, getSqlNameEscape, isBinaryExpression, isEscapeBackslash, isInEncodingEnabled, setCapabilities, setDatabaseSchema, setEscapeBackslash, setFeatureType, setFieldEncoder, setInEncodingEnabled, setInline, setPrimaryKey, setSqlNameEscape, setWriter, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitBinaryComparisonOperator, visitBinarySpatialOperator, visitBinarySpatialOperator, visitBinarySpatialOperator, visitBinaryTemporalOperator, visitBinaryTemporalOperator, visitBinaryTemporalOperator, visitInFunction, visitLiteralGeometry, visitLiteralTimePeriod, visitNullFilter, writeBinaryExpression, writeBinaryExpressionMember, writeLiteral
-
-
-
-
Constructor Detail
-
NestedFilterToSQL
public NestedFilterToSQL(FeatureTypeMapping rootMapping, FilterToSQL original)
Constructor.- Parameters:
rootMapping
- the feature type being queriedoriginal
- the wrapped filter-to-SQL encoder
-
-
Method Detail
-
encode
public void encode(Filter filter) throws FilterToSQLException
Description copied from class:FilterToSQL
Performs the encoding, sends the encoded sql to the writer passed in.- Overrides:
encode
in classFilterToSQL
- Parameters:
filter
- the Filter to be encoded.- Throws:
FilterToSQLException
- If filter type not supported, or if there were io problems.
-
visitNestedFilter
protected Object visitNestedFilter(Filter filter, Object extraData, String xpath)
-
visit
public Object visit(BBOX filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Contains filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Touches filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Intersects filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Overlaps filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Within filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Crosses filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Disjoint filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Equals filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Beyond filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
visit
public Object visit(Or filter, Object extraData)
Description copied from class:FilterToSQL
Write the SQL for an Or filter- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- 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 classFilterToSQL
- Parameters:
filter
- the logic statement to be turned into SQL.extraData
- extra filter data. Not modified directly by this method.
-
visit
public Object visit(DWithin filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
-
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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- 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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- 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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the Like Filter to be visited.
-
visit
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)
Description copied from class:FilterToSQL
Write the SQL for this kind of filter- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- extra data (unused by this method)
-
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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- 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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- extra data (unused by this method)
-
visit
public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData)
Description copied from class:FilterToSQL
Write the SQL for this kind of filter- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- 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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- Parameters:
filter
- the filter to visitextraData
- 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 interfaceFilterVisitor
- Overrides:
visit
in classFilterToSQL
- 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)
-
-