Package org.geotools.appschema.jdbc
Class JoiningJDBCFeatureSource
Object
ContentFeatureSource
JDBCFeatureSource
JoiningJDBCFeatureSource
- All Implemented Interfaces:
FeatureSource<SimpleFeatureType,,SimpleFeature> SimpleFeatureSource
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 ClassesModifier and TypeClassDescriptionstatic classField Encoder for converting Filters/Expressions to SQL, will encode table name with field. -
Field Summary
FieldsFields inherited from class JDBCFeatureSource
FILTER_THREE_WAY_LOGICFields inherited from class ContentFeatureSource
entry, hints, lock, query, queryCapabilities, schema, transaction -
Constructor Summary
ConstructorsConstructorDescriptionJoiningJDBCFeatureSource(JDBCFeatureSource featureSource) JoiningJDBCFeatureSource(JDBCFeatureStore featureStore) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 FilterToSQLCraete 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) Gets a feature reader for a JDBC multivalued mapping.protected FeatureReader<SimpleFeatureType,SimpleFeature> protected FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) Subclass method for returning a native reader from the datastore.protected booleanprotected booleanprotected QueryConvenience 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.selectSQL(SimpleFeatureType featureType, JoiningQuery query, AtomicReference<PreparedFilterToSQL> toSQLref) Generates a 'SELECT p1, p2, ...selectSQL(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 voidCreate 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, splitFilterMethods 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 Details
-
FOREIGN_ID
- See Also:
-
PRIMARY_KEY
- See Also:
-
-
Constructor Details
-
JoiningJDBCFeatureSource
- Throws:
IOException
-
JoiningJDBCFeatureSource
- Throws:
IOException
-
-
Method Details
-
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
Craete the filter to sql converter -
createFilterToSQL
protected FilterToSQL createFilterToSQL(SimpleFeatureType ft, boolean usePreparedStatementParameters) Craete the filter to sql converter -
createAlias
-
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
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.</li> <li>{@link #canLimit(Query)} - handles {@link Query#getMaxFeatures()} and {@link Query#getStartIndex()} internally.</li> <li>{@link #canSort(Query)} - handles {@link Query#getSortBy()} natively.</li> <li>{@link #canRetype(Query)} - handles {@link Query#getProperties()} natively. Example would be only parsing the properties the user asks for from an XML file</li> <li>{@link #canLock()} - handles read-locks natively</li> <li>{@link #canTransact()} - handles transactions natively</li> </ul> </p>
- Overrides:
getReaderInternalin classJDBCFeatureSource- Throws:
IOException
-
resolvePropertyNames
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
Description copied from class:ContentFeatureSourceConvenience method for joining a query with the definining query of the feature source.- Overrides:
joinQueryin classContentFeatureSource
-
aliasFilter
-
isPostgisDialect
protected boolean isPostgisDialect() -
isOrUnionReplacementEnabled
protected boolean isOrUnionReplacementEnabled() -
getCountInternal
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
-