org.geotools.data.postgis
Class PostgisSQLBuilder

Object
  extended by DefaultSQLBuilder
      extended by PostgisSQLBuilder
All Implemented Interfaces:
SQLBuilder

public class PostgisSQLBuilder
extends DefaultSQLBuilder

Builds sql for postgis.

Author:
Chris Holmes
Module:
modules/plugin/postgis (gt-postgis.jar)

Field Summary
protected  boolean byteaEnabled
          If true, ByteA function is used to transfer WKB data
protected  JDBCDataStoreConfig config
          the datastore
protected  boolean schemaEnabled
          If true, tables are qualified with a schema
protected  boolean WKBEnabled
          If true, WKB format is used instead of WKT
 
Fields inherited from class DefaultSQLBuilder
accessor, encoder, ft
 
Constructor Summary
PostgisSQLBuilder(int srid, JDBCDataStoreConfig config)
           
PostgisSQLBuilder(SQLEncoder encoder, JDBCDataStoreConfig config)
          Constructor with encoder.
PostgisSQLBuilder(SQLEncoder encoder, JDBCDataStoreConfig config, SimpleFeatureType ft)
           
 
Method Summary
protected  void addOrderByPK(StringBuffer sql, FIDMapper mapper, SortOrder sortOrder)
          Overrides to support NATURAL_ORDER and REVERSE_ORDER
 String buildSQLQuery(String typeName, FIDMapper mapper, AttributeDescriptor[] attrTypes, Filter filter, SortBy[] sortBy, Integer offset, Integer limit)
          Overrides to support offset and maxFeatures
 String encodeColumnName(String columnName)
           
 String encodeTableName(String tableName)
           
 boolean isByteaEnabled()
          Enables the use of the bytea function to transfer faster WKB geometries
 boolean isSchemaEnabled()
           
 boolean isWKBEnabled()
          Returns true if the WKB format is used to transfer geometries, false otherwise
 void setByteaEnabled(boolean byteaEnable)
          Enables/disables the use of the bytea function
 void setSchemaEnabled(boolean schemaEnabled)
          Enables/disables schema name qualification.
 void setWKBEnabled(boolean enabled)
          If turned on, WKB will be used to transfer geometry data instead of WKT
 void sqlColumns(StringBuffer sql, FIDMapper mapper, AttributeDescriptor[] attributes)
          Produces the select information required.
 void sqlFrom(StringBuffer sql, String typeName)
          Constructs FROM clause for featureType sql: FROM typeName
 void sqlWhere(StringBuffer sql, Filter preFilter)
          Constructs WHERE clause, if needed, for FILTER.
 
Methods inherited from class DefaultSQLBuilder
buildSQLQuery, encode, encode, getFidValidator, getPostQueryFilter, getPreQueryFilter, isForce2D, setHints, splitFilter, sqlGeometryColumn, sqlOrderBy, sqlOrderBy, sqlWhere
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WKBEnabled

protected boolean WKBEnabled
If true, WKB format is used instead of WKT


byteaEnabled

protected boolean byteaEnabled
If true, ByteA function is used to transfer WKB data


schemaEnabled

protected boolean schemaEnabled
If true, tables are qualified with a schema


config

protected JDBCDataStoreConfig config
the datastore

Constructor Detail

PostgisSQLBuilder

public PostgisSQLBuilder(int srid,
                         JDBCDataStoreConfig config)

PostgisSQLBuilder

public PostgisSQLBuilder(SQLEncoder encoder,
                         JDBCDataStoreConfig config)
Constructor with encoder. Use PostgisSQLBuilder(encoder, config, ft) if possible.

Parameters:
encoder -

PostgisSQLBuilder

public PostgisSQLBuilder(SQLEncoder encoder,
                         JDBCDataStoreConfig config,
                         SimpleFeatureType ft)
Method Detail

buildSQLQuery

public String buildSQLQuery(String typeName,
                            FIDMapper mapper,
                            AttributeDescriptor[] attrTypes,
                            Filter filter,
                            SortBy[] sortBy,
                            Integer offset,
                            Integer limit)
                     throws SQLEncoderException
Overrides to support offset and maxFeatures

Specified by:
buildSQLQuery in interface SQLBuilder
Overrides:
buildSQLQuery in class DefaultSQLBuilder
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
See Also:
DefaultSQLBuilder.buildSQLQuery(String, FIDMapper, AttributeDescriptor[], org.opengis.filter.Filter, SortBy[], Integer, Integer)

addOrderByPK

protected void addOrderByPK(StringBuffer sql,
                            FIDMapper mapper,
                            SortOrder sortOrder)
                     throws SQLEncoderException
Overrides to support NATURAL_ORDER and REVERSE_ORDER

Overrides:
addOrderByPK in class DefaultSQLBuilder
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

sqlColumns

public void sqlColumns(StringBuffer sql,
                       FIDMapper mapper,
                       AttributeDescriptor[] attributes)
Produces the select information required.

The featureType, if known, is always requested.

sql: featureID (,attributeColumn)

We may need to provide AttributeReaders with a hook so they can request a wrapper function.

Specified by:
sqlColumns in interface SQLBuilder
Overrides:
sqlColumns in class DefaultSQLBuilder
Parameters:
sql -
mapper -
attributes -

sqlFrom

public void sqlFrom(StringBuffer sql,
                    String typeName)
Constructs FROM clause for featureType

sql: FROM typeName

Specified by:
sqlFrom in interface SQLBuilder
Overrides:
sqlFrom in class DefaultSQLBuilder
Parameters:
sql -
typeName -

sqlWhere

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

sql: WHERE filter encoding

Parameters:
sql - DOCUMENT ME!
preFilter - DOCUMENT ME!
Throws:
SQLEncoderException - DOCUMENT ME!

isWKBEnabled

public boolean isWKBEnabled()
Returns true if the WKB format is used to transfer geometries, false otherwise


setWKBEnabled

public void setWKBEnabled(boolean enabled)
If turned on, WKB will be used to transfer geometry data instead of WKT

Parameters:
enabled -

isByteaEnabled

public boolean isByteaEnabled()
Enables the use of the bytea function to transfer faster WKB geometries


setByteaEnabled

public void setByteaEnabled(boolean byteaEnable)
Enables/disables the use of the bytea function

Parameters:
byteaEnable -

setSchemaEnabled

public void setSchemaEnabled(boolean schemaEnabled)
Enables/disables schema name qualification.


isSchemaEnabled

public boolean isSchemaEnabled()
Returns:
true if table names are prefixed with the containing schema.

encodeTableName

public String encodeTableName(String tableName)

encodeColumnName

public String encodeColumnName(String columnName)


Copyright © 1996-2009 Geotools. All Rights Reserved.