org.geotools.data
Class AbstractFeatureStore

Object
  extended by AbstractFeatureSource
      extended by AbstractFeatureStore
All Implemented Interfaces:
FeatureSource<SimpleFeatureType,SimpleFeature>, FeatureStore<SimpleFeatureType,SimpleFeature>, SimpleFeatureSource, SimpleFeatureStore
Direct Known Subclasses:
AbstractFeatureLocking

public abstract class AbstractFeatureStore
extends AbstractFeatureSource
implements SimpleFeatureStore

This is a starting point for providing your own FeatureStore implementation.

Author:
Jody Garnett, Refractions Research

Field Summary
protected  Transaction transaction
          Current Transaction this SimpleFeatureSource is opperating against
 
Fields inherited from class AbstractFeatureSource
hints, queryCapabilities
 
Constructor Summary
AbstractFeatureStore()
           
AbstractFeatureStore(Set hints)
          This constructors allows to set the supported hints
 
Method Summary
 List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
          Adds all features from the feature collection.
 Set<String> addFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
          Add Features from reader to this FeatureStore.
 Transaction getTransaction()
          Retrieve the Transaction this SimpleFeatureSource is opperating against.
 void modifyFeatures(AttributeDescriptor[] type, Object[] value, Filter filter)
          Modifies features matching filter.
 void modifyFeatures(AttributeDescriptor type, Object value, Filter filter)
          Modifies features matching filter.
 void modifyFeatures(Name[] attributeNames, Object[] attributeValues, Filter filter)
          Modifies the attributes with the supplied values in all features selected by the given filter.
 void modifyFeatures(Name attributeName, Object attributeValue, Filter filter)
          Modifies an attribute with the supplied value in all features selected by the given filter.
 void modifyFeatures(String[] names, Object[] values, Filter filter)
           
 void modifyFeatures(String name, Object attributeValue, Filter filter)
           
 void removeFeatures(Filter filter)
          Removes features indicated by provided filter.
 void setFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
          Replace with contents of reader.
 void setTransaction(Transaction transaction)
          Provide a transaction for commit/rollback control of a modifying operation on this FeatureStore.
 
Methods inherited from class AbstractFeatureSource
getBounds, getBounds, getCount, getDataStore, getFeatures, getFeatures, getFeatures, getInfo, getName, getQueryCapabilities, getSupportedHints, namedQuery
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface SimpleFeatureStore
getFeatures, getFeatures, getFeatures
 
Methods inherited from interface FeatureSource
addFeatureListener, getBounds, getBounds, getCount, getDataStore, getInfo, getName, getQueryCapabilities, getSchema, getSupportedHints, removeFeatureListener
 

Field Detail

transaction

protected Transaction transaction
Current Transaction this SimpleFeatureSource is opperating against

Constructor Detail

AbstractFeatureStore

public AbstractFeatureStore()

AbstractFeatureStore

public AbstractFeatureStore(Set hints)
This constructors allows to set the supported hints

Parameters:
hints -
Method Detail

getTransaction

public Transaction getTransaction()
Retrieve the Transaction this SimpleFeatureSource is opperating against.

Specified by:
getTransaction in interface FeatureStore<SimpleFeatureType,SimpleFeature>
Overrides:
getTransaction in class AbstractFeatureSource
Returns:
Transaction SimpleFeatureSource is operating against

modifyFeatures

public final void modifyFeatures(AttributeDescriptor type,
                                 Object value,
                                 Filter filter)
                          throws IOException
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<SimpleFeatureType,SimpleFeature>
Parameters:
type - Attribute to modify
value - Modification being made to type
filter - Identifies features to modify
Throws:
IOException - If modification could not be made

modifyFeatures

public void modifyFeatures(Name attributeName,
                           Object attributeValue,
                           Filter filter)
                    throws IOException
Description copied from interface: FeatureStore
Modifies an attribute with the supplied value in all features selected by the given filter.

Specified by:
modifyFeatures in interface FeatureStore<SimpleFeatureType,SimpleFeature>
Parameters:
attributeName - the attribute to modify
attributeValue - the new value for the attribute
filter - an OpenGIS filter
Throws:
IOException - if modification is not supported; if the value type does not match the attribute type; or if there errors accessing the data source

modifyFeatures

public void modifyFeatures(String name,
                           Object attributeValue,
                           Filter filter)
                    throws IOException
Specified by:
modifyFeatures in interface SimpleFeatureStore
Throws:
IOException

modifyFeatures

public void modifyFeatures(String[] names,
                           Object[] values,
                           Filter filter)
                    throws IOException
Specified by:
modifyFeatures in interface SimpleFeatureStore
Throws:
IOException

modifyFeatures

public final void modifyFeatures(AttributeDescriptor[] type,
                                 Object[] value,
                                 Filter filter)
                          throws IOException
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<SimpleFeatureType,SimpleFeature>
Parameters:
type - Attributes to modify
value - Modifications being made to type
filter - Identifies features to modify
Throws:
IOException - If we could not modify Feature
DataSourceException - See IOException

modifyFeatures

public void modifyFeatures(Name[] attributeNames,
                           Object[] attributeValues,
                           Filter filter)
                    throws IOException
Description copied from interface: FeatureStore
Modifies the attributes with the supplied values in all features selected by the given filter.

Specified by:
modifyFeatures in interface FeatureStore<SimpleFeatureType,SimpleFeature>
Parameters:
attributeNames - the attributes to modify
attributeValues - the new values for the attributes
filter - an OpenGIS filter
Throws:
IOException - if the attribute and object arrays are not equal in length; if the value types do not match the attribute types; if modification is not supported; or if there errors accessing the data source

addFeatures

public Set<String> addFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
                        throws IOException
Add Features from reader to this FeatureStore.

Equivelent to:


 Set set = new HashSet();
 FeatureWriter writer = dataStore.getFeatureWriter( typeName, true, transaction );
 Featrue feature, newFeature;
 while( reader.hasNext() ){
    feature = reader.next();
    newFeature = writer.next();
    newFeature.setAttributes( feature.getAttribtues( null ) );
    writer.write();
    set.add( newfeature.getID() );
 }
 reader.close();
 writer.close();
 
 return set;
 
 

(If you don't have a FeatureReader handy DataUtilities.reader() may be able to help out)

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

Parameters:
reader -
Returns:
The Set of FeatureIDs added
Throws:
IOException - If we encounter a problem encounter writing content
DataSourceException - See IOException
See Also:
org.geotools.data.FeatureStore#addFeatures(org.geotools.data.FeatureReader)

addFeatures

public List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
                            throws IOException
Description copied from interface: FeatureStore
Adds all features from the feature collection.

A list of FeatureIds is returned, one for each feature in the order created. However, these might not be assigned until after a commit has been performed.

Specified by:
addFeatures in interface FeatureStore<SimpleFeatureType,SimpleFeature>
Parameters:
collection - the collection of features to add
Returns:
the FeatureIds of the newly added features
Throws:
IOException - if an error occurs modifying the data source

removeFeatures

public void removeFeatures(Filter filter)
                    throws IOException
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<SimpleFeatureType,SimpleFeature>
Parameters:
filter - Identifies features to remove
Throws:
IOException

setFeatures

public void setFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
                 throws IOException
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<SimpleFeatureType,SimpleFeature>
Parameters:
reader - Contents to replace with
Throws:
IOException - if anything goes wrong during replacement
DataSourceException - See IOException

setTransaction

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

 Transation t = new DefaultTransaction();
 featureStore.setTransaction(t);
 try {
     featureStore.addFeatures( someFeatures );
     t.commit();
 } catch ( IOException ex ) {
     // something went wrong;
     ex.printStackTrace();
     t.rollback();
 } finally {
     t.close();
 }
 

Specified by:
setTransaction in interface FeatureStore<SimpleFeatureType,SimpleFeature>
Parameters:
transaction - the transaction


Copyright © 1996-2014 Geotools. All Rights Reserved.