public abstract class ContentFeatureSource extends Object implements SimpleFeatureSource
This feature source works off of operations provided by FeatureCollection
. Individual
SimpleFeatureCollection implementations are provided by subclasses:
#all(ContentState)
: Access to entire dataset #filtered(ContentState, Filter)
:
Access to filtered dataset
Even though a feature source is read-only, this class is transaction aware. (see setTransaction(Transaction)
. The transaction is taken into account during operations such as
#getCount()
and getBounds()
since these values may be affected by another
operation (like writing to a FeautreStore) working against the same transaction.
Subclasses must also implement the buildFeatureType()
method which builds the schema
for the feature source.
Modifier and Type | Field and Description |
---|---|
protected ContentEntry |
entry
The entry for the feature source.
|
protected Set<Hints.Key> |
hints
Hints
|
protected FeatureLock |
lock
Current feature lock
|
protected Query |
query
The query defining the feature source
|
protected QueryCapabilities |
queryCapabilities
The query capabilities returned by this feature source
|
protected SimpleFeatureType |
schema
Cached feature type (only set if this instance is a view)
|
protected Transaction |
transaction
The transaction to work from, use {link
ContentEntry.getState(Transaction) to access
shared state in common to ContentFeatureSource and ContentFeatureStore working on this
Transaction. |
Constructor and Description |
---|
ContentFeatureSource(ContentEntry entry,
Query query)
Creates the new feature source from a query.
|
Modifier and Type | Method and Description |
---|---|
void |
accepts(Query query,
FeatureVisitor visitor,
ProgressListener progress)
Visit the features matching the provided query.
|
void |
addFeatureListener(FeatureListener listener)
Adds an listener or observer to the feature source.
|
protected void |
addHints(Set<Hints.Key> hints)
Subclass hook too add additional hints.
|
protected abstract SimpleFeatureType |
buildFeatureType()
Creates the feature type or schema for the feature source.
|
protected QueryCapabilities |
buildQueryCapabilities()
Builds the query capabilities for this feature source.
|
protected boolean |
canEvent()
Determines if the store takes responsibility for issuing events.
|
protected boolean |
canFilter()
Determines if the datastore can natively perform a filtering.
|
protected boolean |
canLimit()
Determines if the datastore can natively limit the number of features returned in a query.
|
protected boolean |
canLock()
Determines if the
datastore can perform feature locking natively. |
protected boolean |
canOffset()
Determines if the datastore can natively skip the first
offset number of
features returned in a query. |
protected boolean |
canReproject()
Determines if the datastore can natively perform reprojection.
|
protected boolean |
canRetype()
Determines if the datasatore can natively perform "retyping" which includes limiting the
number of attributes returned and reordering of those attributes
If the subclass can handle retyping natively it should override this method to return
true . |
protected boolean |
canSort()
Determines if the datastore can natively perform sorting.
|
protected boolean |
canTransact()
Determines if the store can natively manage transactions.
|
protected void |
doLockInternal(String typeName,
SimpleFeature feature)
This method must be implemented overridden when native locking is indicated by
canLock() . |
protected void |
doUnlockInternal(String typeName,
SimpleFeature feature)
This method must be implemented overridden when native locking is indicated by
canLock() . |
protected SimpleFeatureType |
getAbsoluteSchema()
Helper method for returning the underlying schema of the feature source.
|
ReferencedEnvelope |
getBounds()
Returns the bounds of the entire feature source.
|
ReferencedEnvelope |
getBounds(Query query)
Returns the bounds of the results of the specified query against the feature source.
|
protected abstract ReferencedEnvelope |
getBoundsInternal(Query query)
Calculates the bounds of a specified query.
|
int |
getCount(Query query)
Returns the count of the number of features of the feature source.
|
protected abstract int |
getCountInternal(Query query)
Calculates the number of features of a specified query.
|
ContentDataStore |
getDataStore()
The datastore that this feature source originated from.
|
ContentEntry |
getEntry()
The entry for the feature source.
|
ContentFeatureCollection |
getFeatures()
Returns the feature collection of all the features of the feature source.
|
ContentFeatureCollection |
getFeatures(Filter filter)
Returns the feature collection for the features which match the specified filter.
|
ContentFeatureCollection |
getFeatures(Query query)
Returns the feature collection if the features of the feature source which meet the specified
query criteria.
|
ResourceInfo |
getInfo()
A default ResourceInfo with a generic description.
|
Name |
getName()
Returns the same name than the feature type (ie,
getSchema().getName() to honor the
simple feature land common practice of calling the same both the Features produces and their
types |
QueryCapabilities |
getQueryCapabilities()
SimpleFeatureCollection optimized for read-only access.
|
FeatureReader<SimpleFeatureType,SimpleFeature> |
getReader()
Returns a feature reader for all features.
|
FeatureReader<SimpleFeatureType,SimpleFeature> |
getReader(Filter filter)
Returns a reader for features specified by a particular filter.
|
FeatureReader<SimpleFeatureType,SimpleFeature> |
getReader(Query query)
Returns a reader for the features specified by a query.
|
protected abstract FeatureReader<SimpleFeatureType,SimpleFeature> |
getReaderInternal(Query query)
Subclass method for returning a native reader from the datastore.
|
SimpleFeatureType |
getSchema()
Returns the feature type or the schema of the feature source.
|
ContentState |
getState()
The current state for the feature source.
|
Set<RenderingHints.Key> |
getSupportedHints()
The hints provided by the feature store.
|
Transaction |
getTransaction()
The current transaction the feature source is working against.
|
ContentFeatureSource |
getView(Filter filter) |
ContentFeatureSource |
getView(Query query)
Creates a new feature source for the specified query.
|
protected boolean |
handleVisitor(Query query,
FeatureVisitor visitor)
Subclass method which allows subclasses to natively handle a visitor.
|
boolean |
isView()
Indicates if this feature source is actually a view.
|
protected Query |
joinQuery(Query query)
Convenience method for joining a query with the definining query of the feature source.
|
int |
lockFeatures()
Locks all features.
|
int |
lockFeatures(Filter filter)
Locks features specified by a filter.
|
int |
lockFeatures(Query query)
Locks features specified by a query.
|
protected FeatureLock |
processLock(FeatureLock lock)
If the subclass implements native locking, this method is invoked before the feature lock is
(re)assigned to this store.
|
void |
removeFeatureListener(FeatureListener listener)
Removes a listener from the feature source.
|
protected Filter |
resolvePropertyNames(Filter filter)
Transform provided filter; resolving property names
|
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.
|
void |
setFeatureLock(FeatureLock lock)
Sets the feature lock of the feature store.
|
void |
setTransaction(Transaction transaction)
Sets the current transaction the feature source is working against.
|
void |
unLockFeatures()
Unlocks all features.
|
void |
unLockFeatures(Filter filter)
Unlocks features specified by a filter.
|
void |
unLockFeatures(Query query)
Unlocks features specified by a query.
|
protected ContentEntry entry
This entry is managed by the DataStore and is shared between all live ContentFeatureSource and ContentFeatureStore instances.
protected Transaction transaction
ContentEntry.getState(Transaction)
to access
shared state in common to ContentFeatureSource and ContentFeatureStore working on this
Transaction. The use of Transaction.AUTO_COMMIT
is used access the origional/live
content.protected FeatureLock lock
protected Query query
protected SimpleFeatureType schema
protected QueryCapabilities queryCapabilities
public ContentFeatureSource(ContentEntry entry, Query query)
The query is taken into account for any operations done against the feature
source. For example, when getReader(Query) is called the query specified is "joined" to the
query specified in the constructor. The query parameter may be null
to
specify that the feature source represents the entire set of features.
public ContentEntry getEntry()
public Transaction getTransaction()
This transaction is used to derive the state for the feature source. A null
value for a transaction represents the auto commit transaction: Transaction.AUTO_COMMIT
.
#getState()}.
public void setTransaction(Transaction transaction)
transaction may be null
. This signifies that the auto-commit
transaction is used: Transaction.AUTO_COMMIT
.
transaction
- The new transaction, or null
.public ContentState getState()
This value is derived from current transaction of the feature source.
#setTransaction(Transaction)}.
public ContentDataStore getDataStore()
Subclasses may wish to extend this method in order to type narrow its return type.
getDataStore
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
FeatureSource
public final boolean isView()
public ResourceInfo getInfo()
Subclasses should override to provide an explicit ResourceInfo object for their content.
getInfo
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
public Name getName()
getSchema().getName()
to honor the
simple feature land common practice of calling the same both the Features produces and their
typesgetName
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
FeatureSource
FeatureSource.getName()
public final SimpleFeatureType getSchema()
This method delegates to buildFeatureType()
, which must be implemented by
subclasses. The result is cached in ContentState.getFeatureType()
.
getSchema
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
FeatureSource
protected final SimpleFeatureType getAbsoluteSchema()
public final ReferencedEnvelope getBounds() throws IOException
This method delegates to getBounds(Query)
:
return getBounds(Query.ALL)
.
getBounds
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
null
if the bounds are unknown
or too costly to calculate.IOException
- on any errors calculating the boundspublic final ReferencedEnvelope getBounds(Query query) throws IOException
This method calls through to getBoundsInternal(Query)
which subclasses must
implement. It also contains optimizations which check state for cached values.
getBounds
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
query
- the query to select featuresnull
if the bounds are unknown
or too costly to calculate.IOException
- on any errors calculating the boundsprotected abstract ReferencedEnvelope getBoundsInternal(Query query) throws IOException
IOException
public final int getCount(Query query) throws IOException
This method calls through to getCountInternal(Query)
which subclasses must
implement. It also contains optimizations which check state for cached values.
getCount
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
query
- the query to select featuresQuery
;
or -1
if this cannot be calculated.IOException
- if there are errors getting the countprotected abstract int getCountInternal(Query query) throws IOException
IOException
public final ContentFeatureCollection getFeatures() throws IOException
getFeatures
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
getFeatures
in interface SimpleFeatureSource
Query
IOException
- if the underlying data source cannot be accessed.public final FeatureReader<SimpleFeatureType,SimpleFeature> getReader() throws IOException
This method calls through to getReader(Query)
.
IOException
public final ContentFeatureCollection getFeatures(Query query) throws IOException
getFeatures
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
getFeatures
in interface SimpleFeatureSource
query
- DataAccess query for requested information, such as typeName, maxFeatures and
filter.Query
IOException
- if the underlying data source cannot be accessed.Query
public final FeatureReader<SimpleFeatureType,SimpleFeature> getReader(Query query) throws IOException
IOException
public void accepts(Query query, FeatureVisitor visitor, ProgressListener progress) throws IOException
The default information will use getReader( query ) and pass each feature to the provided visitor. Subclasses should override this method to optimise common visitors:
Often in the case of Filter.INCLUDES the information can be determined from a file header or metadata table.visitor
- Visitor called for each featureprogress
- Used to report progress; and errors on a feature by feature basisIOException
protected boolean handleVisitor(Query query, FeatureVisitor visitor) throws IOException
Subclasses would override this method and return true in cases where the specific visitor could be handled without iterating over the entire result set of query. An example would be handling visitors that calculate aggregate values.
query
- The query being made.visitor
- The visitor toIOException
protected abstract FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) throws IOException
It is important to note that if the native reader intends to handle any of the following natively:
true
:
canReproject()
- handles Query.getCoordinateSystemReproject()
internally.
Example would be PostGIS using Proj to handle reproejction internallycanFilter()
- handles Query#getFilter() internally.IOException
protected boolean canReproject()
If the subclass can handle reprojection natively then it should override this method to
return true
. In this case it must do the reprojection or throw an
exception.
Not overriding this method or returning false
will case the feature reader
created by the subclass to be wrapped in a reprojecting decorator when the query specifies a
coordinate system reproject (using crs and crsReproject)
To handle reprojection an implementation should:
Query.getCoordinateSystem()
- optional override - if provided this is used
instead of the native CRS provided by the data format (as a workaround for clients).
Query.getCoordinateSystemReproject()
- if this value is provided it is
used to set up a transform from the origional CRS (native or from query).
ReprojectFeatureReader
protected boolean canLimit()
If the subclass can handle a map feature cap natively then it should override this method
to return true
. In this case it must do the cap or throw an exception.
Not overriding this method or returning false
will case the feature reader
created by the subclass to be wrapped in a max feature capping decorator when the query
specifies a max feature cap.
MaxFeatureReader
protected boolean canOffset()
offset
number of
features returned in a query.
If the subclass can handle a map feature cap natively then it should override this method
to return true
. In this case it must do the cap or throw an exception.
Not overriding this method or returning false
will case the feature reader
created by the subclass to be be accesset offset times before being returned to the caller.
protected boolean canFilter()
If the subclass can handle filtering natively it should override this method to return
true
. In this case it must do the filtering or throw an exception. This
includes the case of partial native filtering where the datastore can only handle part of the
filter natively. In these cases it is up to the subclass to apply a decorator to the reader
it returns which will handle any part of the filter can was not applied natively. See FilteringFeatureReader
.
Not overriding this method or returning false
will cause the feature reader
created by the subclass to be wrapped in a filtering feature reader when the query specifies
a filter. See FilteringFeatureReader
.
protected boolean canRetype()
If the subclass can handle retyping natively it should override this method to return
true
. In this case it must do the retyping or throw an exception.
Not overriding this method or returning false
will cause the feature reader
created by the subclass to be wrapped in a retyping feature reader when the query specifies a
retype.
ReTypeFeatureReader
protected boolean canSort()
If the subclass can handle retyping natively it should override this method to return
true
. In this case it must do the retyping or throw an exception.
Not overriding this method or returning false
will cause an exception to be
thrown when the query specifies sorting.
SortedFeatureReader
protected boolean canTransact()
If a subclass can handle transactions natively it should override this method to return
true
and deal with transactions on its own, including firing feature
modifications events.
protected boolean canEvent()
If a subclass issue events (as part of its low level writer implementation) then it should override this method to return true.
public final ContentFeatureSource getView(Query query) throws IOException
If the current feature source already has a defining query it is joined to the specified query.
query
- IOException
public final ContentFeatureCollection getFeatures(Filter filter) throws IOException
This method calls through to getFeatures(Query)
.
getFeatures
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
getFeatures
in interface SimpleFeatureSource
filter
- the filter to select features; must not be null
(use Filter.INCLUDE instead)Filter
IOException
- if the underlying data source cannot be accessed.Filter
public final FeatureReader<SimpleFeatureType,SimpleFeature> getReader(Filter filter) throws IOException
This method calls through to getReader(Query)
.
IOException
public final ContentFeatureSource getView(Filter filter) throws IOException
IOException
public final void addFeatureListener(FeatureListener listener)
Listeners are stored on a per-transaction basis.
addFeatureListener
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
listener
- the new listenerpublic final void removeFeatureListener(FeatureListener listener)
removeFeatureListener
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
listener
- the listener to removepublic final Set<RenderingHints.Key> getSupportedHints()
Subclasses should implement addHints(Set)
to provide additional hints.
getSupportedHints
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
RenderingHints#Key
objects; may be empty but never null
FeatureSource.getSupportedHints()
protected void addHints(Set<Hints.Key> hints)
By default, the followings are already present:
hints
- The set of hints supported by the feature source.protected Query joinQuery(Query query)
protected Query resolvePropertyNames(Query query)
For example, this method ensures that propertyName's such as "gml:name" are rewritten as simply "name".
protected Filter resolvePropertyNames(Filter filter)
protected abstract SimpleFeatureType buildFeatureType() throws IOException
Implementations should use SimpleFeatureTypeBuilder
to build the feature type.
Also, the builder should be injected with the feature factory which has been set on the
DataStore (see ContentDataStore.getFeatureFactory()
. Example:
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setFeatureTypeFactory( getDataStore().getFeatureTypeFactory() ); //build the feature type ...
IOException
protected QueryCapabilities buildQueryCapabilities()
IOException
public QueryCapabilities getQueryCapabilities()
Available via getView( filter ):
In particular this method of data access is intended for rendering and other high speed operations; care should be taken to optimize the use of FeatureVisitor.
getQueryCapabilities
in interface FeatureSource<SimpleFeatureType,SimpleFeature>
transactionState
- filter
- public final void setFeatureLock(FeatureLock lock)
public final int lockFeatures() throws IOException
This method calls through to lockFeatures(Filter)
.
IOException
public final int lockFeatures(Query query) throws IOException
This method calls through to lockFeatures(Filter)
.
IOException
public final int lockFeatures(Filter filter) throws IOException
IOException
public final void unLockFeatures() throws IOException
This method calls through to unLockFeatures(Filter)
.
IOException
public final void unLockFeatures(Query query) throws IOException
This method calls through to unLockFeatures(Filter)
.
IOException
public final void unLockFeatures(Filter filter) throws IOException
IOException
protected boolean canLock()
datastore
can perform feature locking natively.
If #getWriterInternal(Query, int)
returns a feature writer
that supports feature locking natively, it should override this method to return true
.
Not overriding this method or returning false
will cause ContentFeatureStore
to use the InProcessLockingManager
to return a FeatureWriter
that honors locks.
protected FeatureLock processLock(FeatureLock lock)
lock
- - a FeatureLock
instanceFeatureLock
instanceprotected void doLockInternal(String typeName, SimpleFeature feature) throws IOException
canLock()
.typeName
- SimpleFeature
type namefeature
- SimpleFeature
instanceIOException
protected void doUnlockInternal(String typeName, SimpleFeature feature) throws IOException
canLock()
.typeName
- Feature
type namefeature
- Feature
instanceIOException
Copyright © 1996–2019 Geotools. All rights reserved.