org.geotools.data
Class AbstractFeatureStore

java.lang.Object
  extended byorg.geotools.data.AbstractFeatureSource
      extended byorg.geotools.data.AbstractFeatureStore
All Implemented Interfaces:
FeatureSource, FeatureStore
Direct Known Subclasses:
AbstractFeatureLocking

public abstract class AbstractFeatureStore
extends AbstractFeatureSource
implements FeatureStore

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

Author:
Jody Garnett, Refractions Research

Field Summary
protected  Transaction transaction
          Current Transaction this FeatureSource is opperating against
 
Constructor Summary
AbstractFeatureStore()
           
 
Method Summary
 java.util.Set addFeatures(FeatureReader reader)
          Add Features from reader to this FeatureStore.
 Transaction getTransaction()
          Retrieve the Transaction this FeatureSource is opperating against.
 void modifyFeatures(AttributeType[] type, java.lang.Object[] value, Filter filter)
          Modifies features matching filter.
 void modifyFeatures(AttributeType type, java.lang.Object value, Filter filter)
          Modifies features matching filter.
 void removeFeatures(Filter filter)
          Removes features indicated by provided filter.
 void setFeatures(FeatureReader 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.AbstractFeatureSource
getBounds, getBounds, getCount, getFeatures, getFeatures, getFeatures, 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
addFeatureListener, getBounds, getBounds, getCount, getDataStore, getFeatures, getFeatures, getFeatures, getSchema, removeFeatureListener
 

Field Detail

transaction

protected Transaction transaction
Current Transaction this FeatureSource is opperating against

Constructor Detail

AbstractFeatureStore

public AbstractFeatureStore()
Method Detail

getTransaction

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

Specified by:
getTransaction in interface FeatureStore
Overrides:
getTransaction in class AbstractFeatureSource
Returns:
Transaction FeatureSource is operating against

modifyFeatures

public void modifyFeatures(AttributeType type,
                           java.lang.Object value,
                           Filter filter)
                    throws java.io.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
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
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

modifyFeatures

public void modifyFeatures(AttributeType[] type,
                           java.lang.Object[] value,
                           Filter filter)
                    throws java.io.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
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
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

addFeatures

public java.util.Set addFeatures(FeatureReader reader)
                          throws java.io.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.

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

removeFeatures

public void removeFeatures(Filter filter)
                    throws java.io.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
Parameters:
filter - Identifies features to remove
Throws:
java.io.IOException
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

setFeatures

public void setFeatures(FeatureReader reader)
                 throws java.io.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
Parameters:
reader - Contents to replace with
Throws:
java.io.IOException - if anything goes wrong during replacement
DataSourceException - See IOException
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

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
Parameters:
transaction - DOCUMENT ME!


Copyright © GeoTools. All Rights Reserved.