org.geotools.data.postgis
Class VersionedPostgisFeatureStore

java.lang.Object
  extended by org.geotools.data.AbstractFeatureSource
      extended by org.geotools.data.AbstractFeatureStore
          extended by org.geotools.data.postgis.VersionedPostgisFeatureStore
All Implemented Interfaces:
FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, VersioningFeatureSource, VersioningFeatureStore

public class VersionedPostgisFeatureStore
extends AbstractFeatureStore
implements VersioningFeatureStore

A cheap implementation of a feature locking.

Implementation wise, for all locking needs, tries to leverage the wrapped datastore feature locking. If an optimization is possible (mass updates come to mind), we try to use the feature locking, otherwiser we fall back on the implementation inherited from AbstractFeatureSource.

modifyFeatures(AttributeDescriptor[], Object[], Filter) is an example of things that cannot be optimized. Theoretically, one could mass expire current feature, but he should have first read into memory all of them to rewrite them as new (which may not be possible).

Since:
2.4
Author:
aaime

Field Summary
 
Fields inherited from class org.geotools.data.AbstractFeatureStore
transaction
 
Fields inherited from class org.geotools.data.AbstractFeatureSource
hints, queryCapabilities
 
Constructor Summary
VersionedPostgisFeatureStore(org.opengis.feature.simple.SimpleFeatureType schema, VersionedPostgisDataStore store)
           
 
Method Summary
 void addFeatureListener(FeatureListener listener)
          Adds a listener to the list that's notified each time a change to the FeatureStore occurs.
 java.util.List<org.opengis.filter.identity.FeatureId> addFeatures(FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> collection)
          Adds all features from the passed feature collection to the datasource.
 ReferencedEnvelope getBounds()
          Retrieve Bounds of all Features.
 ReferencedEnvelope getBounds(Query query)
          Retrieve Bounds of Query results.
 int getCount(Query query)
          Retrieve total number of Query results.
 DataStore getDataStore()
          Overrides to explicitly type narrow the return type to DataStore
 FeatureDiffReaderImpl getDifferences(java.lang.String fromVersion, java.lang.String toVersion, org.opengis.filter.Filter filter, java.lang.String[] userIds)
          Returns a feature difference reader providing the changes occurred on filtered features between the two specified versions
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures()
          Retrieve all Features.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures(org.opengis.filter.Filter filter)
          Retrieve all Feature matching the Filter.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures(Query query)
          Provides an interface to for the Results of a Query.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getLog(java.lang.String fromVersion, java.lang.String toVersion, org.opengis.filter.Filter filter, java.lang.String[] userIds, int maxRows)
          Returns a log of changes performed between fromVersion and toVersion against the features matched by the specified filter.
 QueryCapabilities getQueryCapabilities()
          Returns and indication of what query capabilities this FeatureSource supports natively.
 org.opengis.feature.simple.SimpleFeatureType getSchema()
          Retrieves the featureType that features extracted from this datasource will be created with.
 java.util.Set getSupportedHints()
          By default, no Hints are supported
 Transaction getTransaction()
          Retrieve the Transaction this FeatureSource is opperating against.
 java.lang.String getVersion()
          Returns the revision for the current transaction, or null if no transaction is set.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures()
          Returns the same features as FeatureSource.getFeatures() but providing more attributes, namely, revision, author and date of the version.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures(org.opengis.filter.Filter filter)
          Returns the same features as FeatureSource.getFeatures(Filter) but providing more attributes, namely, revision, author and date of the version.
 FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures(Query query)
          Returns the same features as FeatureSource.getFeatures(Query) but providing more attributes, namely, revision, author and date of the version.
 void modifyFeatures(org.opengis.feature.type.AttributeDescriptor[] type, java.lang.Object[] value, org.opengis.filter.Filter filter)
          Modifies features matching filter.
 void modifyFeatures(org.opengis.feature.type.AttributeDescriptor type, java.lang.Object value, org.opengis.filter.Filter filter)
          Modifies features matching filter.
 void removeFeatureListener(FeatureListener listener)
          Removes a listener from the list that's notified each time a change to the FeatureStore occurs.
 void removeFeatures(org.opengis.filter.Filter filter)
          Removes features indicated by provided filter.
 void rollback(java.lang.String toVersion, org.opengis.filter.Filter filter, java.lang.String[] userIds)
          Rolls back features matching the filter to the state they had on the specified version.
 void setFeatures(FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> reader)
          Replace with contents of reader.
 void setTransaction(Transaction transaction)
          Provides a transaction for commit/rollback control of this FeatureStore.
 
Methods inherited from class org.geotools.data.AbstractFeatureStore
addFeatures
 
Methods inherited from class org.geotools.data.AbstractFeatureSource
getInfo, getName, namedQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.data.FeatureSource
getInfo, getName
 

Constructor Detail

VersionedPostgisFeatureStore

public VersionedPostgisFeatureStore(org.opengis.feature.simple.SimpleFeatureType schema,
                                    VersionedPostgisDataStore store)
                             throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getTransaction

public Transaction getTransaction()
Description copied from class: AbstractFeatureStore
Retrieve the Transaction this FeatureSource is opperating against.

Specified by:
getTransaction in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getTransaction in class AbstractFeatureStore
Returns:
Transaction FeatureSource is operating against

setTransaction

public void setTransaction(Transaction transaction)
Description copied from interface: FeatureStore
Provides a transaction for commit/rollback control of this FeatureStore.

This method operates as a replacement for setAutoCommitMode. When a transaction is provided you are no longer automatically committing.

In order to return to AutoCommit mode supply the Transaction.AUTO_COMMIT to this method. Since this represents a return to AutoCommit mode the previous Transaction will be commited.

Specified by:
setTransaction in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
setTransaction in class AbstractFeatureStore
Parameters:
transaction - DOCUMENT ME!

getBounds

public ReferencedEnvelope getBounds()
                             throws java.io.IOException
Description copied from class: AbstractFeatureSource
Retrieve Bounds of all Features.

Currently returns null, consider getFeatures().getBounds() instead.

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
getBounds in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getBounds in class AbstractFeatureSource
Returns:
null representing the lack of an optimization
Throws:
java.io.IOException - DOCUMENT ME!

getBounds

public ReferencedEnvelope getBounds(Query query)
                             throws java.io.IOException
Description copied from class: AbstractFeatureSource
Retrieve Bounds of Query results.

Currently returns null, consider getFeatures( query ).getBounds() instead.

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
getBounds in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getBounds in class AbstractFeatureSource
Parameters:
query - Query we are requesting the bounds of
Returns:
null representing the lack of an optimization
Throws:
java.io.IOException - DOCUMENT ME!

getCount

public int getCount(Query query)
             throws java.io.IOException
Description copied from class: AbstractFeatureSource
Retrieve total number of Query results.

Currently returns -1, consider getFeatures( query ).getCount() instead.

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
getCount in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getCount in class AbstractFeatureSource
Parameters:
query - Query we are requesting the count of
Returns:
-1 representing the lack of an optimization
Throws:
java.io.IOException - if there are errors getting the count

getDataStore

public DataStore getDataStore()
Description copied from class: AbstractFeatureSource
Overrides to explicitly type narrow the return type to DataStore

Specified by:
getDataStore in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Specified by:
getDataStore in class AbstractFeatureSource
Returns:
DataStore implementing this FeatureStore

addFeatureListener

public void addFeatureListener(FeatureListener listener)
Description copied from interface: FeatureSource
Adds a listener to the list that's notified each time a change to the FeatureStore occurs.

Specified by:
addFeatureListener in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
listener - FeatureListener

getSchema

public org.opengis.feature.simple.SimpleFeatureType getSchema()
Description copied from interface: FeatureSource
Retrieves the featureType that features extracted from this datasource will be created with.

The schema returned is the LCD supported by all available Features. In the common case of shapfiles and database table this schema will match that of every feature available. In the degenerate GML case this will simply reflect the gml:AbstractFeatureType.

Specified by:
getSchema in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Returns:
the schema of features created by this datasource.

removeFeatureListener

public void removeFeatureListener(FeatureListener listener)
Description copied from interface: FeatureSource
Removes a listener from the list that's notified each time a change to the FeatureStore occurs.

Specified by:
removeFeatureListener in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
listener - FeatureListener

modifyFeatures

public void modifyFeatures(org.opengis.feature.type.AttributeDescriptor type,
                           java.lang.Object value,
                           org.opengis.filter.Filter filter)
                    throws java.io.IOException
Description copied from class: AbstractFeatureStore
Modifies features matching filter.

Equivelent to:


 FeatureWriter writer = dataStore.getFeatureWriter( typeName, filter, transaction );
 while( writer.hasNext() ){
    feature = writer.next();
    feature.setAttribute( type.getName(), value );
    writer.write();
 }
 writer.close();
 
 

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
modifyFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
modifyFeatures in class AbstractFeatureStore
Parameters:
type - Attribute to modify
value - Modification being made to type
filter - Identifies features to modify
Throws:
java.io.IOException - If modification could not be made

modifyFeatures

public void modifyFeatures(org.opengis.feature.type.AttributeDescriptor[] type,
                           java.lang.Object[] value,
                           org.opengis.filter.Filter filter)
                    throws java.io.IOException
Description copied from class: AbstractFeatureStore
Modifies features matching filter.

Equivelent to:


 FeatureWriter writer = dataStore.getFeatureWriter( typeName, filter, transaction );
 Feature feature;
 while( writer.hasNext() ){
    feature = writer.next();
    feature.setAttribute( type[0].getName(), value[0] );
    feature.setAttribute( type[1].getName(), value[1] );
    ...
    feature.setAttribute( type[N].getName(), value[N] ); 
    writer.write();
 }
 writer.close();
 
 

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
modifyFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
modifyFeatures in class AbstractFeatureStore
Parameters:
type - Attributes to modify
value - Modifications being made to type
filter - Identifies features to modify
Throws:
java.io.IOException - If we could not modify Feature
DataSourceException - See IOException

removeFeatures

public void removeFeatures(org.opengis.filter.Filter filter)
                    throws java.io.IOException
Description copied from class: AbstractFeatureStore
Removes features indicated by provided filter.

Equivelent to:


 FeatureWriter writer = dataStore.getFeatureWriter( typeName, filter, transaction );
 Feature feature;
 while( writer.hasNext() ){
    feature = writer.next();
    writer.remove();
 }
 writer.close();
 
 

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
removeFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
removeFeatures in class AbstractFeatureStore
Parameters:
filter - Identifies features to remove
Throws:
java.io.IOException - If anything goes wrong.

setFeatures

public void setFeatures(FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> reader)
                 throws java.io.IOException
Description copied from class: AbstractFeatureStore
Replace with contents of reader.

Equivelent to:


 FeatureWriter writer = dataStore.getFeatureWriter( typeName, false, transaction );
 Feature feature, newFeature;
 while( writer.hasNext() ){
    feature = writer.next();
    writer.remove();
 }
 while( reader.hasNext() ){
    newFeature = reader.next();
    feature = writer.next();
    newFeature.setAttributes( feature.getAttributes( null ) );
    writer.write();
 }
 reader.close();
 writer.close();
 
 

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
setFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
setFeatures in class AbstractFeatureStore
Parameters:
reader - Contents to replace with
Throws:
java.io.IOException - if anything goes wrong during replacement
DataSourceException - See IOException

getFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures(Query query)
                                                                                                                     throws java.io.IOException
Description copied from class: AbstractFeatureSource
Provides an interface to for the Results of a Query.

Various queries can be made against the results, the most basic being to retrieve Features.

Specified by:
getFeatures in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getFeatures in class AbstractFeatureSource
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:
FeatureSource.getFeatures(org.geotools.data.Query)

getFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures(org.opengis.filter.Filter filter)
                                                                                                                     throws java.io.IOException
Description copied from class: AbstractFeatureSource
Retrieve all Feature matching the Filter.

Specified by:
getFeatures in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getFeatures in class AbstractFeatureSource
Parameters:
filter - Indicates features to retrieve
Returns:
FeatureResults indicating features matching filter
Throws:
java.io.IOException - If results could not be obtained

getFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatures()
                                                                                                                     throws java.io.IOException
Description copied from class: AbstractFeatureSource
Retrieve all Features.

Specified by:
getFeatures in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getFeatures in class AbstractFeatureSource
Returns:
FeatureResults of all Features in FeatureSource
Throws:
java.io.IOException - If features could not be obtained

getVersionedFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures(Query query)
                                                                                                                              throws java.io.IOException
Description copied from interface: VersioningFeatureSource
Returns the same features as FeatureSource.getFeatures(Query) but providing more attributes, namely, revision, author and date of the version.

Specified by:
getVersionedFeatures in interface VersioningFeatureSource
Returns:
Throws:
java.io.IOException

getVersionedFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures(org.opengis.filter.Filter filter)
                                                                                                                              throws java.io.IOException
Description copied from interface: VersioningFeatureSource
Returns the same features as FeatureSource.getFeatures(Filter) but providing more attributes, namely, revision, author and date of the version.

Specified by:
getVersionedFeatures in interface VersioningFeatureSource
Returns:
Throws:
java.io.IOException

getVersionedFeatures

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getVersionedFeatures()
                                                                                                                              throws java.io.IOException
Description copied from interface: VersioningFeatureSource
Returns the same features as FeatureSource.getFeatures() but providing more attributes, namely, revision, author and date of the version.

Specified by:
getVersionedFeatures in interface VersioningFeatureSource
Returns:
Throws:
java.io.IOException

addFeatures

public java.util.List<org.opengis.filter.identity.FeatureId> addFeatures(FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> collection)
                                                                  throws java.io.IOException
Description copied from interface: FeatureStore
Adds all features from the passed feature collection to the datasource.

A list of FeatureIds is returned; one for each Feature in the order created. Please note that these FeatureIds may not be assigned until after a commit has been performed.

Specified by:
addFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
addFeatures in class AbstractFeatureStore
Parameters:
collection - The collection of features to add.
Returns:
the FeatureIds of the newly added features.
Throws:
java.io.IOException - if anything goes wrong.

getVersion

public java.lang.String getVersion()
                            throws java.io.IOException
Description copied from interface: VersioningFeatureStore
Returns the revision for the current transaction, or null if no transaction is set. This operation is optional, some datastore may not be able to determine the version before the commit, in that case an UnsupportedOperationException will be thrown

Specified by:
getVersion in interface VersioningFeatureStore
Returns:
Throws:
java.io.IOException

rollback

public void rollback(java.lang.String toVersion,
                     org.opengis.filter.Filter filter,
                     java.lang.String[] userIds)
              throws java.io.IOException
Description copied from interface: VersioningFeatureStore
Rolls back features matching the filter to the state they had on the specified version.

For a feature to be included into the rollback it's sufficient that one of its states between toVersion and current matches the filter.

Specified by:
rollback in interface VersioningFeatureStore
Parameters:
toVersion - target of the rollback
filter - limits the feature whose history will be rolled back by an OGC filter
userIds - limits the feaeature whose history will be rolled back, by catching only those that have been modified by at least one of the specified users. May be null to avoi user filtering.
Throws:
java.io.IOException

getLog

public FeatureCollection<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getLog(java.lang.String fromVersion,
                                                                                                                       java.lang.String toVersion,
                                                                                                                       org.opengis.filter.Filter filter,
                                                                                                                       java.lang.String[] userIds,
                                                                                                                       int maxRows)
                                                                                                                throws java.io.IOException
Description copied from interface: VersioningFeatureSource
Returns a log of changes performed between fromVersion and toVersion against the features matched by the specified filter.

This is equivalent to gathering the ids of features changed between the two versions and matching the filter, getting a list of revision involving those feaures between fromVersion and toVersion, and then query VersionedPostgisDataStore.TBL_CHANGESETS against these revision numbers.

Specified by:
getLog in interface VersioningFeatureSource
Parameters:
fromVersion - the start revision
toVersion - the end revision, may be null to imply the latest one
filter - will match features whose log will be reported *
maxRows - the maximum number of log rows returned from this call
Returns:
a feature collection of the logs, sorted on revision, descending
Throws:
java.io.IOException

getDifferences

public FeatureDiffReaderImpl getDifferences(java.lang.String fromVersion,
                                            java.lang.String toVersion,
                                            org.opengis.filter.Filter filter,
                                            java.lang.String[] userIds)
                                     throws java.io.IOException
Description copied from interface: VersioningFeatureSource
Returns a feature difference reader providing the changes occurred on filtered features between the two specified versions

Specified by:
getDifferences in interface VersioningFeatureSource
Parameters:
fromVersion - the start version
toVersion - the end version, may be null to imply the latest one
filter - matches features whose differences will be reported *
Returns:
a difference reader
Throws:
java.io.IOException

getSupportedHints

public java.util.Set getSupportedHints()
Description copied from class: AbstractFeatureSource
By default, no Hints are supported

Specified by:
getSupportedHints in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getSupportedHints in class AbstractFeatureSource
Returns:
a set of RenderingHints#Key objects (eventually empty, never null).

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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getQueryCapabilities in class AbstractFeatureSource
Returns:
a QueryCapabilities object containing the native query capabilities.


Copyright © 1996-2010 Geotools. All Rights Reserved.