org.geotools.data
Class AbstractDataStore

java.lang.Object
  extended byorg.geotools.data.AbstractDataStore
All Implemented Interfaces:
DataStore
Direct Known Subclasses:
MemoryDataStore

public abstract class AbstractDataStore
extends java.lang.Object
implements DataStore

Represents a stating point for implementing your own DataStore.

The goal is to have this class provide everything else if you can only provide:

All remaining functionality is implemented against these methods, including Transaction and Locking Support. These implementations will not be optimal but they will work.

Pleae note that there may be a better place for you to start out from, (like JDBCDataStore).

Author:
jgarnett

Field Summary
protected  boolean isWriteable
          Flags AbstractDataStore to allow Modification.
 FeatureListenerManager listenerManager
          Manages listener lists for FeatureSource implementation
 
Constructor Summary
AbstractDataStore()
           
AbstractDataStore(boolean isWriteable)
           
 
Method Summary
protected  InProcessLockingManager createLockingManager()
          Currently returns an InProcessLockingManager.
 void createSchema(FeatureType featureType)
          Subclass should implement to provide writing support.
 void fireAdded(Feature newFeature)
           
 void fireChanged(Feature before, Feature after)
           
 void fireRemoved(Feature removedFeature)
           
 FeatureReader getFeatureReader(FeatureType featureType, Filter filter, Transaction transaction)
          Access a FeatureReader providing access to Feature information.
 FeatureReader getFeatureReader(Query query, Transaction transaction)
           
protected abstract  FeatureReader getFeatureReader(java.lang.String typeName)
          Subclass must implement.
 FeatureSource getFeatureSource(java.lang.String typeName)
          Default implementation based on getFeatureReader and getFeatureWriter.
protected  FeatureWriter getFeatureWriter(java.lang.String typeName)
          Subclass should implement this to provide writing support.
 FeatureWriter getFeatureWriter(java.lang.String typeName, Filter filter, Transaction transaction)
          Access FeatureWriter for modification of the DataStore contents.
 FeatureWriter getFeatureWriter(java.lang.String typeName, Transaction transaction)
          Access FeatureWriter for modification of the DataStore typeName.
 FeatureWriter getFeatureWriterAppend(java.lang.String typeName, Transaction transaction)
          Aquire a FeatureWriter for adding new content to a FeatureType.
 LockingManager getLockingManager()
          Locking manager used for this DataStore.
abstract  FeatureType getSchema(java.lang.String typeName)
          Retrieve FeatureType metadata by typeName.
abstract  java.lang.String[] getTypeNames()
          Retrieves a list of of the available FeatureTypes
 FeatureSource getView(Query query)
           
 void updateSchema(java.lang.String typeName, FeatureType featureType)
          Used to force namespace and CS info into a persistent change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerManager

public FeatureListenerManager listenerManager
Manages listener lists for FeatureSource implementation


isWriteable

protected final boolean isWriteable
Flags AbstractDataStore to allow Modification.

GetFeatureSource will return a FeatureStore is this is true.

Constructor Detail

AbstractDataStore

public AbstractDataStore()

AbstractDataStore

public AbstractDataStore(boolean isWriteable)
Method Detail

createLockingManager

protected InProcessLockingManager createLockingManager()
Currently returns an InProcessLockingManager.

Subclasses that implement real locking may override this method to return null.

Returns:
InProcessLockingManager or null.

fireAdded

public void fireAdded(Feature newFeature)

fireRemoved

public void fireRemoved(Feature removedFeature)

fireChanged

public void fireChanged(Feature before,
                        Feature after)

getTypeNames

public abstract java.lang.String[] getTypeNames()
Description copied from interface: DataStore
Retrieves a list of of the available FeatureTypes

This is simply a list of the FeatureType names as aquiring the actual FeatureType schemas may be expensive.

Specified by:
getTypeNames in interface DataStore
Returns:
typeNames for available FeatureTypes.

getSchema

public abstract FeatureType getSchema(java.lang.String typeName)
                               throws java.io.IOException
Description copied from interface: DataStore
Retrieve FeatureType metadata by typeName.

Retrieves the Schema information as a FeatureType object.

Specified by:
getSchema in interface DataStore
Parameters:
typeName - typeName of requested FeatureType
Returns:
FeatureType for the provided typeName
Throws:
java.io.IOException - If typeName cannot be found

getFeatureReader

protected abstract FeatureReader getFeatureReader(java.lang.String typeName)
                                           throws java.io.IOException
Subclass must implement.

Parameters:
typeName -
Returns:
FeatureReader over contents of typeName
Throws:
java.io.IOException

getFeatureWriter

protected FeatureWriter getFeatureWriter(java.lang.String typeName)
                                  throws java.io.IOException
Subclass should implement this to provide writing support.

Parameters:
typeName -
Returns:
FeatureWriter over contents of typeName
Throws:
java.io.IOException - Subclass may throw IOException
java.lang.UnsupportedOperationException - Subclass may implement

createSchema

public void createSchema(FeatureType featureType)
                  throws java.io.IOException
Subclass should implement to provide writing support.

Specified by:
createSchema in interface DataStore
Parameters:
featureType - Requested FeatureType
Throws:
java.io.IOException - Subclass may throw IOException
java.lang.UnsupportedOperationException - Subclass may implement

updateSchema

public void updateSchema(java.lang.String typeName,
                         FeatureType featureType)
                  throws java.io.IOException
Description copied from interface: DataStore
Used to force namespace and CS info into a persistent change.

The provided featureType should completely cover the existing schema. All attributes should be accounted for and the typeName should match.

Suggestions:

Specified by:
updateSchema in interface DataStore
Parameters:
typeName -
Throws:
java.io.IOException

getView

public FeatureSource getView(Query query)
                      throws java.io.IOException,
                             SchemaException
Throws:
java.io.IOException
SchemaException

getFeatureSource

public FeatureSource getFeatureSource(java.lang.String typeName)
                               throws java.io.IOException
Default implementation based on getFeatureReader and getFeatureWriter.

We should be able to optimize this to only get the RowSet once

Specified by:
getFeatureSource in interface DataStore
Parameters:
typeName -
Returns:
FeatureSource (or subclass) providing opperations for typeName
Throws:
java.io.IOException
See Also:
DataStore.getFeatureSource(java.lang.String)

getFeatureReader

public FeatureReader getFeatureReader(Query query,
                                      Transaction transaction)
                               throws java.io.IOException,
                                      SchemaException
Throws:
java.io.IOException
SchemaException

getFeatureReader

public FeatureReader getFeatureReader(FeatureType featureType,
                                      Filter filter,
                                      Transaction transaction)
                               throws java.io.IOException
Description copied from interface: DataStore
Access a FeatureReader providing access to Feature information.

Filter is used as a low-level indication of constraints. (Implementations may resort to using a FilteredFeatureReader, or provide their own optimizations)

FeatureType provides a template for the returned FeatureReader

Transaction to externalize DataStore state on a per Transaction basis. The most common example is a JDBC datastore saving a Connection for use across several FeatureReader requests. Similarly a Shapefile reader may wish to redirect FeatureReader requests to a alternate filename over the course of a Transaction.

Notes For Implementing DataStore

Subclasses may need to retrieve additional attributes, beyond those requested by featureType.getAttributeTypes(), in order to correctly apply the filter.
These Additional attribtues should be not be returned by FeatureReader. Subclasses may use ReTypeFeatureReader to aid in acomplishing this.

Helper classes for implementing a FeatureReader (in order):

Sample use (not optimized):


 if (filter == Filter.ALL) {
      return new EmptyFeatureReader(featureType);
  }

  String typeName = featureType.getTypeName();
  FeatureType schema = getSchema( typeName );
  FeatureReader reader = new DefaultFeatureReader( getAttributeReaders(), schema );

  if (filter != Filter.NONE) {
      reader = new FilteringFeatureReader(reader, filter);
  }

  if (transaction != Transaction.AUTO_COMMIT) {
      Map diff = state(transaction).diff(typeName);
      reader = new DiffFeatureReader(reader, diff);
  }

  if (!featureType.equals(reader.getFeatureType())) {
      reader = new ReTypeFeatureReader(reader, featureType);
  }
 return reader
 

Locking support does not need to be provided for FeatureReaders.

Suggestions:

Specified by:
getFeatureReader in interface DataStore
Parameters:
featureType - Describes the form of the returned Features
filter - Constraints used to limit the results
transaction - Transaction this query opperates against
Returns:
FeatureReader Allows Sequential Processing of featureType
Throws:
java.io.IOException
See Also:
DataStore.getFeatureReader(org.geotools.feature.FeatureType, org.geotools.filter.Filter, org.geotools.data.Transaction)

getFeatureWriter

public FeatureWriter getFeatureWriter(java.lang.String typeName,
                                      Filter filter,
                                      Transaction transaction)
                               throws java.io.IOException
Description copied from interface: DataStore
Access FeatureWriter for modification of the DataStore contents.

The constructed FeatureWriter will be placed at the start of the provided store.

To limit FeatureWriter to the FeatureTypes defined by this DataStore, typeName is used to indicate FeatureType. The resulting feature writer will allow modifications against the same FeatureType provided by getSchema( typeName )

Notes For Implementing DataStore

The returned FeatureWriter does not support the addition on new Features to FeatureType (it would need to police your modifications to agree with filer). As such it will return false for getNext() when it reaches the end of the Query and NoSuchElementException when next() is called.

Helper classes for implementing a FeatureWriter (in order):

  • InProcessLockingManager.checkedWriter( writer ) - provides a check against locks before allowing modification
  • FilteringFeatureWriter - filtering support for FeatureWriter (does not allow new content)
  • DiffFeatureWriter - In-Process Transaction Support (see TransactionStateDiff)
  • EmptyFeatureWriter - provides no content for Filter.ALL optimizations
  • Specified by:
    getFeatureWriter in interface DataStore
    Parameters:
    typeName - Indicates featureType to be modified
    filter - constraints used to limit the modification
    transaction - Transaction this query opperates against
    Returns:
    FeatureWriter Allows Sequential Modification of featureType
    Throws:
    java.io.IOException

    getFeatureWriter

    public FeatureWriter getFeatureWriter(java.lang.String typeName,
                                          Transaction transaction)
                                   throws java.io.IOException
    Description copied from interface: DataStore
    Access FeatureWriter for modification of the DataStore typeName.

    FeatureWriters will need to be limited to the FeatureTypes defined by the DataStore, the easiest way to express this limitation is to the FeatureType by a provided typeName.

    The returned FeatureWriter will return false for getNext() when it reaches the end of the Query.

    Specified by:
    getFeatureWriter in interface DataStore
    Parameters:
    typeName - Indicates featureType to be modified
    transaction - Transaction this query opperates against
    Returns:
    FeatureReader Allows Sequential Processing of featureType
    Throws:
    java.io.IOException

    getFeatureWriterAppend

    public FeatureWriter getFeatureWriterAppend(java.lang.String typeName,
                                                Transaction transaction)
                                         throws java.io.IOException
    Description copied from interface: DataStore
    Aquire a FeatureWriter for adding new content to a FeatureType.

    This FeatureWriter will return false for hasNext(), however next() may be used to aquire new Features that may be writen out to add new content.

    Specified by:
    getFeatureWriterAppend in interface DataStore
    Parameters:
    typeName -
    transaction -
    Returns:
    Throws:
    java.io.IOException

    getLockingManager

    public LockingManager getLockingManager()
    Locking manager used for this DataStore.

    By default AbstractDataStore makes use of InProcessLockingManager.

    Specified by:
    getLockingManager in interface DataStore
    Returns:
    See Also:
    DataStore.getLockingManager()


    Copyright © 1996-2003 GeoTools. All Rights Reserved.