org.geotools.jdbc
Class JoiningJDBCFeatureSource

Object
  extended by ContentFeatureSource
      extended by JDBCFeatureSource
          extended by JoiningJDBCFeatureSource
All Implemented Interfaces:
FeatureSource<SimpleFeatureType,SimpleFeature>, SimpleFeatureSource

public class JoiningJDBCFeatureSource
extends JDBCFeatureSource

This is where the magic happens. The Joining JDBC Feature Source is a "hacking" class rather than a proper subclass. It provides functionality for executing 'joining queries'. Because only simple features can be returned by the existing geotools database logic, these joins on the db are not used for linking the actual features together, but only for putting the simple features in a certain order; an order that will allow us to do the actual feature chaining faster when we are building the complex features, because the right features will already be lined up in the right order.

Author:
Niels Charlier (Curtin University of Technology)

Nested Class Summary
protected  class JoiningJDBCFeatureSource.JoiningFieldEncoder
          Field Encoder for converting Filters/Expressions to SQL, will encode table name with field
 
Field Summary
static String FOREIGN_ID
           
static String PRIMARY_KEY
           
 
Fields inherited from class ContentFeatureSource
entry, hints, lock, query, queryCapabilities, schema, transaction
 
Constructor Summary
JoiningJDBCFeatureSource(JDBCFeatureSource featureSource)
           
JoiningJDBCFeatureSource(JDBCFeatureStore featureStore)
           
 
Method Summary
protected  void addMultiValuedSort(String tableName, Set<String> orderByFields, JoiningQuery.QueryJoin join, StringBuffer sql)
           
protected static String createAlias(String typeName, Set<String> tableNames)
           
protected  FilterToSQL createFilterToSQL(SimpleFeatureType ft)
          Craete the filter to sql converter
 void encodeColumnName(String colName, String typeName, StringBuffer sql, Hints hints)
          Encode column name with table name included.
 void encodeColumnName2(String colName, String typeName, StringBuffer sql, Hints hints)
          Encode column name with table name included, but do not include schema name (for aliases)
protected  void encodeGeometryColumn(GeometryDescriptor gatt, String typeName, StringBuffer sql, Hints hints)
          Encoding a geometry column with respect to hints Supported Hints are provided by SQLDialect.addSupportedHints(Set)
protected  SimpleFeatureType getFeatureType(SimpleFeatureType origType, JoiningQuery query)
           
protected  FeatureReader<SimpleFeatureType,SimpleFeature> getJoiningReaderInternal(JoiningQuery query)
           
protected  FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query)
          Subclass method for returning a native reader from the datastore.
protected  Query joinQuery(Query query)
          Convenience method for joining a query with the definining query of the feature source.
protected  Query resolvePropertyNames(Query query)
          This method changes the query object so that all propertyName references are resolved to simple attribute names against the schema of the feature source.
protected  String selectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref)
          Generates a 'SELECT p1, p2, ...
protected  PreparedStatement selectSQLPS(SimpleFeatureType featureType, JoiningQuery query, Connection cx)
          Generates a 'SELECT p1, p2, ...
protected  void sort(JoiningQuery query, StringBuffer sql, String[] aliases, Set<String> pkColumnNames)
          Creates ORDER BY for joining query, based on all the sortby's that are specified per joining table
protected  void sort(String typeName, String alias, SortBy[] sort, Set<String> orderByFields, StringBuffer sql)
          Create order by field for specific table name
 
Methods inherited from class JDBCFeatureSource
addHints, buildFeatureType, buildQueryCapabilities, canFilter, canLimit, canOffset, canRetype, canSort, canTransact, getBoundsInternal, getCountInternal, getDataStore, getPrimaryKey, getState, handleVisitor, isExposePrimaryKeyColumns, setExposePrimaryKeyColumns
 
Methods inherited from class ContentFeatureSource
accepts, addFeatureListener, canEvent, canLock, canReproject, doLockInternal, doUnlockInternal, getAbsoluteSchema, getBounds, getBounds, getCount, getEntry, getFeatures, getFeatures, getFeatures, getInfo, getName, getQueryCapabilities, getReader, getReader, getReader, getSchema, getSupportedHints, getTransaction, getView, getView, isView, lockFeatures, lockFeatures, lockFeatures, processLock, removeFeatureListener, resolvePropertyNames, setFeatureLock, setTransaction, unLockFeatures, unLockFeatures, unLockFeatures
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FOREIGN_ID

public static final String FOREIGN_ID
See Also:
Constant Field Values

PRIMARY_KEY

public static final String PRIMARY_KEY
See Also:
Constant Field Values
Constructor Detail

JoiningJDBCFeatureSource

public JoiningJDBCFeatureSource(JDBCFeatureSource featureSource)
                         throws IOException
Throws:
IOException

JoiningJDBCFeatureSource

public JoiningJDBCFeatureSource(JDBCFeatureStore featureStore)
                         throws IOException
Throws:
IOException
Method Detail

encodeGeometryColumn

protected void encodeGeometryColumn(GeometryDescriptor gatt,
                                    String typeName,
                                    StringBuffer sql,
                                    Hints hints)
                             throws SQLException
Encoding a geometry column with respect to hints Supported Hints are provided by SQLDialect.addSupportedHints(Set)

Parameters:
gatt -
sql -
hints - , may be null
Throws:
SQLException

sort

protected void sort(String typeName,
                    String alias,
                    SortBy[] sort,
                    Set<String> orderByFields,
                    StringBuffer sql)
             throws IOException,
                    SQLException
Create order by field for specific table name

Parameters:
typeName -
alias -
sort -
orderByFields -
Throws:
IOException
SQLException

addMultiValuedSort

protected void addMultiValuedSort(String tableName,
                                  Set<String> orderByFields,
                                  JoiningQuery.QueryJoin join,
                                  StringBuffer sql)
                           throws IOException,
                                  FilterToSQLException,
                                  SQLException
Throws:
IOException
FilterToSQLException
SQLException

sort

protected void sort(JoiningQuery query,
                    StringBuffer sql,
                    String[] aliases,
                    Set<String> pkColumnNames)
             throws IOException,
                    SQLException,
                    FilterToSQLException
Creates ORDER BY for joining query, based on all the sortby's that are specified per joining table

Parameters:
query -
sql -
Throws:
IOException
SQLException
FilterToSQLException

encodeColumnName

public void encodeColumnName(String colName,
                             String typeName,
                             StringBuffer sql,
                             Hints hints)
                      throws SQLException
Encode column name with table name included.

Parameters:
colName -
typeName -
sql -
hints -
Throws:
SQLException

encodeColumnName2

public void encodeColumnName2(String colName,
                              String typeName,
                              StringBuffer sql,
                              Hints hints)
                       throws SQLException
Encode column name with table name included, but do not include schema name (for aliases)

Parameters:
colName -
typeName -
sql -
hints -
Throws:
SQLException

createFilterToSQL

protected FilterToSQL createFilterToSQL(SimpleFeatureType ft)
Craete the filter to sql converter

Parameters:
ft -
Returns:

createAlias

protected static String createAlias(String typeName,
                                    Set<String> tableNames)

selectSQL

protected String selectSQL(SimpleFeatureType featureType,
                           JoiningQuery query,
                           AtomicReference<PreparedFilterToSQL> toSQLref)
                    throws IOException,
                           SQLException,
                           FilterToSQLException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' prepared statement.

Parameters:
featureType - the feature type that the query must return (may contain less attributes than the native one)
attributes - the properties queried, or Query.ALL_NAMES to gather all of them
query - the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature type
cx - The database connection to be used to create the prepared statement
Throws:
SQLException
IOException
FilterToSQLException

selectSQLPS

protected PreparedStatement selectSQLPS(SimpleFeatureType featureType,
                                        JoiningQuery query,
                                        Connection cx)
                                 throws SQLException,
                                        IOException,
                                        FilterToSQLException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' prepared statement.

Parameters:
featureType - the feature type that the query must return (may contain less attributes than the native one)
attributes - the properties queried, or Query.ALL_NAMES to gather all of them
query - the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature type
cx - The database connection to be used to create the prepared statement
Throws:
FilterToSQLException
SQLException
IOException

getFeatureType

protected SimpleFeatureType getFeatureType(SimpleFeatureType origType,
                                           JoiningQuery query)
                                    throws IOException
Throws:
IOException

getJoiningReaderInternal

protected FeatureReader<SimpleFeatureType,SimpleFeature> getJoiningReaderInternal(JoiningQuery query)
                                                                           throws IOException
Throws:
IOException

getReaderInternal

protected FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query)
                                                                    throws IOException
Description copied from class: ContentFeatureSource
Subclass method for returning a native reader from the datastore.

It is important to note that if the native reader intends to handle any of the following natively:

Then it *must* set the corresponding flags to true:

Overrides:
getReaderInternal in class JDBCFeatureSource
Throws:
IOException

resolvePropertyNames

protected Query resolvePropertyNames(Query query)
Description copied from class: ContentFeatureSource
This method changes the query object so that all propertyName references are resolved to simple attribute names against the schema of the feature source.

For example, this method ensures that propertyName's such as "gml:name" are rewritten as simply "name".

Overrides:
resolvePropertyNames in class ContentFeatureSource

joinQuery

protected Query joinQuery(Query query)
Description copied from class: ContentFeatureSource
Convenience method for joining a query with the definining query of the feature source.

Overrides:
joinQuery in class ContentFeatureSource


Copyright © 1996-2014 Geotools. All Rights Reserved.