org.geotools.caching.featurecache
Class AbstractFeatureCache

java.lang.Object
  extended by org.geotools.caching.featurecache.AbstractFeatureCache
All Implemented Interfaces:
java.util.EventListener, FeatureCache, FeatureListener, FeatureSource
Direct Known Subclasses:
GridFeatureCache

public abstract class AbstractFeatureCache
extends java.lang.Object
implements FeatureCache, FeatureListener

Abstract implementation of a feature cache.

This implementation uses envelopes to deal with determining what has been added to the cache already and what items need to be retrieved from the feature source.


Field Summary
protected static org.opengis.filter.FilterFactory ff
           
protected  FeatureSource fs
           
protected  java.util.concurrent.locks.ReentrantReadWriteLock lock
           
protected static java.util.logging.Logger logger
           
protected  int source_feature_reads
           
protected  int source_hits
           
 
Constructor Summary
AbstractFeatureCache(FeatureSource fs)
          Creates a new feature cache from the given feature source.
 
Method Summary
protected  FeatureCollection _getFeatures(org.opengis.filter.Filter filter)
          Gets features with satisfy a given filter.
 void addFeatureListener(FeatureListener listener)
          Adds a feature listener
 void changed(FeatureEvent event)
          This event is fired when the features in the feature source have changed.
 FeatureCollection get(com.vividsolutions.jts.geom.Envelope e)
          Get all features within a given envelope as a in memory feature collection.
 DataAccess getDataStore()
          Returns the DataAccess of the underlying feature source
 FeatureCollection getFeatures()
          Gets all features from that are contained within the feature source.
 FeatureCollection getFeatures(org.opengis.filter.Filter filter)
          Get all features with satisfy a given filter.
 FeatureCollection getFeatures(Query query)
          Gets all features which satisfy the given query.
 ResourceInfo getInfo()
          Information describing the contents of this resoruce.
 org.opengis.feature.type.Name getName()
          Returns the qualified name for the Features this FeatureSource serves.
 QueryCapabilities getQueryCapabilities()
          Returns and indication of what query capabilities this FeatureSource supports natively.
 org.opengis.feature.simple.SimpleFeatureType getSchema()
          Returns the feature schema of the underlying feature source.
abstract  java.lang.String getStats()
          Gets the feature cache statistics
protected abstract  void isOversized(FeatureCollection fc)
          Determines if the given feature collection is too big to put into the cache.
protected abstract  java.util.List<com.vividsolutions.jts.geom.Envelope> match(com.vividsolutions.jts.geom.Envelope e)
          Returns a list of envelopes that are not in the cache but within the given bounds.
 void readLock()
          Gets a read lock
 void readUnLock()
          Unlocks the read lock
protected  void register(BBOXImpl f)
          Registers a given bounding box filter with the cache.
protected abstract  void register(com.vividsolutions.jts.geom.Envelope e)
          Registers a given envelope with the cache.
 void register(org.opengis.filter.Filter f)
          Registers filter from the cache.
 void removeFeatureListener(FeatureListener listener)
          Removes a feature listener.
 java.lang.String sourceAccessStats()
          Returns a string containing statistics about data source reading.
protected  void unregister(BBOXImpl f)
          Unregisters a given bounding box filter with the cache.
protected abstract  void unregister(com.vividsolutions.jts.geom.Envelope e)
          Unregisters a given envelope with the cache.
 void unregister(org.opengis.filter.Filter f)
          Unregisters filter from the cache.
 void writeLock()
          Gets a write lock
 void writeUnLock()
          unlocks the write lock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.caching.featurecache.FeatureCache
clear, dispose, peek, put, put, remove
 
Methods inherited from interface org.geotools.data.FeatureSource
getBounds, getBounds, getCount, getSupportedHints
 

Field Detail

logger

protected static java.util.logging.Logger logger

ff

protected static org.opengis.filter.FilterFactory ff

fs

protected FeatureSource fs

source_hits

protected int source_hits

source_feature_reads

protected int source_feature_reads

lock

protected java.util.concurrent.locks.ReentrantReadWriteLock lock
Constructor Detail

AbstractFeatureCache

public AbstractFeatureCache(FeatureSource fs)
Creates a new feature cache from the given feature source.

Parameters:
fs -
Method Detail

addFeatureListener

public void addFeatureListener(FeatureListener listener)
Adds a feature listener

Specified by:
addFeatureListener in interface FeatureSource
Parameters:
listener - FeatureListener

getDataStore

public DataAccess getDataStore()
Returns the DataAccess of the underlying feature source

Specified by:
getDataStore in interface FeatureSource
Returns:
DataStore implementing this FeatureStore

getFeatures

public FeatureCollection getFeatures()
                              throws java.io.IOException
Gets all features from that are contained within the feature source.

Specified by:
getFeatures in interface FeatureSource
Returns:
Collection The collection to put the features into.
Throws:
java.io.IOException - For all data source errors.

getFeatures

public FeatureCollection getFeatures(Query query)
                              throws java.io.IOException
Gets all features which satisfy the given query.

This version gets all the features from the cache and datastore and combines them in a memory feature collection.

This should probably be overwritten for any implementations.

Specified by:
getFeatures in interface FeatureSource
Parameters:
query - a datasource query object. It encapsulates requested information, such as typeName, maxFeatures and filter.
Returns:
Collection The collection to put the features into.
Throws:
java.io.IOException - For all data source errors.
See Also:
Query

getFeatures

public FeatureCollection getFeatures(org.opengis.filter.Filter filter)
                              throws java.io.IOException
Get all features with satisfy a given filter.

This version gets all features from the cache and from memory and combines them in a memory feature collection.

This should probably be overwritten for any implementations.

Specified by:
getFeatures in interface FeatureSource
Parameters:
filter - An OpenGIS filter; specifies which features to retrieve. null is not allowed, use Filter.INCLUDE instead.
Returns:
Collection The collection to put the features into.
Throws:
java.io.IOException - For all data source errors.

_getFeatures

protected FeatureCollection _getFeatures(org.opengis.filter.Filter filter)
                                  throws java.io.IOException
Gets features with satisfy a given filter.

Parameters:
filter - must be a BBOXImpl filter
Returns:
Throws:
java.io.IOException

get

public FeatureCollection get(com.vividsolutions.jts.geom.Envelope e)
                      throws java.io.IOException
Get all features within a given envelope as a in memory feature collection.

Specified by:
get in interface FeatureCache
Returns:
Collection of feature found in the given envelope (from the cache or feature source)
Throws:
java.io.IOException

match

protected abstract java.util.List<com.vividsolutions.jts.geom.Envelope> match(com.vividsolutions.jts.geom.Envelope e)
Returns a list of envelopes that are not in the cache but within the given bounds.

Parameters:
e -
Returns:

register

protected void register(BBOXImpl f)
Registers a given bounding box filter with the cache.

This informs the cache that it has data for the given area.

Parameters:
f -

register

protected abstract void register(com.vividsolutions.jts.geom.Envelope e)
Registers a given envelope with the cache.

This informs the cache that it has data for the given area.

Parameters:
e -

unregister

protected abstract void unregister(com.vividsolutions.jts.geom.Envelope e)
Unregisters a given envelope with the cache.

This informs the cache that there is no data for the given envelope or that the data is incomplete.

Parameters:
e -

unregister

protected void unregister(BBOXImpl f)
Unregisters a given bounding box filter with the cache.

This informs the cache that there is no data for the given envelope or that the data is incomplete.

Parameters:
e -

unregister

public void unregister(org.opengis.filter.Filter f)
Unregisters filter from the cache.

Filter needs to be an instance of BBOXImpl or a collection of BBOXImpls that are combined using or. Any other combination will result in a UnsupportedOperationException.

Parameters:
f -

isOversized

protected abstract void isOversized(FeatureCollection fc)
                             throws CacheOversizedException
Determines if the given feature collection is too big to put into the cache.

Parameters:
fc -
Throws:
CacheOversizedException - if feature collection is to big for cache

getSchema

public org.opengis.feature.simple.SimpleFeatureType getSchema()
Returns the feature schema of the underlying feature source.

Specified by:
getSchema in interface FeatureSource
Returns:
the schema of features created by this datasource.

removeFeatureListener

public void removeFeatureListener(FeatureListener listener)
Removes a feature listener.

Specified by:
removeFeatureListener in interface FeatureSource
Parameters:
listener - FeatureListener

changed

public void changed(FeatureEvent event)
This event is fired when the features in the feature source have changed.

Specified by:
changed in interface FeatureListener
Parameters:
event - The FeatureEvent being fired

register

public void register(org.opengis.filter.Filter f)
Registers filter from the cache.

Filter needs to be an instance of BBOXImpl or a collection of BBOXImpls that are combined using or. Any other combination will result in a UnsupportedOperationException.

Parameters:
f -

sourceAccessStats

public java.lang.String sourceAccessStats()
Returns a string containing statistics about data source reading.

Stats include: Source hits and Feature Source Reads

Returns:

getStats

public abstract java.lang.String getStats()
Gets the feature cache statistics

Returns:

readLock

public void readLock()
Gets a read lock


readUnLock

public void readUnLock()
Unlocks the read lock


writeLock

public void writeLock()
Gets a write lock


writeUnLock

public void writeUnLock()
unlocks the write lock


getInfo

public ResourceInfo getInfo()
Description copied from interface: FeatureSource
Information describing the contents of this resoruce.

Please note that for FeatureContent:


getName

public org.opengis.feature.type.Name getName()
Description copied from interface: FeatureSource
Returns the qualified name for the Features this FeatureSource serves.

Note this is different from getSchema().getType().getName() (that is, the feature type name), this name specifies the AttributeDescriptor name for the Features served by this source. So, FeatureSoruce.getName() == FeatureSource.getFeatures().next().getAttributeDescriptor().getName().

Though it's a common practice when dealing with SimpleFeatureType and SimpleFeature to assume they're equal. There's no conflict (as per the dynamic typing system the org.opengis.feature package defines) in a Feature and its type sharing the same name, as well as in a GML schema an element declaration and a type definition may be named the same. Yet, the distinction becomes important as we get rid of that assumption and thus allow to reuse a type definition for different FeatureSoruces, decoupling the descriptor (homologous to the Feature element declaration in a GML schema) from its type definition.

So, even if implementors are allowed to delegate to getSchema().getName() if they want to call the fatures and their type the same, client code asking a DataAccess.getFeatureSource(Name) shall use this name to request for a FeatureSource, rather than the type name, as used in pre 2.5 versions of GeoTools. For example, if we have a FeatureSource named Roads and its type is named Roads_Type, the DataAccess shall be queried through Roads, not Roads_Type.

Specified by:
getName in interface FeatureSource
Returns:
the name from the main feature source being cached

getQueryCapabilities

public QueryCapabilities getQueryCapabilities()
Description copied from interface: FeatureSource
Returns and indication of what query capabilities this FeatureSource supports natively.

Specified by:
getQueryCapabilities in interface FeatureSource
Returns:
the query capabilities from the main feature source being cached


Copyright © 1996-2010 Geotools. All Rights Reserved.