public class FilterToSQL extends Object implements FilterVisitor, ExpressionVisitor
createFilterCapabilities()
method.
This version was ported from the original to support org.opengis.filter type Filters.
Modifier and Type | Class and Description |
---|---|
static interface |
FilterToSQL.FieldEncoder
Interface for customizing the encoding of Fields, irrespective of which subclass of
FilterToSQL we are using.
|
Modifier and Type | Field and Description |
---|---|
protected FilterCapabilities |
capabilities
The filter types that this class can encode
|
protected Integer |
currentDimension
The dimension corresponding to the current binary spatial filter being encoded
|
protected GeometryDescriptor |
currentGeometry
the geometry descriptor corresponding to the current binary spatial filter being encoded
|
protected Integer |
currentSRID
the srid corresponding to the current binary spatial filter being encoded
|
protected String |
databaseSchema
The schema that contains the table the filter being encoded against.
|
protected boolean |
encodingFunction
flag which indicates that the encoder is currently encoding a function
|
protected SimpleFeatureType |
featureType
the schmema the encoder will be used to be encode sql for
|
protected FilterToSQL.FieldEncoder |
fieldEncoder
Current field encoder
|
protected static FilterFactory |
filterFactory
filter factory
|
protected boolean |
inEncodingEnabled
Whether the encoder should try to encode "in" function into a SQL IN operator
|
protected boolean |
inline
inline flag, controlling whether "WHERE" will prefix the SQL encoded filter
|
protected static String |
IO_ERROR
error message for exceptions
|
protected static Logger |
LOGGER
Standard java logger
|
protected FIDMapper |
mapper
Deprecated.
use
primaryKey |
protected Writer |
out
where to write the constructed string from visiting the filters.
|
protected PrimaryKey |
primaryKey
The primary key corresponding to the table the filter is being encoded against.
|
Constructor and Description |
---|
FilterToSQL()
Default constructor
|
FilterToSQL(Writer out) |
Modifier and Type | Method and Description |
---|---|
protected String |
cast(String encodedProperty,
Class target)
Gives the opportunity to subclasses to force the property to the desired type.
|
protected FilterCapabilities |
createFilterCapabilities()
Sets the capabilities of this filter.
|
void |
encode(Expression expression)
Performs the encoding, sends the encoded sql to the writer passed in.
|
void |
encode(Filter filter)
Performs the encoding, sends the encoded sql to the writer passed in.
|
String |
encodeToString(Expression expression)
purely a convenience method.
|
String |
encodeToString(Filter filter)
purely a convenience method.
|
String |
escapeName(String name)
Surrounds a name with the SQL escape character.
|
Object |
evaluateLiteral(Literal expression,
Class target) |
FilterCapabilities |
getCapabilities()
Describes the capabilities of this encoder.
|
String |
getDatabaseSchema() |
protected double |
getDistanceInMeters(DistanceBufferOperator operator)
Converts the distance of the operator in meters, or returns the current value if there is no
units distance
|
protected double |
getDistanceInNativeUnits(DistanceBufferOperator operator)
Rough evaluation of distance in the units of the current SRID, assuming that the SRID maps to
a known EPSG code.
|
Class |
getExpressionType(Expression expression)
Returns the expression type, if can be found, or null otherwise.
|
SimpleFeatureType |
getFeatureType()
Returns the feature type set in this encoder, if any
|
FIDMapper |
getFIDMapper()
Deprecated.
use
getPrimaryKey() |
protected String |
getFunctionName(Function function)
Maps the function to the native database function name
|
protected Class |
getFunctionReturnType(Function f) |
protected Expression |
getParameter(Function function,
int idx,
boolean mandatory)
Returns the n-th parameter of a function, throwing an exception if the parameter is not there
and has been marked as mandatory
|
PrimaryKey |
getPrimaryKey() |
protected Coordinate |
getReferenceGeometryCentroid(DistanceBufferOperator operator)
Returns the center of the reference geometry of the distance buffer operator, in case
|
protected boolean |
isBinaryExpression(Expression e) |
boolean |
isInEncodingEnabled()
Whether "in" like functions are encoded in SQL or not
|
void |
setCapabilities(FilterCapabilities capabilities)
Sets the capabilities for the encoder.
|
void |
setDatabaseSchema(String databaseSchema) |
void |
setFeatureType(SimpleFeatureType featureType)
Sets the featuretype the encoder is encoding sql for.
|
void |
setFIDMapper(FIDMapper mapper)
Deprecated.
|
void |
setFieldEncoder(FilterToSQL.FieldEncoder fieldEncoder)
Set custom field encoder
|
void |
setInEncodingEnabled(boolean inEncodingEnabled)
Makes the encoder translate in like functions into SQL (see also
InFunction.isInFunction(Expression) |
void |
setInline(boolean inline) |
void |
setPrimaryKey(PrimaryKey primaryKey) |
void |
setSqlNameEscape(String escape)
Sets the SQL name escape string.
|
void |
setWriter(Writer out)
Sets the writer the encoder will write to.
|
Object |
visit(Add expression,
Object extraData) |
Object |
visit(After after,
Object extraData) |
Object |
visit(And filter,
Object extraData)
Write the SQL for an And filter
|
Object |
visit(AnyInteracts anyInteracts,
Object extraData) |
Object |
visit(BBOX filter,
Object extraData) |
Object |
visit(Before before,
Object extraData) |
Object |
visit(Begins begins,
Object extraData) |
Object |
visit(BegunBy begunBy,
Object extraData) |
Object |
visit(Beyond filter,
Object extraData) |
protected Object |
visit(BinaryExpression expression,
String operator,
Object extraData)
Writes the SQL for the Math Expression.
|
protected Object |
visit(BinaryLogicOperator filter,
Object extraData)
Common implementation for BinaryLogicOperator filters.
|
Object |
visit(Contains filter,
Object extraData) |
Object |
visit(Crosses filter,
Object extraData) |
Object |
visit(Disjoint filter,
Object extraData) |
Object |
visit(Divide expression,
Object extraData) |
Object |
visit(During during,
Object extraData) |
Object |
visit(DWithin filter,
Object extraData) |
Object |
visit(EndedBy endedBy,
Object extraData) |
Object |
visit(Ends ends,
Object extraData) |
Object |
visit(Equals filter,
Object extraData) |
Object |
visit(ExcludeFilter filter,
Object extraData)
Visit
Filter.EXCLUDE (often used during data structure transformations). |
Object |
visit(Function function,
Object extraData)
Writes sql for a function expression.
|
Object |
visit(Id filter,
Object extraData)
Encodes an Id filter
|
Object |
visit(IncludeFilter filter,
Object extraData)
Visit
Filter.INCLUDE (often used during data structure transformations). |
Object |
visit(Intersects filter,
Object extraData) |
Object |
visit(Literal expression,
Object context)
Export the contents of a Literal Expresion
|
Object |
visit(Meets meets,
Object extraData) |
Object |
visit(MetBy metBy,
Object extraData) |
Object |
visit(Multiply expression,
Object extraData) |
Object |
visit(NativeFilter filter,
Object data) |
Object |
visit(NilExpression expression,
Object extraData)
Used to visit a Expression.NIL, also called for
null where an expression is
expected. |
Object |
visit(Not filter,
Object extraData)
Write the SQL for a Not filter
|
Object |
visit(Or filter,
Object extraData)
Write the SQL for an Or filter
|
Object |
visit(OverlappedBy overlappedBy,
Object extraData) |
Object |
visit(Overlaps filter,
Object extraData) |
Object |
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 filter
|
Object |
visit(PropertyIsGreaterThan filter,
Object extraData)
Write the SQL for this kind of filter
|
Object |
visit(PropertyIsGreaterThanOrEqualTo filter,
Object extraData)
Write the SQL for this kind of filter
|
Object |
visit(PropertyIsLessThan filter,
Object extraData)
Write the SQL for this kind of filter
|
Object |
visit(PropertyIsLessThanOrEqualTo filter,
Object extraData)
Write the SQL for this kind of filter
|
Object |
visit(PropertyIsLike filter,
Object extraData)
Writes the SQL for the Like Filter.
|
Object |
visit(PropertyIsNil filter,
Object extraData) |
Object |
visit(PropertyIsNotEqualTo filter,
Object extraData)
Write the SQL for this kind of filter
|
Object |
visit(PropertyIsNull filter,
Object extraData)
Writes the SQL for the Null Filter.
|
Object |
visit(PropertyName expression,
Object extraData)
Writes the SQL for the attribute Expression.
|
Object |
visit(Subtract expression,
Object extraData) |
Object |
visit(TContains contains,
Object extraData) |
Object |
visit(TEquals equals,
Object extraData) |
Object |
visit(Touches filter,
Object extraData) |
Object |
visit(TOverlaps contains,
Object extraData) |
Object |
visit(Within filter,
Object extraData) |
protected void |
visitBinaryComparisonOperator(BinaryComparisonOperator filter,
Object extraData)
Common implementation for BinaryComparisonOperator filters.
|
protected Object |
visitBinarySpatialOperator(BinarySpatialOperator filter,
Expression e1,
Expression e2,
Object extraData)
Handles the more general case of two generic expressions.
|
protected Object |
visitBinarySpatialOperator(BinarySpatialOperator filter,
Object extraData) |
protected Object |
visitBinarySpatialOperator(BinarySpatialOperator filter,
PropertyName property,
Literal geometry,
boolean swapped,
Object extraData)
Handles the common case of a PropertyName,Literal geometry binary spatial operator.
|
protected Object |
visitBinaryTemporalOperator(BinaryTemporalOperator filter,
Expression e1,
Expression e2,
Object extraData)
Handles the general case of two expressions in a binary temporal filter.
|
protected Object |
visitBinaryTemporalOperator(BinaryTemporalOperator filter,
Object extraData) |
protected Object |
visitBinaryTemporalOperator(BinaryTemporalOperator filter,
PropertyName property,
Literal temporal,
boolean swapped,
Object extraData)
Handles the common case of a PropertyName,Literal geometry binary temporal operator.
|
protected void |
visitInFunction(Function function,
boolean encodeAsExpression,
boolean negate,
Object extraData)
Encodes a "in" function (as recognized by
InFunction.isInFunction(Expression) |
protected void |
visitLiteralGeometry(Literal expression)
Subclasses must implement this method in order to encode geometry filters according to the
specific database implementation
|
protected void |
visitLiteralTimePeriod(Period expression) |
Object |
visitNullFilter(Object extraData)
Encodes a null filter value.
|
protected void |
writeBinaryExpression(Expression e,
Class context) |
protected void |
writeBinaryExpressionMember(Expression exp,
Class context)
Writes out an expression, wrapping it in parenthesis if it's a binary one
|
protected void |
writeLiteral(Object literal)
Writes out a non null, non geometry literal.
|
protected static final String IO_ERROR
protected static FilterFactory filterFactory
protected FilterCapabilities capabilities
protected static Logger LOGGER
protected Writer out
protected FIDMapper mapper
primaryKey
protected PrimaryKey primaryKey
protected String databaseSchema
protected SimpleFeatureType featureType
protected boolean encodingFunction
protected GeometryDescriptor currentGeometry
protected Integer currentSRID
protected Integer currentDimension
protected boolean inline
protected boolean inEncodingEnabled
protected FilterToSQL.FieldEncoder fieldEncoder
public FilterToSQL()
public FilterToSQL(Writer out)
public void setWriter(Writer out)
public void setInline(boolean inline)
public boolean isInEncodingEnabled()
public void setInEncodingEnabled(boolean inEncodingEnabled)
InFunction.isInFunction(Expression)
inEncodingEnabled
- the new flag controlling in encodingpublic void encode(Filter filter) throws FilterToSQLException
filter
- the Filter to be encoded.FilterToSQLException
- If filter type not supported, or if there were io problems.public String encodeToString(Filter filter) throws FilterToSQLException
Equivalent to:
StringWriter out = new StringWriter(); new FilterToSQL(out).encode(filter); out.getBuffer().toString();
filter
- FilterToSQLException
public void encode(Expression expression) throws FilterToSQLException
filter
- the Filter to be encoded.FilterToSQLException
- If filter type not supported, or if there were io problems.public String encodeToString(Expression expression) throws FilterToSQLException
Equivalent to:
StringWriter out = new StringWriter(); new FilterToSQL(out).encode(filter); out.getBuffer().toString();
filter
- FilterToSQLException
public void setFeatureType(SimpleFeatureType featureType)
This is used for context for attribute expressions when encoding to sql.
featureType
- public SimpleFeatureType getFeatureType()
public void setFIDMapper(FIDMapper mapper)
setPrimaryKey(PrimaryKey)
mapper
- public FIDMapper getFIDMapper()
getPrimaryKey()
public PrimaryKey getPrimaryKey()
public void setPrimaryKey(PrimaryKey primaryKey)
public String getDatabaseSchema()
public void setDatabaseSchema(String databaseSchema)
protected FilterCapabilities createFilterCapabilities()
public final FilterCapabilities getCapabilities()
Performs lazy creation of capabilities. If you're subclassing this class, override createFilterCapabilities to declare which filtercapabilities you support. Don't use this method.
public void setCapabilities(FilterCapabilities capabilities)
public Object visit(ExcludeFilter filter, Object extraData)
FilterVisitor
Filter.EXCLUDE
(often used during data structure transformations).visit
in interface FilterVisitor
the
- filter to be visitedFilterVisitor#visit(ExcludeFilter, Object)}
Writes the SQL for the IncludeFilter by writing "FALSE".
public Object visit(IncludeFilter filter, Object extraData)
FilterVisitor
Filter.INCLUDE
(often used during data structure transformations).visit
in interface FilterVisitor
the
- filter to be visitedFilterVisitor#visit(IncludeFilter, Object)}
Writes the SQL for the IncludeFilter by writing "TRUE".
public Object visit(PropertyIsBetween filter, Object extraData) throws RuntimeException
visit
in interface FilterVisitor
filter
- the Filter to be visited.RuntimeException
- for io exception with writerpublic Object visit(PropertyIsLike filter, Object extraData)
visit
in interface FilterVisitor
filter
- the Like Filter to be visited.public Object visit(And filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(Not filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(Or filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)protected Object visit(BinaryLogicOperator filter, Object extraData)
filter
- the logic statement to be turned into SQL.extraData
- extra filter data. Not modified directly by this method.public Object visit(PropertyIsEqualTo filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(PropertyIsGreaterThan filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(PropertyIsLessThan filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)public Object visit(PropertyIsNotEqualTo filter, Object extraData)
visit
in interface FilterVisitor
filter
- the filter to visitextraData
- extra data (unused by this method)protected void visitBinaryComparisonOperator(BinaryComparisonOperator filter, Object extraData) throws RuntimeException