Package org.geotools.appschema.jdbc
Class JoiningJDBCFeatureSource
- Object
-
- ContentFeatureSource
-
- JDBCFeatureSource
-
- 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
Nested Classes Modifier and Type Class Description static classJoiningJDBCFeatureSource.JoiningFieldEncoderField Encoder for converting Filters/Expressions to SQL, will encode table name with field.
-
Field Summary
Fields Modifier and Type Field Description static StringFOREIGN_IDstatic StringPRIMARY_KEY-
Fields inherited from class JDBCFeatureSource
FILTER_THREE_WAY_LOGIC
-
Fields inherited from class ContentFeatureSource
entry, hints, lock, query, queryCapabilities, schema, transaction
-
-
Constructor Summary
Constructors Constructor Description JoiningJDBCFeatureSource(JDBCFeatureSource featureSource)JoiningJDBCFeatureSource(JDBCFeatureStore featureStore)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddMultiValuedSort(String tableName, Set<String> orderByFields, JoiningQuery.QueryJoin join, StringBuffer sql)protected FilteraliasFilter(Filter filter, SimpleFeatureType featureType, String alias)protected static StringcreateAlias(String typeName, Set<String> tableNames)protected FilterToSQLcreateFilterToSQL(SimpleFeatureType ft)Craete the filter to sql converterprotected FilterToSQLcreateFilterToSQL(SimpleFeatureType ft, boolean usePreparedStatementParameters)Craete the filter to sql convertervoidencodeColumnName(String colName, String typeName, StringBuffer sql, Hints hints)Encode column name with table name included.voidencodeColumnName2(String colName, String typeName, StringBuffer sql, Hints hints)Encode column name with table name included, but do not include schema name (for aliases)protected voidencodeGeometryColumn(GeometryDescriptor gatt, String typeName, StringBuffer sql, Hints hints)Encoding a geometry column with respect to hints Supported Hints are provided bySQLDialect.addSupportedHints(Set)protected intgetCountInternal(Query query)Calculates the number of features of a specified query.protected SimpleFeatureTypegetFeatureType(SimpleFeatureType origType, JoiningQuery query)FeatureReader<SimpleFeatureType,SimpleFeature>getJoiningReaderInternal(JdbcMultipleValue mv, JoiningQuery query)Gets a feature reader for a JDBC multivalued mapping.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 booleanisOrUnionReplacementEnabled()protected booleanisPostgisDialect()protected QueryjoinQuery(Query query)Convenience method for joining a query with the definining query of the feature source.protected QueryresolvePropertyNames(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.StringselectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref)Generates a 'SELECT p1, p2, ...StringselectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref, boolean isCount)Generates a 'SELECT p1, p2, ...protected PreparedStatementselectSQLPS(SimpleFeatureType featureType, JoiningQuery query, Connection cx)Generates a 'SELECT p1, p2, ...protected voidsort(String typeName, String alias, SortBy[] sort, Set<String> orderByFields, StringBuffer sql)Create order by field for specific table nameprotected voidsort(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 tableprotected Filter[]splitFilter(Filter original)Helper method for splitting a filter.-
Methods inherited from class JDBCFeatureSource
addHints, buildFeatureType, buildQueryCapabilities, canFilter, canLimit, canOffset, canRetype, canSort, canTransact, getBoundsInternal, getDataStore, getPrimaryKey, getState, handleVisitor, isExposePrimaryKeyColumns, setExposePrimaryKeyColumns, splitFilter
-
Methods inherited from class ContentFeatureSource
accepts, addFeatureListener, canEvent, canFilter, canLimit, canLock, canOffset, canReproject, canRetype, canSort, 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
-
-
-
-
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 bySQLDialect.addSupportedHints(Set)- Parameters:
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- Throws:
IOExceptionSQLException
-
addMultiValuedSort
protected void addMultiValuedSort(String tableName, Set<String> orderByFields, JoiningQuery.QueryJoin join, StringBuffer sql) 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
-
encodeColumnName
public void encodeColumnName(String colName, String typeName, StringBuffer sql, Hints hints) throws SQLException
Encode column name with table name included.- 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)- Throws:
SQLException
-
createFilterToSQL
protected FilterToSQL createFilterToSQL(SimpleFeatureType ft)
Craete the filter to sql converter
-
createFilterToSQL
protected FilterToSQL createFilterToSQL(SimpleFeatureType ft, boolean usePreparedStatementParameters)
Craete the filter to sql converter
-
selectSQL
public String selectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref) 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)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 typetoSQLref- atomic reference to a FilterToSQL able to works with PreparedStament parameters- Throws:
SQLExceptionIOExceptionFilterToSQLException
-
selectSQL
public String selectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref, boolean isCount) 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)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 typetoSQLref- atomic reference to a FilterToSQL able to works with PreparedStament parametersisCount- avoid the encoding of unnecessary SQL pieces when a count query is needed- Throws:
IOExceptionSQLExceptionFilterToSQLException
-
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)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 typecx- The database connection to be used to create the prepared statement- Throws:
SQLExceptionIOExceptionFilterToSQLException
-
splitFilter
protected Filter[] splitFilter(Filter original)
Description copied from class:JDBCFeatureSourceHelper method for splitting a filter.- Overrides:
splitFilterin classJDBCFeatureSource
-
getFeatureType
protected SimpleFeatureType getFeatureType(SimpleFeatureType origType, JoiningQuery query) throws IOException
- Throws:
IOException
-
getJoiningReaderInternal
protected FeatureReader<SimpleFeatureType,SimpleFeature> getJoiningReaderInternal(JoiningQuery query) throws IOException
- Throws:
IOException
-
getJoiningReaderInternal
public FeatureReader<SimpleFeatureType,SimpleFeature> getJoiningReaderInternal(JdbcMultipleValue mv, JoiningQuery query) throws IOException
Gets a feature reader for a JDBC multivalued mapping.- Throws:
IOException
-
getReaderInternal
protected FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) throws IOException
Description copied from class:ContentFeatureSourceSubclass 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:
- reprojection
- filtering
- max feature limiting
- sorting
- locking
- transactions
true:ContentFeatureSource.canReproject()- handlesQuery.getCoordinateSystemReproject()internally. Example would be PostGIS using Proj to handle reproejction internallyContentFeatureSource.canFilter(Query)- handlesinternally.- {@link #canLimit(Query)} - handles {@link Query#getMaxFeatures()} and {@link Query#getStartIndex()} internally.
- {@link #canSort(Query)} - handles {@link Query#getSortBy()} natively.
- {@link #canRetype(Query)} - handles {@link Query#getProperties()} natively. Example would be only parsing the properties the user asks for from an XML file
- {@link #canLock()} - handles read-locks natively
- {@link #canTransact()} - handles transactions natively
- Overrides:
getReaderInternalin classJDBCFeatureSource- Throws:
IOException
-
resolvePropertyNames
protected Query resolvePropertyNames(Query query)
Description copied from class:ContentFeatureSourceThis 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:
resolvePropertyNamesin classContentFeatureSource
-
joinQuery
protected Query joinQuery(Query query)
Description copied from class:ContentFeatureSourceConvenience method for joining a query with the definining query of the feature source.- Overrides:
joinQueryin classContentFeatureSource
-
aliasFilter
protected Filter aliasFilter(Filter filter, SimpleFeatureType featureType, String alias)
-
isPostgisDialect
protected boolean isPostgisDialect()
-
isOrUnionReplacementEnabled
protected boolean isOrUnionReplacementEnabled()
-
getCountInternal
protected int getCountInternal(Query query) throws IOException
Description copied from class:ContentFeatureSourceCalculates the number of features of a specified query. Subclasses must implement this method. If the computation is not fast, it's possible to return -1.- Overrides:
getCountInternalin classJDBCFeatureSource- Throws:
IOException
-
-