org.geotools.data
Class AbstractDataStore

Object
  extended by AbstractDataStore
All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>, DataStore
Direct Known Subclasses:
AbstractFileDataStore, ArrayDataStore, CollectionDataStore, MemoryDataStore, PropertyDataStore, WFS_1_0_0_DataStore

public abstract class AbstractDataStore
extends 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:

and optionally this protected methods to allow custom query optimizations:

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 SimpleFeatureSource implementation
protected static Logger LOGGER
          The logger for the filter module.
 
Constructor Summary
AbstractDataStore()
          Default (Writeable) DataStore
AbstractDataStore(boolean isWriteable)
          AbstractDataStore creation.
 
Method Summary
protected  FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName, Transaction transaction)
          Subclass should implement this to provide writing support.
protected  InProcessLockingManager createLockingManager()
          Currently returns an InProcessLockingManager.
protected  Map createMetadata(String typeName)
          Subclass override to provide access to metadata.
 void createSchema(SimpleFeatureType featureType)
          Subclass should implement to provide writing support.
 void dispose()
          Dummy implementation, it's a no-op.
protected  ReferencedEnvelope getBounds(Query query)
          Computes the bounds of the features for the specified feature type that satisfy the query provided that there is a fast way to get that result.
protected  int getCount(Query query)
          Gets the number of the features that would be returned by this query for the specified feature type.
 FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(Query query, Transaction transaction)
          Gets a FeatureReader for features selected by the given Query.
protected abstract  FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName)
          Subclass must implement.
protected  FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName, Query query)
          GR: this method is called from inside getFeatureReader(Query ,Transaction ) to allow subclasses return an optimized FeatureReader wich supports the filter and attributes truncation specified in query A subclass that supports the creation of such an optimized FeatureReader shold override this method.
 SimpleFeatureSource getFeatureSource(Name typeName)
          Delegates to getFeatureSource(String) with name.getLocalPart()
 SimpleFeatureSource getFeatureSource(String typeName)
          Default implementation based on getFeatureReader and getFeatureWriter.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName, Filter filter, Transaction transaction)
          Gets a FeatureWriter to modify features in this DataStore.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName, Transaction transaction)
          Gets a FeatureWriter to modify features in this DataStore.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName, Transaction transaction)
          Gets a FeatureWriter that can add new features to the DataStore.
 ServiceInfo getInfo()
          Information about this service.
 LockingManager getLockingManager()
          Locking manager used for this DataStore.
 List<Name> getNames()
          Returns the same list of names than getTypeNames() meaning the returned Names have no namespace set.
 SimpleFeatureType getSchema(Name name)
          Delegates to getSchema(String) with name.getLocalPart()
abstract  SimpleFeatureType getSchema(String typeName)
          Retrive schema information for typeName
protected  Set getSupportedHints()
          If you are using the automated FeatureSource/Store/Locking creation, this method allows for the specification of the supported hints.
abstract  String[] getTypeNames()
          helper method for retrieving all the names.
protected  Filter getUnsupportedFilter(String typeName, Filter filter)
          GR: if a subclass supports filtering, it should override this method to return the unsupported part of the passed filter, so a FilteringFeatureReader will be constructed upon it.
 void removeSchema(Name typeName)
          Used to permanently remove a schema from the underlying storage This functionality is similar to an "drop table" statement in SQL.
 void removeSchema(String typeName)
          Used to permanently remove a schema from the underlying storage This functionality is similar to an "drop table" statement in SQL.
protected  TransactionStateDiff state(Transaction transaction)
          Used to retrive the TransactionStateDiff for this transaction.
 void updateSchema(Name typeName, SimpleFeatureType featureType)
          Delegates to updateSchema(String, SimpleFeatureType) with name.getLocalPart()
 void updateSchema(String typeName, SimpleFeatureType featureType)
          Applies a new schema to the given feature type.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final Logger LOGGER
The logger for the filter module.


listenerManager

public FeatureListenerManager listenerManager
Manages listener lists for SimpleFeatureSource 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()
Default (Writeable) DataStore


AbstractDataStore

public AbstractDataStore(boolean isWriteable)
AbstractDataStore creation.

Parameters:
isWriteable - true for writable DataStore.
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.

createMetadata

protected Map createMetadata(String typeName)
Subclass override to provide access to metadata.

CreateTypeEntry uses this method to aquire metadata information, if available.


getTypeNames

public abstract String[] getTypeNames()
                               throws IOException
helper method for retrieving all the names.

Specified by:
getTypeNames in interface DataStore
Returns:
names of feature types available in this DataStore
Throws:
IOException - if data access errors occur

getInfo

public ServiceInfo getInfo()
Description copied from interface: DataAccess
Information about this service.

This method offers access to a summary of header or metadata information describing the service.

Subclasses may return a specific ServiceInfo instance that has additional information (such as FilterCapabilities).

Specified by:
getInfo in interface DataAccess<SimpleFeatureType,SimpleFeature>
Returns:
SeviceInfo

getSchema

public abstract SimpleFeatureType getSchema(String typeName)
                                     throws IOException
Retrive schema information for typeName

Specified by:
getSchema in interface DataStore
Parameters:
typeName - the feature type name
Returns:
the requested feature type
Throws:
IOException - if typeName is not available

getFeatureReader

protected abstract FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName)
                                                                            throws IOException
Subclass must implement.

Parameters:
typeName -
Returns:
FeatureReader over contents of typeName
Throws:
IOException

createFeatureWriter

protected FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName,
                                                                             Transaction transaction)
                                                                      throws IOException
Subclass should implement this to provide writing support.

A feature writer writes to the resource so it should considered to always be committing. The transaction is passed in so that it can be known what FeatureListeners should be notified of the changes. If the Transaction is AUTOCOMMIT then all listeners should be notified. If not all listeners that are NOT registered with that transaction should be notified.

Parameters:
typeName -
transaction - a feature writer
Returns:
FeatureWriter over contents of typeName
Throws:
IOException
IOException - Subclass may throw IOException
UnsupportedOperationException - Subclass may implement

createSchema

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

Specified by:
createSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Parameters:
featureType - Requested FeatureType
Throws:
IOException
IOException - Subclass may throw IOException
UnsupportedOperationException - Subclass may implement

updateSchema

public void updateSchema(String typeName,
                         SimpleFeatureType featureType)
Description copied from interface: DataStore
Applies a new schema to the given feature type. This can be used to add or remove properties. The resulting update will be persistent.

Specified by:
updateSchema in interface DataStore
Parameters:
typeName - name of the feature type to update
featureType - the new schema to apply

getFeatureSource

public SimpleFeatureSource getFeatureSource(String typeName)
                                     throws 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 - the feature type
Returns:
a SimpleFeatureSource (or possibly a subclass) providing operations for features of the specified type
Throws:
IOException - if data access errors occur
See Also:
DataStore.getFeatureSource(java.lang.String)

getFeatureReader

public FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(Query query,
                                                                       Transaction transaction)
                                                                throws IOException
Description copied from interface: DataStore
Gets a FeatureReader for features selected by the given Query. FeatureReader provies an iterator-style API to feature data.

The Query provides the schema for the form of the returned features as well as a Filter to constrain the features available via the reader.

The Transaction can be used to externalize the state of the DataStore. Examples of this include a JDBCDataStore sharing a connection for use across several FeatureReader requests; and a ShapefileDataStore redirecting requests to an alternate file during the course of a Transaction.

Specified by:
getFeatureReader in interface DataStore
Parameters:
query - a query providing the schema and constraints for features that the reader will return
transaction - a transaction that this reader will operate against
Returns:
an instance of FeatureReader
Throws:
IOException - if data access errors occur

getFeatureReader

protected FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName,
                                                                          Query query)
                                                                   throws IOException
GR: this method is called from inside getFeatureReader(Query ,Transaction ) to allow subclasses return an optimized FeatureReader wich supports the filter and attributes truncation specified in query

A subclass that supports the creation of such an optimized FeatureReader shold override this method. Otherwise, it just returns getFeatureReader(typeName)

Throws:
IOException

getUnsupportedFilter

protected Filter getUnsupportedFilter(String typeName,
                                      Filter filter)
GR: if a subclass supports filtering, it should override this method to return the unsupported part of the passed filter, so a FilteringFeatureReader will be constructed upon it. Otherwise it will just return the same filter.

If the complete filter is supported, the subclass must return Filter.INCLUDE


state

protected TransactionStateDiff state(Transaction transaction)
Used to retrive the TransactionStateDiff for this transaction. If you subclass is doing its own thing (ArcSDE I am talking to you) then you should arrange for this method to return null.

By default a TransactionStateDiff will be created that holds any changes in memory.

Parameters:
transaction -
Returns:
TransactionStateDiff or null if subclass is handling differences

getFeatureWriter

public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName,
                                                                       Filter filter,
                                                                       Transaction transaction)
                                                                throws IOException
Description copied from interface: DataStore
Gets a FeatureWriter to modify features in this DataStore. FeatureWriter provides an iterator style API to features.

The returned writer does not allow features to be added.

Specified by:
getFeatureWriter in interface DataStore
Parameters:
typeName - the type name for features that will be accessible
filter - defines additional constraints on the features that will be accessible
transaction - the transation that the returned writer operates against
Returns:
an instance of FeatureWriter
Throws:
IOException - if data access errors occur
See Also:
DataStore.getFeatureWriterAppend(String, Transaction)

getFeatureWriter

public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName,
                                                                       Transaction transaction)
                                                                throws IOException
Description copied from interface: DataStore
Gets a FeatureWriter to modify features in this DataStore. FeatureWriter provides an iterator style API to features.

The returned writer does not allow features to be added.

Specified by:
getFeatureWriter in interface DataStore
Parameters:
typeName - the type name for features that will be accessible
transaction - the transation that the returned writer operates against
Returns:
an instance of FeatureWriter
Throws:
IOException - if data access errors occur
See Also:
DataStore.getFeatureWriterAppend(String, Transaction)

getFeatureWriterAppend

public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName,
                                                                             Transaction transaction)
                                                                      throws IOException
Description copied from interface: DataStore
Gets a FeatureWriter that can add new features to the DataStore.

The FeatureWriter will return false when its hasNext() method is called, but next() can be used to acquire new features.

Specified by:
getFeatureWriterAppend in interface DataStore
Parameters:
typeName - name of the feature type for which features will be added
transaction - the transaction to operate against
Returns:
an instance of FeatureWriter that can only be used to append new features
Throws:
IOException - if data access errors occur

getLockingManager

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

By default AbstractDataStore makes use of InProcessLockingManager.

Specified by:
getLockingManager in interface DataStore
Returns:
an instance of LockingManager; or null if locking is handled by the DataStore in a different fashion
See Also:
DataStore.getLockingManager()

getBounds

protected ReferencedEnvelope getBounds(Query query)
                                throws IOException
Computes the bounds of the features for the specified feature type that satisfy the query provided that there is a fast way to get that result.

Will return null if there is not fast way to compute the bounds. Since it's based on some kind of header/cached information, it's not guaranteed to be real bound of the features

Parameters:
query -
Returns:
the bounds, or null if too expensive
Throws:
SchemaNotFoundException
IOException

getCount

protected int getCount(Query query)
                throws IOException
Gets the number of the features that would be returned by this query for the specified feature type.

If getBounds(Query) returns -1 due to expense consider using getFeatures(Query).getCount() as a an alternative.

Parameters:
query - Contains the Filter and MaxFeatures to find the bounds for.
Returns:
The number of Features provided by the Query or -1 if count is too expensive to calculate or any errors or occur.
Throws:
IOException
IOException - if there are errors getting the count

getSupportedHints

protected Set getSupportedHints()
If you are using the automated FeatureSource/Store/Locking creation, this method allows for the specification of the supported hints.

Returns:

dispose

public void dispose()
Dummy implementation, it's a no-op. Subclasses holding to system resources must override this method and release them.

Specified by:
dispose in interface DataAccess<SimpleFeatureType,SimpleFeature>

getFeatureSource

public SimpleFeatureSource getFeatureSource(Name typeName)
                                     throws IOException
Delegates to getFeatureSource(String) with name.getLocalPart()

Specified by:
getFeatureSource in interface DataAccess<SimpleFeatureType,SimpleFeature>
Specified by:
getFeatureSource in interface DataStore
Parameters:
typeName - the qualified name of the feature type
Returns:
a SimpleFeatureSource (or possibly a subclass) providing operations for features of the specified type
Throws:
IOException - if data access errors occur
Since:
2.5
See Also:
DataAccess.getFeatureSource(Name)

getNames

public List<Name> getNames()
                    throws IOException
Returns the same list of names than getTypeNames() meaning the returned Names have no namespace set.

Specified by:
getNames in interface DataAccess<SimpleFeatureType,SimpleFeature>
Returns:
Names of the available contents.
Throws:
IOException
Since:
2.5
See Also:
DataAccess.getNames()

getSchema

public SimpleFeatureType getSchema(Name name)
                            throws IOException
Delegates to getSchema(String) with name.getLocalPart()

Specified by:
getSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Parameters:
name - Type name a the resource from getNames()
Returns:
Description of the FeatureType being made avaialble
Throws:
IOException
Since:
2.5
See Also:
DataAccess.getSchema(Name)

updateSchema

public void updateSchema(Name typeName,
                         SimpleFeatureType featureType)
                  throws IOException
Delegates to updateSchema(String, SimpleFeatureType) with name.getLocalPart()

Specified by:
updateSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Throws:
IOException - if the operation failed
Since:
2.5
See Also:
DataAccess.getFeatureSource(Name)

removeSchema

public void removeSchema(Name typeName)
                  throws IOException
Description copied from interface: DataAccess
Used to permanently remove a schema from the underlying storage

This functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.

Specified by:
removeSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Throws:
IOException - if the operation failed
See Also:
DataAccess.removeSchema(Name)

removeSchema

public void removeSchema(String typeName)
                  throws IOException
Description copied from interface: DataStore
Used to permanently remove a schema from the underlying storage

This functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.

Specified by:
removeSchema in interface DataStore
Throws:
IOException - if the operation failed
See Also:
DataStore.removeSchema(String)


Copyright © 1996-2014 Geotools. All Rights Reserved.