|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.filter.SQLEncoder
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.
Field Summary | |
protected FIDMapper |
mapper
the fid mapper used to encode the fid filters |
protected java.io.Writer |
out
where to write the constructed string from visiting the filters. |
Constructor Summary | |
SQLEncoder()
Empty constructor |
|
SQLEncoder(java.io.Writer out,
Filter filter)
Convenience constructor to perform the whole encoding process at once. |
Method Summary | |
protected FilterCapabilities |
createFilterCapabilities()
Sets the capabilities of this filter. |
java.lang.String |
encode(Filter filter)
Performs the encoding, returns a string of the encoded SQL. |
void |
encode(java.io.Writer out,
Filter filter)
Performs the encoding, sends the encoded sql to the writer passed in. |
java.lang.String |
escapeName(java.lang.String name)
Surrounds a name with the SQL escape character. |
FilterCapabilities |
getCapabilities()
Describes the capabilities of this encoder. |
protected java.lang.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. |
void |
setColnameEscape(java.lang.String escape)
Deprecated. Use setSqlNameEscape instead, as it is more aptly named. |
void |
setFIDMapper(FIDMapper mapper)
Sets the FIDMapper that will be used in subsequente visit calls. |
void |
setSqlNameEscape(java.lang.String escape)
Sets the SQL name escape string. |
void |
visit(AttributeExpression expression)
Writes the SQL for the attribute Expression. |
void |
visit(BetweenFilter filter)
Writes the SQL for the Between Filter. |
void |
visit(CompareFilter filter)
Writes the SQL for a Compare Filter. |
void |
visit(Expression expression)
Writes the SQL for the attribute Expression. |
void |
visit(FidFilter filter)
Encodes an FidFilter. |
void |
visit(Filter filter)
This should never be called. |
void |
visit(FunctionExpression expression)
Writes sql for a function expression. |
void |
visit(GeometryFilter filter)
Called when accept is called on a Geometry Filter. |
void |
visit(LikeFilter filter)
Writes the SQL for the Like Filter. |
void |
visit(LiteralExpression expression)
Export the contents of a Literal Expresion |
void |
visit(LogicFilter filter)
Writes the SQL for the Logic Filter. |
void |
visit(MathExpression expression)
Writes the SQL for the Math Expression. |
void |
visit(NullFilter filter)
Writes the SQL for the Null Filter. |
protected void |
visitLiteralGeometry(LiteralExpression expression)
Subclasses must implement this method in order to encode geometry filters according to the specific database implementation |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.io.Writer out
protected FIDMapper mapper
Constructor Detail |
public SQLEncoder()
public SQLEncoder(java.io.Writer out, Filter filter) throws SQLEncoderException
out
- the writer to encode the SQL to.filter
- the Filter to be encoded.
SQLEncoderException
- If there were problems encodingMethod Detail |
public void setFIDMapper(FIDMapper mapper)
mapper
- protected FilterCapabilities createFilterCapabilities()
public void encode(java.io.Writer out, Filter filter) throws SQLEncoderException
out
- the writer to encode the SQL to.filter
- the Filter to be encoded.
SQLEncoderException
- If filter type not supported, or if there
were io problems.public java.lang.String encode(Filter filter) throws SQLEncoderException
filter
- the Filter to be encoded.
SQLEncoderException
- If filter type not supported, or if there
were io problems.public FilterCapabilities getCapabilities()
Performs lazy creation of capabilities.
public void visit(Filter filter)
visit
in interface FilterVisitor
filter
- The filter to visit
java.lang.RuntimeException
- for IO Encoding problems.public void visit(BetweenFilter filter) throws java.lang.RuntimeException
visit
in interface FilterVisitor
filter
- the Filter to be visited.
java.lang.RuntimeException
- for io exception with writerpublic void visit(LikeFilter filter) throws java.lang.UnsupportedOperationException
visit
in interface FilterVisitor
filter
- the Like Filter to be visited.
java.lang.UnsupportedOperationException
- always, as likes aren't
implemented yet.public void visit(LogicFilter filter) throws java.lang.RuntimeException
visit
in interface FilterVisitor
filter
- the logic statement to be turned into SQL.
java.lang.RuntimeException
- for io exception with writerpublic void visit(CompareFilter filter) throws java.lang.RuntimeException
visit
in interface FilterVisitor
filter
- the comparison to be turned into SQL.
java.lang.RuntimeException
- for io exception with writerpublic void visit(NullFilter filter) throws java.lang.RuntimeException
visit
in interface FilterVisitor
filter
- the null filter to be written to SQL.
java.lang.RuntimeException
- for io exception with writerpublic void visit(FidFilter filter)
visit
in interface FilterVisitor
filter
-
java.lang.RuntimeException
- DOCUMENT ME!visit(org.geotools.filter.FidFilter)
public void visit(AttributeExpression expression) throws java.lang.RuntimeException
visit
in interface FilterVisitor
expression
- the attribute to turn to SQL.
java.lang.RuntimeException
- for io exception with writerpublic void visit(Expression expression)
visit
in interface FilterVisitor
expression
- the attribute to turn to SQL.public void visit(LiteralExpression expression) throws java.lang.RuntimeException
visit
in interface FilterVisitor
expression
- the Literal to export
java.lang.RuntimeException
- for io exception with writerprotected void visitLiteralGeometry(LiteralExpression expression) throws java.io.IOException
expression
-
java.io.IOException
- DOCUMENT ME!
java.lang.RuntimeException
- DOCUMENT ME!public void visit(GeometryFilter filter)
FilterVisitor
visit
in interface FilterVisitor
filter
- The filter to visitFilterVisitor.visit(org.geotools.filter.GeometryFilter)
public void visit(MathExpression expression) throws java.lang.RuntimeException
visit
in interface FilterVisitor
expression
- the Math phrase to be written.
java.lang.RuntimeException
- for io problemspublic void visit(FunctionExpression expression) throws java.lang.UnsupportedOperationException
visit
in interface FilterVisitor
expression
- a function expression
java.lang.UnsupportedOperationException
- every time, this isn't supported.public void setSqlNameEscape(java.lang.String escape)
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"
escape
- the character to be used to escape database namespublic void setColnameEscape(java.lang.String escape)
escape
- The character to be used to escape database names.protected java.lang.String getColnameEscape()
public java.lang.String escapeName(java.lang.String name)
name
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |