| java.lang.Object org.geotools.data.jdbc.FilterToSQL
All known Subclasses: org.geotools.data.db2.filter.SQLEncoderDB2, org.geotools.data.geometryless.filter.SQLEncoderBBOX, org.geotools.arcsde.filter.FilterToSQLSDE, org.geotools.filter.UnaliasSQLEncoder,
FilterToSQL | public class FilterToSQL implements FilterVisitor,ExpressionVisitor(Code) | | Encodes a filter into a SQL WHERE statement. It should hopefully be generic
enough that any SQL database will work with it.
This generic SQL encoder should eventually
be able to encode all filters except Geometry Filters.
This is because the OGC's SFS for SQL document specifies
two ways of doing SQL databases, one with native geometry types and one
without. To implement an encoder for one of the two types simply subclass
off of this encoder and put in the proper GeometryFilter visit method. Then
add the filter types supported to the capabilities by overriding the
{
FilterToSQL.createFilterCapabilities() method.
This version was ported from the original to support org.opengis.filter type
Filters.
author: originally by Chris Holmes, TOPP author: ported by Saul Farber, MassGIS |
Method Summary | |
protected FilterCapabilities | createFilterCapabilities() Sets the capabilities of this filter. | public void | encode(Filter filter) Performs the encoding, sends the encoded sql to the writer passed in. | public String | encodeToString(Filter filter) purely a convenience method. | public String | escapeName(String name) Surrounds a name with the SQL escape character. | final public synchronized FilterCapabilities | getCapabilities() Describes the capabilities of this encoder.
Performs lazy creation of capabilities.
If you're subclassing this class, override createFilterCapabilities
to declare which filtercapabilities you support. | public void | setFIDMapper(FIDMapper mapper) Sets the FIDMapper that will be used in subsequente visit calls. | public void | setFeatureType(FeatureType featureType) Sets the featuretype the encoder is encoding sql for.
This is used for context for attribute expressions when encoding to sql. | public void | setSqlNameEscape(String escape) Sets the SQL name escape string.
The value of this string is prefixed and appended to table schema names,
table names and column names in an SQL statement to support mixed-case
and non-English names. | public Object | visit(ExcludeFilter filter, Object extraData) | public Object | visit(IncludeFilter filter, Object extraData) | public Object | visit(PropertyIsBetween filter, Object extraData) Writes the SQL for the PropertyIsBetween Filter. | public Object | visit(PropertyIsLike filter, Object extraData) Writes the SQL for the Like Filter. | public Object | visit(And filter, Object extraData) | public Object | visit(Not filter, Object extraData) | public Object | visit(Or filter, Object extraData) | protected Object | visit(BinaryLogicOperator filter, Object extraData) Common implementation for BinaryLogicOperator filters. | public Object | visit(PropertyIsEqualTo filter, Object extraData) | public Object | visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) | public Object | visit(PropertyIsGreaterThan filter, Object extraData) | public Object | visit(PropertyIsLessThan filter, Object extraData) | public Object | visit(PropertyIsLessThanOrEqualTo filter, Object extraData) | public Object | visit(PropertyIsNotEqualTo filter, Object extraData) | public Object | visit(PropertyIsNull filter, Object extraData) Writes the SQL for the Null Filter. | public Object | visit(Id filter, Object extraData) | public Object | visit(BBOX filter, Object extraData) | public Object | visit(Beyond filter, Object extraData) | public Object | visit(Contains filter, Object extraData) | public Object | visit(Crosses filter, Object extraData) | public Object | visit(Disjoint filter, Object extraData) | public Object | visit(DWithin filter, Object extraData) | public Object | visit(Equals filter, Object extraData) | public Object | visit(Intersects filter, Object extraData) | public Object | visit(Overlaps filter, Object extraData) | public Object | visit(Touches filter, Object extraData) | public Object | visit(Within filter, Object extraData) | public Object | visit(PropertyName expression, Object extraData) Writes the SQL for the attribute Expression.
NOTE: This (default) implementation doesn't handle XPath at all.
Not sure exactly how to do that in a general way. | public Object | visit(Literal expression, Object context) | public Object | visit(Add expression, Object extraData) | public Object | visit(Divide expression, Object extraData) | public Object | visit(Multiply expression, Object extraData) | public Object | visit(Subtract expression, Object extraData) | protected Object | visit(BinaryExpression expression, Object extraData) Writes the SQL for the Math Expression. | public Object | visit(Function expression, Object extraData) Writes sql for a function expression. | public Object | visit(NilExpression expression, Object extraData) | protected void | visitBinaryComparisonOperator(BinaryComparisonOperator filter, Object extraData) Common implementation for BinaryComparisonOperator filters. | protected Object | visitBinarySpatialOperator(BinarySpatialOperator filter, Object extraData) | protected void | visitLiteralGeometry(Literal expression) | public Object | visitNullFilter(Object extraData) Encodes a null filter value. |
IO_ERROR | final protected static String IO_ERROR(Code) | | error message for exceptions
|
featureType | protected FeatureType featureType(Code) | | the schmema the encoder will be used to be encode sql for
|
mapper | protected FIDMapper mapper(Code) | | the fid mapper used to encode the fid filters
|
out | protected Writer out(Code) | | where to write the constructed string from visiting the filters.
|
FilterToSQL | public FilterToSQL()(Code) | | Default constructor
|
createFilterCapabilities | protected FilterCapabilities createFilterCapabilities()(Code) | | Sets the capabilities of this filter.
FilterCapabilities for this Filter |
encode | public void encode(Filter filter) throws FilterToSQLException(Code) | | Performs the encoding, sends the encoded sql to the writer passed in.
Parameters: filter - the Filter to be encoded. throws: OpenGISFilterToOpenGISFilterToSQLEncoderException - If filter type not supported, or if therewere io problems. |
encodeToString | public String encodeToString(Filter filter) throws FilterToSQLException(Code) | | purely a convenience method.
Equivalent to:
StringWriter out = new StringWriter();
new FilterToSQL(out).encode(filter);
out.getBuffer().toString();
Parameters: filter - a string representing the filter encoded to SQL. throws: FilterToSQLException - |
escapeName | public String escapeName(String name)(Code) | | Surrounds a name with the SQL escape character.
Parameters: name - DOCUMENT ME! |
getCapabilities | final public synchronized FilterCapabilities getCapabilities()(Code) | | Describes the capabilities of this encoder.
Performs lazy creation of capabilities.
If you're subclassing this class, override createFilterCapabilities
to declare which filtercapabilities you support. Don't use
this method.
The capabilities supported by this encoder. |
setFIDMapper | public void setFIDMapper(FIDMapper mapper)(Code) | | Sets the FIDMapper that will be used in subsequente visit calls. There
must be a FIDMapper in order to invoke the FIDFilter encoder.
Parameters: mapper - |
setFeatureType | public void setFeatureType(FeatureType featureType)(Code) | | Sets the featuretype the encoder is encoding sql for.
This is used for context for attribute expressions when encoding to sql.
Parameters: featureType - |
setSqlNameEscape | public void setSqlNameEscape(String escape)(Code) | | Sets the SQL name escape string.
The value of this string is prefixed and appended to table schema names,
table names and column names in an SQL statement to support mixed-case
and non-English names. Without this, the DBMS may assume a mixed-case
name in the query should be treated as upper-case and an SQLCODE of
-204 or 206 may result if the name is not found.
Typically this is the double-quote character, ", but may not be for all
databases.
For example, consider the following query:
SELECT Geom FROM Spear.ArchSites May be interpreted by the database as:
SELECT GEOM FROM SPEAR.ARCHSITES If the column and table names were
actually created using mixed-case, the query needs to be specified as:
SELECT "Geom" from "Spear"."ArchSites"
Parameters: escape - the character to be used to escape database names |
visit | public Object visit(ExcludeFilter filter, Object extraData)(Code) | | See Also: FilterVisitor.visit(ExcludeFilterObject) See Also: Writes the SQL for the IncludeFilter by writing "FALSE". Parameters: the - filter to be visited |
visit | public Object visit(IncludeFilter filter, Object extraData)(Code) | | See Also: FilterVisitor.visit(IncludeFilterObject) See Also: Writes the SQL for the IncludeFilter by writing "TRUE". Parameters: the - filter to be visited |
visit | public Object visit(PropertyIsLike filter, Object extraData)(Code) | | 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.
Parameters: filter - the Like Filter to be visited. |
visit | public Object visit(And filter, Object extraData)(Code) | | Write the SQL for an And filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(Not filter, Object extraData)(Code) | | Write the SQL for a Not filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(Or filter, Object extraData)(Code) | | Write the SQL for an Or filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | protected Object visit(BinaryLogicOperator filter, Object extraData)(Code) | | Common implementation for BinaryLogicOperator filters. This way
they're all handled centrally.
Parameters: filter - the logic statement to be turned into SQL. Parameters: extraData - extra filter data. Not modified directly by this method. |
visit | public Object visit(PropertyIsEqualTo filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyIsGreaterThan filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyIsLessThan filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyIsNotEqualTo filter, Object extraData)(Code) | | Write the SQL for this kind of filter
Parameters: filter - the filter to visit Parameters: extraData - extra data (unused by this method) |
visit | public Object visit(PropertyName expression, Object extraData) throws RuntimeException(Code) | | Writes the SQL for the attribute Expression.
NOTE: This (default) implementation doesn't handle XPath at all.
Not sure exactly how to do that in a general way. How to map from the XPATH of the
property name into a column or something? Use propertyName.evaluate()?
Parameters: expression - the attribute to turn to SQL. throws: RuntimeException - for io exception with writer |
visitBinaryComparisonOperator | protected void visitBinaryComparisonOperator(BinaryComparisonOperator filter, Object extraData) throws RuntimeException(Code) | | Common implementation for BinaryComparisonOperator filters. This way
they're all handled centrally.
DJB: note, postgis overwrites this implementation because of the way
null is handled. This is for filters and filters
are handled. They will come here with "property = null".
NOTE:
SELECT * FROM WHERE isnull; -- postgresql
SELECT * FROM WHERE isnull(); -- oracle???
Parameters: filter - the comparison to be turned into SQL. throws: RuntimeException - for io exception with writer
visitBinarySpatialOperator | protected Object visitBinarySpatialOperator(BinarySpatialOperator filter, Object extraData)(Code) | | See Also: FilterVisitor.visit |
visitLiteralGeometry | protected void visitLiteralGeometry(Literal expression) throws IOException(Code) | | Subclasses must implement this method in order to encode geometry
filters according to the specific database implementation
Parameters: expression - throws: IOException - DOCUMENT ME! throws: RuntimeException - DOCUMENT ME! |
visitNullFilter | public Object visitNullFilter(Object extraData)(Code) | | Encodes a null filter value. The current implementation
does exactly nothing.
Parameters: extraData - extra data to be used to evaluate the filter the untouched extraData parameter |
|
|
|