org.geotools.data.jdbc
Class DefaultSQLBuilder

java.lang.Object
  extended by org.geotools.data.jdbc.DefaultSQLBuilder
All Implemented Interfaces:
SQLBuilder
Direct Known Subclasses:
PostgisSQLBuilder

Deprecated. Use GeoAPISQLBuilder instead

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  ClientTransactionAccessor accessor
          Deprecated.  
protected  SQLEncoder encoder
          Deprecated.  
protected  org.opengis.feature.simple.SimpleFeatureType ft
          Deprecated.  
 
Constructor Summary
DefaultSQLBuilder()
          Deprecated. Constructs an instance of this class with a default SQLEncoder
DefaultSQLBuilder(SQLEncoder encoder)
          Deprecated.  
DefaultSQLBuilder(SQLEncoder encoder, org.opengis.feature.simple.SimpleFeatureType featureType, ClientTransactionAccessor accessor)
          Deprecated. Constructs an instance of this class using the encoder class specified.
 
Method Summary
protected  void addOrderByPK(java.lang.StringBuffer sql, FIDMapper mapper, org.opengis.filter.sort.SortOrder sortOrder)
          Deprecated.  
 java.lang.String buildSQLQuery(java.lang.String typeName, FIDMapper mapper, org.opengis.feature.type.AttributeDescriptor[] attrTypes, org.opengis.filter.Filter filter)
          Deprecated.  
 java.lang.String buildSQLQuery(java.lang.String typeName, FIDMapper mapper, org.opengis.feature.type.AttributeDescriptor[] attrTypes, org.opengis.filter.Filter filter, org.opengis.filter.sort.SortBy[] sortBy, java.lang.Integer offset, java.lang.Integer limit)
          Deprecated. Constructs the full SQL SELECT statement for the supplied Filter.
 void encode(java.lang.StringBuffer sql, org.opengis.filter.expression.Expression expression)
          Deprecated. Lower level method allowing for the encoding of a single expession in sql
 void encode(java.lang.StringBuffer sql, org.opengis.filter.Filter filter)
          Deprecated. Lower level method allowing for the encoding of a single filter in sql
protected  SimplifyingFilterVisitor.FIDValidator getFidValidator()
          Deprecated. Returns a fid validator to filter out the invalid fids from a Filter
 org.opengis.filter.Filter getPostQueryFilter(org.opengis.filter.Filter filter)
          Deprecated. Return the postQueryFilter that must be applied to the database query result set.
 org.opengis.filter.Filter getPreQueryFilter(org.opengis.filter.Filter filter)
          Deprecated. Return the preQueryFilter that can be used to generate the WHERE clause.
 boolean isForce2D()
          Deprecated. Check the hints to see if we are forced into 2D
 void setHints(Hints hints)
          Deprecated. Hints supplied by the user.
protected  void splitFilter(org.opengis.filter.Filter filter)
          Deprecated.  
 void sqlColumns(java.lang.StringBuffer sql, FIDMapper mapper, org.opengis.feature.type.AttributeDescriptor[] attributes)
          Deprecated. Appends the names of the columns to be selected.
 void sqlFrom(java.lang.StringBuffer sql, java.lang.String typeName)
          Deprecated. Constructs the FROM clause for a featureType
 void sqlGeometryColumn(java.lang.StringBuffer sql, org.opengis.feature.type.AttributeDescriptor geomAttribute)
          Deprecated. Generates the select column specification for a geometry column.
 void sqlOrderBy(java.lang.StringBuffer sql, FIDMapper mapper, org.opengis.filter.sort.SortBy[] sortBy)
          Deprecated. Generates the order by clause.
 void sqlOrderBy(java.lang.StringBuffer sql, org.opengis.filter.sort.SortBy[] sortBy)
          Deprecated.  
 void sqlWhere(java.lang.StringBuffer sql, org.opengis.filter.Filter preFilter)
          Deprecated. 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
Deprecated. 

ft

protected org.opengis.feature.simple.SimpleFeatureType ft
Deprecated. 

accessor

protected ClientTransactionAccessor accessor
Deprecated. 
Constructor Detail

DefaultSQLBuilder

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


DefaultSQLBuilder

public DefaultSQLBuilder(SQLEncoder encoder)
Deprecated. 

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

This constructor should not be used to obtain Pre/Post filters, as these methods require a SimpleFeatureType to function properly.

Parameters:
encoder - the specific encoder to be used.

DefaultSQLBuilder

public DefaultSQLBuilder(SQLEncoder encoder,
                         org.opengis.feature.simple.SimpleFeatureType featureType,
                         ClientTransactionAccessor accessor)
Deprecated. 
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.
featureType -
accessor - client-side transaction handler; may be null.
Method Detail

setHints

public void setHints(Hints hints)
Deprecated. 
Description copied from interface: SQLBuilder
Hints supplied by the user.

The following hints are of interest when working with Features:

Specified by:
setHints in interface SQLBuilder

isForce2D

public boolean isForce2D()
Deprecated. 
Check the hints to see if we are forced into 2D


getPostQueryFilter

public org.opengis.filter.Filter getPostQueryFilter(org.opengis.filter.Filter filter)
Deprecated. 
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 org.opengis.filter.Filter getPreQueryFilter(org.opengis.filter.Filter filter)
Deprecated. 
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.

splitFilter

protected void splitFilter(org.opengis.filter.Filter filter)
Deprecated. 

getFidValidator

protected SimplifyingFilterVisitor.FIDValidator getFidValidator()
Deprecated. 
Returns a fid validator to filter out the invalid fids from a Filter

Returns:
a fid validator wrapping the encoder's FIDMapper.isValid(String)
See Also:
splitFilter(Filter)

sqlFrom

public void sqlFrom(java.lang.StringBuffer sql,
                    java.lang.String typeName)
Deprecated. 
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,
                     org.opengis.filter.Filter preFilter)
              throws SQLEncoderException
Deprecated. 
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,
                                      org.opengis.feature.type.AttributeDescriptor[] attrTypes,
                                      org.opengis.filter.Filter filter)
                               throws SQLEncoderException
Deprecated. 

Specified by:
buildSQLQuery in interface SQLBuilder
Throws:
SQLEncoderException

buildSQLQuery

public java.lang.String buildSQLQuery(java.lang.String typeName,
                                      FIDMapper mapper,
                                      org.opengis.feature.type.AttributeDescriptor[] attrTypes,
                                      org.opengis.filter.Filter filter,
                                      org.opengis.filter.sort.SortBy[] sortBy,
                                      java.lang.Integer offset,
                                      java.lang.Integer limit)
                               throws SQLEncoderException
Deprecated. 
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 Filte.

Subclasses that support startIndex should override as appropriate.

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,
                       org.opengis.feature.type.AttributeDescriptor[] attributes)
Deprecated. 
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

sqlGeometryColumn

public void sqlGeometryColumn(java.lang.StringBuffer sql,
                              org.opengis.feature.type.AttributeDescriptor geomAttribute)
Deprecated. 
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 AttributeDescriptor for a geometry attribute

sqlOrderBy

public void sqlOrderBy(java.lang.StringBuffer sql,
                       org.opengis.filter.sort.SortBy[] sortBy)
                throws SQLEncoderException
Deprecated. 

Description copied from interface: SQLBuilder
Constructs ORDER BY clause.

sql: ORDER BY <property1> [ASC|DESC], ....

FIXME: This should change to a FilterToSQLException after SQLEncoder is dropped

Specified by:
sqlOrderBy in interface SQLBuilder
Throws:
SQLEncoderException

sqlOrderBy

public void sqlOrderBy(java.lang.StringBuffer sql,
                       FIDMapper mapper,
                       org.opengis.filter.sort.SortBy[] sortBy)
                throws SQLEncoderException
Deprecated. 
Generates the order by clause.

This uses the standard ASC,DESC sql keywords to denote ascending,descending sort respectivley.

Specified by:
sqlOrderBy in interface SQLBuilder
Parameters:
sql - buffer where the complete query is being built
mapper - where to inferr the primary key fields from in case the sortBy list contains SortBy.NATURAL_ORDER or SortBy.REVERSE_ORDER
sortBy - the order by criteria, possibly null FIXME: This should change to a FilterToSQLException after SQLEncoder is dropped
Throws:
SQLEncoderException

encode

public void encode(java.lang.StringBuffer sql,
                   org.opengis.filter.expression.Expression expression)
            throws SQLEncoderException
Deprecated. 
Description copied from interface: SQLBuilder
Lower level method allowing for the encoding of a single expession in sql

Specified by:
encode in interface SQLBuilder
Throws:
SQLEncoderException

encode

public void encode(java.lang.StringBuffer sql,
                   org.opengis.filter.Filter filter)
            throws SQLEncoderException
Deprecated. 
Description copied from interface: SQLBuilder
Lower level method allowing for the encoding of a single filter in sql

Specified by:
encode in interface SQLBuilder
Throws:
SQLEncoderException

addOrderByPK

protected void addOrderByPK(java.lang.StringBuffer sql,
                            FIDMapper mapper,
                            org.opengis.filter.sort.SortOrder sortOrder)
                     throws SQLEncoderException
Deprecated. 
Parameters:
sql - the buffer where the select statement is being built, already contains the "ORDER BY " clause, only needs to be appended with the PK fields.
mapper - the fid mapper where to get the PK fields from, may be null, in which case implementations should either throw an exception or not, depending on whether they actually need it.
sortOrder - the order in which to encode the PK fields (eg, "pkAtt1 DESC, pkAtt2 DESC")
Throws:
SQLEncoderException - by default, subclasses shall override if pk ordering is supported


Copyright © 1996-2010 Geotools. All Rights Reserved.