org.geotools.filter
Class SQLEncoder

Object
  extended by SQLEncoder
All Implemented Interfaces:
FilterVisitor, FilterVisitor2

Deprecated. Please use org.geotools.data.jdbc.FilterToSQL which uses opengis filters instead of these geotools filters.

public class SQLEncoder
extends Object
implements FilterVisitor2

Encodes a filter into a SQL WHERE statement. It should hopefully be generic enough that any SQL database will work with it, though it has only been tested with MySQL and Postgis. This generic SQL encoder should eventually be able to encode all filters except Geometry Filters (currently LikeFilters are not yet fully implemented, but when they are they should be generic enough). 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 in the static capabilities.addType block.

Author:
Chris Holmes, TOPP
TODO:
TODO: Implement LikeFilter encoding, need to figure out escape chars, the rest of the code should work right. Once fixed be sure to add the LIKE type to capabilities, so others know that they can be encoded., REVISIT: need to figure out exceptions, we're currently eating io errors, which is bad. Probably need a generic visitor exception.

Field Summary
protected  FilterCapabilities capabilities
          Deprecated. The filter types that this class can encode
protected static Map comparisions
          Deprecated. Map of comparison types to sql representation
protected  Class context
          Deprecated. A type to use as context when encoding literal.
protected  SimpleFeatureType featureType
          Deprecated. the schmema the encoder will be used to be encode sql for
protected static String IO_ERROR
          Deprecated. error message for exceptions
protected  FIDMapper mapper
          Deprecated. the fid mapper used to encode the fid filters
protected  Writer out
          Deprecated. where to write the constructed string from visiting the filters.
 
Constructor Summary
SQLEncoder()
          Deprecated. Empty constructor
SQLEncoder(Writer out, Filter filter)
          Deprecated. Convenience constructor to perform the whole encoding process at once.
 
Method Summary
protected  FilterCapabilities createFilterCapabilities()
          Deprecated. Sets the capabilities of this filter.
 String encode(Expression expression)
          Deprecated. Performs the encoding, returns a string of the encoded SQL.
 String encode(Filter filter)
          Deprecated. Performs the encoding, returns a string of the encoded SQL.
 void encode(Writer out, Expression expression)
          Deprecated.  
 void encode(Writer out, Filter filter)
          Deprecated. Performs the encoding, sends the encoded sql to the writer passed in.
 String escapeName(String name)
          Deprecated. Surrounds a name with the SQL escape character.
 FilterCapabilities getCapabilities()
          Deprecated. Describes the capabilities of this encoder.
protected  String getColnameEscape()
          Deprecated. the escapeName method is preferred over this, it automatically returns the name properly escaped, since that's all getColnameEscape was being used for.
 FIDMapper getFIDMapper()
          Deprecated.  
 void setColnameEscape(String escape)
          Deprecated. Use setSqlNameEscape instead, as it is more aptly named.
 void setFeatureType(SimpleFeatureType featureType)
          Deprecated. Sets the featuretype the encoder is encoding sql for.
 void setFIDMapper(FIDMapper mapper)
          Deprecated. Sets the FIDMapper that will be used in subsequente visit calls.
 void setSqlNameEscape(String escape)
          Deprecated. Sets the SQL name escape string.
 void visit(AttributeExpression expression)
          Deprecated. Writes the SQL for the attribute Expression.
 void visit(BetweenFilter filter)
          Deprecated. Writes the SQL for the Between Filter.
 void visit(CompareFilter filter)
          Deprecated. Writes the SQL for a Compare Filter.
 void visit(ExcludeFilter filter)
          Deprecated.  
 void visit(Expression expression)
          Deprecated. Writes the SQL for the attribute Expression.
 void visit(FidFilter filter)
          Deprecated. Encodes an FidFilter.
 void visit(Filter filter)
          Deprecated. This should never be called.
 void visit(FunctionExpression expression)
          Deprecated. Writes sql for a function expression.
 void visit(GeometryFilter filter)
          Deprecated. Called when accept is called on a Geometry Filter.
 void visit(IncludeFilter filter)
          Deprecated.  
 void visit(LikeFilter filter)
          Deprecated. Writes the SQL for the Like Filter.
 void visit(LiteralExpression expression)
          Deprecated. Export the contents of a Literal Expresion
 void visit(LogicFilter filter)
          Deprecated. Writes the SQL for the Logic Filter.
 void visit(MathExpression expression)
          Deprecated. Writes the SQL for the Math Expression.
 void visit(NullFilter filter)
          Deprecated. Writes the SQL for the Null Filter.
protected  void visitLiteralGeometry(LiteralExpression expression)
          Deprecated. Subclasses must implement this method in order to encode geometry filters according to the specific database implementation
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IO_ERROR

protected static final String IO_ERROR
Deprecated. 
error message for exceptions

See Also:
Constant Field Values

capabilities

protected FilterCapabilities capabilities
Deprecated. 
The filter types that this class can encode


comparisions

protected static Map comparisions
Deprecated. 
Map of comparison types to sql representation


out

protected Writer out
Deprecated. 
where to write the constructed string from visiting the filters.


mapper

protected FIDMapper mapper
Deprecated. 
the fid mapper used to encode the fid filters


featureType

protected SimpleFeatureType featureType
Deprecated. 
the schmema the encoder will be used to be encode sql for


context

protected Class context
Deprecated. 
A type to use as context when encoding literal. NOTE: when we move to geoapi filter visitor api, this will not be needed.

Constructor Detail

SQLEncoder

public SQLEncoder()
Deprecated. 
Empty constructor


SQLEncoder

public SQLEncoder(Writer out,
                  Filter filter)
           throws SQLEncoderException
Deprecated. 
Convenience constructor to perform the whole encoding process at once.

Parameters:
out - the writer to encode the SQL to.
filter - the Filter to be encoded.
Throws:
SQLEncoderException - If there were problems encoding
Method Detail

setFeatureType

public void setFeatureType(SimpleFeatureType featureType)
Deprecated. 
Sets the featuretype the encoder is encoding sql for.

This is used for context for attribute expressions when encoding to sql.

Parameters:
featureType -

setFIDMapper

public void setFIDMapper(FIDMapper mapper)
Deprecated. 
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 -

getFIDMapper

public FIDMapper getFIDMapper()
Deprecated. 

createFilterCapabilities

protected FilterCapabilities createFilterCapabilities()
Deprecated. 
Sets the capabilities of this filter.

Returns:
FilterCapabilities for this Filter

encode

public void encode(Writer out,
                   Filter filter)
            throws SQLEncoderException
Deprecated. 
Performs the encoding, sends the encoded sql to the writer passed in.

Parameters:
out - the writer to encode the SQL to.
filter - the Filter to be encoded.
Throws:
SQLEncoderException - If filter type not supported, or if there were io problems.

encode

public String encode(Filter filter)
              throws SQLEncoderException
Deprecated. 
Performs the encoding, returns a string of the encoded SQL.

Parameters:
filter - the Filter to be encoded.
Returns:
the string of the SQL where statement.
Throws:
SQLEncoderException - If filter type not supported, or if there were io problems.

encode

public void encode(Writer out,
                   Expression expression)
            throws SQLEncoderException
Deprecated. 
Throws:
SQLEncoderException

encode

public String encode(Expression expression)
              throws SQLEncoderException
Deprecated. 
Performs the encoding, returns a string of the encoded SQL.

Parameters:
expression - the expression to be encoded.
Returns:
the correspondent SQL snippet
Throws:
SQLEncoderException - If expression type not supported, or if there were io problems.

getCapabilities

public FilterCapabilities getCapabilities()
Deprecated. 
Describes the capabilities of this encoder.

Performs lazy creation of capabilities.

Returns:
The capabilities supported by this encoder.

visit

public void visit(Filter filter)
Deprecated. 
This should never be called. This can only happen if a subclass of AbstractFilter failes to implement its own version of accept(FilterVisitor);

Specified by:
visit in interface FilterVisitor
Parameters:
filter - The filter to visit
Throws:
RuntimeException - for IO Encoding problems.
TODO:
REVISIT: I don't think Filter.INCLUDE and Filter.EXCLUDE should be handled here. They should have their own methods, but they don't have interfaces, so I don't know if that's possible.

visit

public void visit(BetweenFilter filter)
           throws RuntimeException
Deprecated. 
Writes the SQL for the Between Filter.

Specified by:
visit in interface FilterVisitor
Parameters:
filter - the Filter to be visited.
Throws:
RuntimeException - for io exception with writer

visit

public void visit(LikeFilter filter)
           throws UnsupportedOperationException
Deprecated. 
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. Currently does nothing, and should not be called, not included in the capabilities.

Specified by:
visit in interface FilterVisitor
Parameters:
filter - the Like Filter to be visited.
Throws:
UnsupportedOperationException - always, as likes aren't implemented yet.
TODO:
REVISIT: Need to think through the escape char, so it works right when Java uses one, and escapes correctly with an '_'.

visit

public void visit(LogicFilter filter)
           throws RuntimeException
Deprecated. 
Writes the SQL for the Logic Filter.

Specified by:
visit in interface FilterVisitor
Parameters:
filter - the logic statement to be turned into SQL.
Throws:
RuntimeException - for io exception with writer

visit

public void visit(CompareFilter filter)
           throws RuntimeException
Deprecated. 
Writes the SQL for a Compare Filter. 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???

Specified by:
visit in interface FilterVisitor
Parameters:
filter - the comparison to be turned into SQL.
Throws:
RuntimeException - for io exception with writer

visit

public void visit(NullFilter filter)
           throws RuntimeException
Deprecated. 
Writes the SQL for the Null Filter.

Specified by:
visit in interface FilterVisitor
Parameters:
filter - the null filter to be written to SQL.
Throws:
RuntimeException - for io exception with writer

visit

public void visit(FidFilter filter)
Deprecated. 
Encodes an FidFilter.

Specified by:
visit in interface FilterVisitor
Parameters:
filter -
Throws:
RuntimeException - DOCUMENT ME!
See Also:
visit(org.geotools.filter.FidFilter)

visit

public void visit(AttributeExpression expression)
           throws RuntimeException
Deprecated. 
Writes the SQL for the attribute Expression.

Specified by:
visit in interface FilterVisitor
Parameters:
expression - the attribute to turn to SQL.
Throws:
RuntimeException - for io exception with writer

visit

public void visit(Expression expression)
Deprecated. 
Writes the SQL for the attribute Expression.

Specified by:
visit in interface FilterVisitor
Parameters:
expression - the attribute to turn to SQL.

visit

public void visit(LiteralExpression expression)
           throws RuntimeException
Deprecated. 
Export the contents of a Literal Expresion

Specified by:
visit in interface FilterVisitor
Parameters:
expression - the Literal to export
Throws:
RuntimeException - for io exception with writer

visitLiteralGeometry

protected void visitLiteralGeometry(LiteralExpression expression)
                             throws IOException
Deprecated. 
Subclasses must implement this method in order to encode geometry filters according to the specific database implementation

Parameters:
expression -
Throws:
IOException - DOCUMENT ME!
RuntimeException - DOCUMENT ME!

visit

public void visit(GeometryFilter filter)
Deprecated. 
Description copied from interface: FilterVisitor
Called when accept is called on a Geometry Filter. Implementers will want to access the left and right geometries.

Specified by:
visit in interface FilterVisitor
Parameters:
filter - The filter to visit
See Also:
FilterVisitor.visit(org.geotools.filter.GeometryFilter)

visit

public void visit(MathExpression expression)
           throws RuntimeException
Deprecated. 
Writes the SQL for the Math Expression.

Specified by:
visit in interface FilterVisitor
Parameters:
expression - the Math phrase to be written.
Throws:
RuntimeException - for io problems

visit

public void visit(FunctionExpression expression)
           throws UnsupportedOperationException
Deprecated. 
Writes sql for a function expression. Not currently supported.

Specified by:
visit in interface FilterVisitor
Parameters:
expression - a function expression
Throws:
UnsupportedOperationException - every time, this isn't supported.

setSqlNameEscape

public void setSqlNameEscape(String escape)
Deprecated. 
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

setColnameEscape

public void setColnameEscape(String escape)
Deprecated. Use setSqlNameEscape instead, as it is more aptly named.

Sets the escape character for the column name.

Parameters:
escape - The character to be used to escape database names.

getColnameEscape

protected String getColnameEscape()
Deprecated. the escapeName method is preferred over this, it automatically returns the name properly escaped, since that's all getColnameEscape was being used for.

Gets the column escape name.

Returns:
the string to be used to properly escape a db's name.

escapeName

public String escapeName(String name)
Deprecated. 
Surrounds a name with the SQL escape character.

Parameters:
name -
Returns:
DOCUMENT ME!

visit

public void visit(IncludeFilter filter)
Deprecated. 
Specified by:
visit in interface FilterVisitor2

visit

public void visit(ExcludeFilter filter)
Deprecated. 
Specified by:
visit in interface FilterVisitor2


Copyright © 1996-2014 Geotools. All Rights Reserved.