org.geotools.data.jdbc
Class DefaultSQLBuilder

java.lang.Object
  extended byorg.geotools.data.jdbc.DefaultSQLBuilder
All Implemented Interfaces:
SQLBuilder
Direct Known Subclasses:
BBOXSQLBuilder, DB2SQLBuilder, GeometrylessSQLBuilder, HsqlSQLBuilder, LocationsXYSQLBuilder, MySQLSQLBuilder, PostgisSQLBuilder

public class DefaultSQLBuilder
extends java.lang.Object
implements SQLBuilder

Builds a complete SQL query to select the specified attributes for the specified feature type, using a specified filter to generate a WHERE clause.

The actual WHERE clause is generated by the SQLEncoder class or appropriate subclass for a particular database. If a specific encoder is to be used, it must be specified to the constructor for this class.

In order to implement the functionality of the application-specified Filter, this is split into a 'preQueryFilter' which can be incorporated into the SQL query itself and a 'postQueryFilter. The encoder capabilities are used to determine how much of the function can be performed by the database directly and how much has to be performed on the result set.

Author:
Sean Geoghegan, Defence Science and Technology Organisation.

Field Summary
protected  SQLEncoder encoder
           
 
Constructor Summary
DefaultSQLBuilder()
          Constructs an instance of this class with a default SQLEncoder
DefaultSQLBuilder(SQLEncoder encoder)
          Constructs an instance of this class using the encoder class specified.
 
Method Summary
 java.lang.String buildSQLQuery(java.lang.String typeName, FIDMapper mapper, AttributeType[] attrTypes, Filter filter)
          Constructs the full SQL SELECT statement for the supplied Filter.
 Filter getPostQueryFilter(Filter filter)
          Return the postQueryFilter that must be applied to the database query result set.
 Filter getPreQueryFilter(Filter filter)
          Return the preQueryFilter that can be used to generate the WHERE clause.
 void sqlColumns(java.lang.StringBuffer sql, FIDMapper mapper, AttributeType[] attributes)
          Appends the names of the columns to be selected.
 void sqlFrom(java.lang.StringBuffer sql, java.lang.String typeName)
          Constructs the FROM clause for a featureType sql: FROM typeName
 void sqlGeometryColumn(java.lang.StringBuffer sql, AttributeType geomAttribute)
          Generates the select column specification for a geometry column.
 void sqlWhere(java.lang.StringBuffer sql, Filter preFilter)
          Constructs WHERE clause, if needed, for FILTER.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encoder

protected SQLEncoder encoder
Constructor Detail

DefaultSQLBuilder

public DefaultSQLBuilder()
Constructs an instance of this class with a default SQLEncoder


DefaultSQLBuilder

public DefaultSQLBuilder(SQLEncoder encoder)
Constructs an instance of this class using the encoder class specified. This will typically be from the getSqlBuilder method of a JDBCDataStore subclass

Parameters:
encoder - the specific encoder to be used.
Method Detail

getPostQueryFilter

public Filter getPostQueryFilter(Filter filter)
Return the postQueryFilter that must be applied to the database query result set.

Specified by:
getPostQueryFilter in interface SQLBuilder
Parameters:
filter - the application filter which must be applied
Returns:
the filter representing the functionality that must be performed on the result set.

getPreQueryFilter

public Filter getPreQueryFilter(Filter filter)
Return the preQueryFilter that can be used to generate the WHERE clause.

Specified by:
getPreQueryFilter in interface SQLBuilder
Parameters:
filter - the application filter which must be applied
Returns:
the filter representing the functionality that can be performed by the database.

sqlFrom

public void sqlFrom(java.lang.StringBuffer sql,
                    java.lang.String typeName)
Constructs the FROM clause for a featureType

sql: FROM typeName

Specified by:
sqlFrom in interface SQLBuilder
Parameters:
sql - the StringBuffer that the WHERE clause should be appended to
typeName - the name of the table (feature type) to be queried

sqlWhere

public void sqlWhere(java.lang.StringBuffer sql,
                     Filter preFilter)
              throws SQLEncoderException
Constructs WHERE clause, if needed, for FILTER.

sql: WHERE filter encoding

Specified by:
sqlWhere in interface SQLBuilder
Parameters:
sql - The StringBuffer that the WHERE clause should be appended to
preFilter - The filter to be used by the encoder class to generate the WHERE clause
Throws:
SQLEncoderException - Not thrown here but may be thrown by the encoder

buildSQLQuery

public java.lang.String buildSQLQuery(java.lang.String typeName,
                                      FIDMapper mapper,
                                      AttributeType[] attrTypes,
                                      Filter filter)
                               throws SQLEncoderException
Constructs the full SQL SELECT statement for the supplied Filter.

The statement is constructed by concatenating the SELECT column list, FROM table specification and WHERE clause appropriate to the supplied Filter.

Specified by:
buildSQLQuery in interface SQLBuilder
Parameters:
typeName - The name of the table (feature type) to be queried
mapper - FIDMapper to identify the FID columns in the table
attrTypes - The specific attribute columns to be selected
filter - The Filter that will be used by the encoder to construct the WHERE clause
Returns:
The fully formed SQL SELECT statement
Throws:
SQLEncoderException - Not thrown by this method but may be thrown by the encoder class

sqlColumns

public void sqlColumns(java.lang.StringBuffer sql,
                       FIDMapper mapper,
                       AttributeType[] attributes)
Appends the names of the columns to be selected.

sqlGeometryColumn is invoked for any special handling for geometry columns.

Specified by:
sqlColumns in interface SQLBuilder
Parameters:
sql - StringBuffer to be appended to
mapper - FIDMapper to provide the name(s) of the FID columns
attributes - Array of columns to be selected
See Also:
postgisDataStore.SQLBuilder#sqlColumns(java.lang.StringBuffer, postgisDataStore.FIDMapper.FIDMapper, org.geotools.feature.AttributeType[])

sqlGeometryColumn

public void sqlGeometryColumn(java.lang.StringBuffer sql,
                              AttributeType geomAttribute)
Generates the select column specification for a geometry column.

This should typically be overridden in the subclass to return a meaningful value that the attribute i/o handler can process.

Parameters:
sql - A StringBuffer that the column specification can be appended to
geomAttribute - An AttributeType for a geometry attribute


Copyright © GeoTools. All Rights Reserved.