org.geotools.data.store
Class ContentDataStore

Object
  extended by ContentDataStore
All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>, DataStore

public abstract class ContentDataStore
extends Object
implements DataStore

Abstract base class for data stores.

A datastore contains a set of entries (ContentEntry). Each entry corresponds to a "real world dataset". For instance, a shapefile datastore would contain a single entry which would represent the shapefile on disk. A postgis datastore could contain many entries, one for each table in the database.

Each entry is identified by a name (Name). The name can be qualified with a namespace uri, or unqualified (in which the namespace uri is null). An example of a datastore that might use qualified names is WFS, where in each entry corresponds to a WFS "Feature Type", which have namespace qualified name. Other datastores (such as databases) use unqualified names.

When entry names of a datastore are unqualified, a default namespace uri can be set "globally" on the datastore itself, see setNamespaceURI(String). When this value is set, unqualified entry names are implicitly qualified with the global namespace uri.

Subclasses

At a minimum subclasses must implement the following methods:

The following methods may also be overriden: The following methods may be overriden but only to narrow the return type to a specific subclass of ContentFeatureSource.

Author:
Jody Garnett, Refractions Research Inc., Justin Deoliveira, The Open Planning Project

Field Summary
protected  Map<Name,ContentEntry> entries
          name, entry map
protected  FeatureFactory featureFactory
          Factory used to create features
protected  FilterFactory filterFactory
          Factory used to create filters
protected  GeometryFactory geometryFactory
          Factory used to create geometries
protected  LockingManager lockingManager
          locking manager
protected  Logger LOGGER
          logger
protected  String namespaceURI
          namespace uri of the datastore itself, or default namespace
protected  FeatureTypeFactory typeFactory
          Factory used to create feature types
protected static int WRITER_ADD
          writer flags
protected static int WRITER_UPDATE
           
 
Constructor Summary
ContentDataStore()
           
 
Method Summary
protected  ContentState createContentState(ContentEntry entry)
          Instantiates a new content state for the entry.
protected abstract  ContentFeatureSource createFeatureSource(ContentEntry entry)
          Instantiates new feature source for the entry.
 void createSchema(SimpleFeatureType featureType)
          Creates a new schema in the datastore.
protected abstract  List<Name> createTypeNames()
          Creates a set of qualified names corresponding to the types that the datastore provides.
 void dispose()
          Disposes of this data store and releases any resource that it is using.
protected  ContentEntry ensureEntry(Name name)
          Helper method to look up an entry in the datastore which throws an IOException in the event that the entry does not exist.
protected  ContentFeatureStore ensureFeatureStore(String typeName, Transaction tx)
          Helper method which gets a feature source ensuring that it is a feature store as well.
protected  ContentEntry entry(Name name)
          Helper method to look up an entry in the datastore.
 ContentEntry getEntry(Name name)
          Returns the entry for a specified name, or null if no such entry exists.
 FeatureFactory getFeatureFactory()
          The factory used to create features.
 FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(Query query, Transaction tx)
          Returns a feature reader for the specified query and transaction.
 FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource(Name typeName)
          Delegates to getFeatureSource(String) with name.getLocalPart()
 ContentFeatureSource getFeatureSource(Name typeName, Transaction tx)
          Returns the feature source matching the specified name and explicitly specifies a transaction.
 ContentFeatureSource getFeatureSource(String typeName)
          Returns the feature source matching the specified name.
 ContentFeatureSource getFeatureSource(String typeName, Transaction tx)
          Returns the feature source matching the specified name and explicitly specifies a transaction.
 FeatureTypeFactory getFeatureTypeFactory()
          The factory used to create feature types.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName, Filter filter, Transaction tx)
          Returns a feature writer for the specified query and transaction.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName, Transaction tx)
          Returns a feature writer for the specified type name and transaction.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName, Transaction tx)
          Returns an appending feature writer for the specified type name and transaction.
 FilterFactory getFilterFactory()
          The factory used to create filters.
 GeometryFactory getGeometryFactory()
          The factory used to create geometries.
 ServiceInfo getInfo()
          Information about this service.
 LockingManager getLockingManager()
          Retrieve a per featureID based locking service from this DataStore.
 Logger getLogger()
          The logger for the datastore.
 List<Name> getNames()
          Returns the same list of names than getTypeNames() meaning the returned Names have no namespace set.
 String getNamespaceURI()
          The namespace uri of the datastore.
 SimpleFeatureType getSchema(Name name)
          Delegates to getSchema(String) with name.getLocalPart()
 SimpleFeatureType getSchema(String typeName)
          Returns the feature type or schema matching the specified name.
 String[] getTypeNames()
          Returns the names of all entries or types provided by the datastore.
 FeatureSource<SimpleFeatureType,SimpleFeature> getView(Query query)
          Access a FeatureSource for Query providing a high-level API.
protected  Name name(String typeName)
          Helper method to wrap a non-qualified name.
 void setFeatureFactory(FeatureFactory featureFactory)
          Sets the factory used to create features.
 void setFeatureTypeFactory(FeatureTypeFactory typeFactory)
          Sets the factory used to create feature types.
 void setFilterFactory(FilterFactory filterFactory)
          Sets the factory used to create filters.
 void setGeometryFactory(GeometryFactory geometryFactory)
          Sets the factory used to create geometries.
 void setNamespaceURI(String namespaceURI)
          Sets the namespace uri of the datastore.
 void updateSchema(Name typeName, SimpleFeatureType featureType)
          Delegates to updateSchema(String, SimpleFeatureType) with name.getLocalPart()
 void updateSchema(String typeName, SimpleFeatureType featureType)
          Used to force namespace and CS info into a persistent change.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WRITER_ADD

protected static final int WRITER_ADD
writer flags

See Also:
Constant Field Values

WRITER_UPDATE

protected static final int WRITER_UPDATE
See Also:
Constant Field Values

entries

protected final Map<Name,ContentEntry> entries
name, entry map


LOGGER

protected final Logger LOGGER
logger


typeFactory

protected FeatureTypeFactory typeFactory
Factory used to create feature types


featureFactory

protected FeatureFactory featureFactory
Factory used to create features


filterFactory

protected FilterFactory filterFactory
Factory used to create filters


geometryFactory

protected GeometryFactory geometryFactory
Factory used to create geometries


namespaceURI

protected String namespaceURI
namespace uri of the datastore itself, or default namespace


lockingManager

protected LockingManager lockingManager
locking manager

Constructor Detail

ContentDataStore

public ContentDataStore()
Method Detail

getFeatureTypeFactory

public FeatureTypeFactory getFeatureTypeFactory()
The factory used to create feature types.


setFeatureTypeFactory

public void setFeatureTypeFactory(FeatureTypeFactory typeFactory)
Sets the factory used to create feature types.


setFeatureFactory

public void setFeatureFactory(FeatureFactory featureFactory)
Sets the factory used to create features.


getFilterFactory

public FilterFactory getFilterFactory()
The factory used to create filters.


getFeatureFactory

public FeatureFactory getFeatureFactory()
The factory used to create features.


setFilterFactory

public void setFilterFactory(FilterFactory filterFactory)
Sets the factory used to create filters.


getGeometryFactory

public GeometryFactory getGeometryFactory()
The factory used to create geometries.


setGeometryFactory

public void setGeometryFactory(GeometryFactory geometryFactory)
Sets the factory used to create geometries.


getNamespaceURI

public String getNamespaceURI()
The namespace uri of the datastore.

Returns:
The namespace uri, may be null.

setNamespaceURI

public void setNamespaceURI(String namespaceURI)
Sets the namespace uri of the datastore.

This will be used to qualify the entries or types of the datastore.

Parameters:
namespaceURI - The namespace uri, may be null.

getLogger

public Logger getLogger()
The logger for the datastore.


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

getTypeNames

public final String[] getTypeNames()
                            throws IOException
Returns the names of all entries or types provided by the datastore.

This method is marked final and delegates to createTypeNames(), which subclasses are intended to implement.

Specified by:
getTypeNames in interface DataStore
Returns:
typeNames for available FeatureTypes.
Throws:
IOException
See Also:
DataStore.getTypeNames()

createSchema

public void createSchema(SimpleFeatureType featureType)
                  throws IOException
Creates a new schema in the datastore.

This implementation throws aUnsupportedOperationException. Subclasses should override to support schema creation.

Specified by:
createSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Parameters:
featureType - FetureType to add to DataStore
Throws:
IOException - If featureType cannot be created
See Also:
DataAccess.createSchema(FeatureType)

getSchema

public final SimpleFeatureType getSchema(String typeName)
                                  throws IOException
Returns the feature type or schema matching the specified name.

This method calls through to getFeatureSource(typeName).getSchema()

Specified by:
getSchema in interface DataStore
Parameters:
typeName - typeName of requested FeatureType
Returns:
FeatureType for the provided typeName
Throws:
IOException - If typeName cannot be found
See Also:
DataStore.getSchema(String)

getFeatureSource

public ContentFeatureSource getFeatureSource(String typeName)
                                      throws IOException
Returns the feature source matching the specified name.

Subclasses should not implement this method. However overriding in order to perform a type narrowing to a subclasses of ContentFeatureSource is acceptable.

Specified by:
getFeatureSource in interface DataStore
Returns:
FeatureSource (or subclass) providing operations for typeName
Throws:
IOException
See Also:
DataStore.getFeatureSource(String)

getFeatureSource

public ContentFeatureSource getFeatureSource(String typeName,
                                             Transaction tx)
                                      throws IOException
Returns the feature source matching the specified name and explicitly specifies a transaction.

Subclasses should not implement this method. However overriding in order to perform a type narrowing to a subclasses of ContentFeatureSource is acceptable.

Throws:
IOException
See Also:
DataStore.getFeatureSource(String)

getFeatureSource

public ContentFeatureSource getFeatureSource(Name typeName,
                                             Transaction tx)
                                      throws IOException
Returns the feature source matching the specified name and explicitly specifies a transaction.

Subclasses should not implement this method. However overriding in order to perform a type narrowing to a subclasses of ContentFeatureSource is acceptable.

Throws:
IOException
See Also:
DataStore.getFeatureSource(String)

getFeatureReader

public FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(Query query,
                                                                       Transaction tx)
                                                                throws IOException
Returns a feature reader for the specified query and transaction.

This method is not intended to be overridden and is marked final. This implementation delegates to FeatureCollection and wraps an iterator in a FeatureReader.

Specified by:
getFeatureReader in interface DataStore
Parameters:
query - Requested form of the returned Features and the filter used to constraints the results
tx - Transaction this query operates against
Returns:
FeatureReader Allows Sequential Processing of featureType
Throws:
IOException

getFeatureWriter

public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName,
                                                                       Filter filter,
                                                                       Transaction tx)
                                                                throws IOException
Returns a feature writer for the specified query and transaction.

This method is not intended to be overridden and is marked final. This implementation delegates to FeatureCollection and wraps an iterator in a FeatureWriter.

Specified by:
getFeatureWriter in interface DataStore
Parameters:
typeName - Indicates featureType to be modified
filter - constraints used to limit the modification
tx - Transaction this query operates against
Returns:
FeatureWriter Allows Sequential Modification of featureType
Throws:
IOException

ensureFeatureStore

protected final ContentFeatureStore ensureFeatureStore(String typeName,
                                                       Transaction tx)
                                                throws IOException
Helper method which gets a feature source ensuring that it is a feature store as well. If not it throws an IOException.

Parameters:
typeName - The name of the feature source.
tx - A transaction handle.
Throws:
IOException - If the feature source is not a store.

getFeatureWriter

public final FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(String typeName,
                                                                             Transaction tx)
                                                                      throws IOException
Returns a feature writer for the specified type name and transaction.

This method is convenience for getFeatureWriter(typeName,Filter.INCLUDE,tx).

Specified by:
getFeatureWriter in interface DataStore
Parameters:
typeName - Indicates featureType to be modified
tx - Transaction to operates against
Returns:
FeatureReader Allows Sequential Processing of featureType
Throws:
IOException

getFeatureWriterAppend

public final FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName,
                                                                                   Transaction tx)
                                                                            throws IOException
Returns an appending feature writer for the specified type name and transaction.

This method is not intended to be overridden and is marked final. This implementation delegates to FeatureCollection and wraps an iterator in a FeatureWriter.

Specified by:
getFeatureWriterAppend in interface DataStore
Parameters:
typeName - Indicates featureType to be modified
tx - Transaction to operates against
Returns:
FeatureWriter that may only be used to append new content
Throws:
IOException

getLockingManager

public final LockingManager getLockingManager()
Description copied from interface: DataStore
Retrieve a per featureID based locking service from this DataStore.

It is common to return an instanceof InProcessLockingManager for DataStores that do not provide native locking.

AbstractFeatureLocking makes use of this service to provide locking support. You are not limitied by this implementation and may simply return null for this value.

Specified by:
getLockingManager in interface DataStore
Returns:
DataStores may return null, if the handling locking in another fashion.

getView

public final FeatureSource<SimpleFeatureType,SimpleFeature> getView(Query query)
                                                             throws IOException,
                                                                    SchemaException
Description copied from interface: DataStore
Access a FeatureSource for Query providing a high-level API.

The provided Query does not need to completely cover the existing schema for Query.getTypeName(). The result will mostly likely only be a FeatureSource and probably wont' allow write access by the FeatureStore method.

By using Query we allow support for reprojection, in addition to overriding the CoordinateSystem used by the native FeatureType.

We may wish to limit this method to only support Queries using Filter.EXCLUDE.

Update - GeoServer has an elegatent implementation of this functionality that we could steal. GeoServerFeatureSource, GeoServerFeatureStore and GeoServerFeatureLocking serve as a working prototype.

Specified by:
getView in interface DataStore
Parameters:
query - Query.getTypeName() locates FeatureType being viewed
Returns:
FeatureSource providing operations for featureType
Throws:
IOException - If FeatureSource is not available
SchemaException - If fetureType is not covered by existing schema

updateSchema

public final void updateSchema(String typeName,
                               SimpleFeatureType featureType)
                        throws 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
Throws:
IOException

dispose

public void dispose()
Description copied from interface: DataAccess
Disposes of this data store and releases any resource that it is using.

A DataStore cannot be used after dispose has been called, neither can any data access object it helped create, such as FeatureReader, FeatureSource or FeatureCollection.

This operation can be called more than once without side effects.

There is no thread safety assurance associated with this method. For example, client code will have to make sure this method is not called while retrieving/saving data from/to the storage, or be prepared for the consequences.

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

getEntry

public ContentEntry getEntry(Name name)
Returns the entry for a specified name, or null if no such entry exists.


createContentState

protected ContentState createContentState(ContentEntry entry)
Instantiates a new content state for the entry.

Subclasses may override this method to return a specific subclass of ContentState.

Parameters:
entry - The entry.
Returns:
A new instance of ContentState for the entry.

name

protected final Name name(String typeName)
Helper method to wrap a non-qualified name.


entry

protected final ContentEntry entry(Name name)
                            throws IOException
Helper method to look up an entry in the datastore.

This method will create a new instance of ContentEntry if one does not exist.

In the event that the name does not map to an entry and one cannot be created null will be returned. Note that #ensureEntry(TypeName) will throw an exception in this case.

Parameters:
The - name of the entry.
Returns:
The entry, or null if it does not exist.
Throws:
IOException

ensureEntry

protected final ContentEntry ensureEntry(Name name)
                                  throws IOException
Helper method to look up an entry in the datastore which throws an IOException in the event that the entry does not exist.

Parameters:
name - The name of the entry.
Returns:
The entry.
Throws:
IOException - If the entry does not exist, or if there was an error looking it up.

createTypeNames

protected abstract List<Name> createTypeNames()
                                       throws IOException
Creates a set of qualified names corresponding to the types that the datastore provides.

Namespaces may be left null for data stores which do not support namespace qualified type names.

Returns:
A list of Name.
Throws:
IOException - Any errors occuring connecting to data.

createFeatureSource

protected abstract ContentFeatureSource createFeatureSource(ContentEntry entry)
                                                     throws IOException
Instantiates new feature source for the entry.

Subclasses should override this method to return a specific subclass of ContentFeatureSource.

Parameters:
entry - The entry.
Returns:
An new instance of ContentFeatureSource for the entry.
Throws:
IOException

getFeatureSource

public FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource(Name typeName)
                                                                throws IOException
Delegates to getFeatureSource(String) with name.getLocalPart()

Specified by:
getFeatureSource in interface DataAccess<SimpleFeatureType,SimpleFeature>
Returns:
Access to the named resource being made available
Throws:
IOException
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)


Copyright © 1996-2009 Geotools. All Rights Reserved.