org.geotools.data.memory
Class MemoryDataStore

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

public class MemoryDataStore
extends AbstractDataStore

This is an example implementation of a DataStore used for testing.

It serves as an example implementation of:

This class will also illustrate the use of In-Process locking when the time comes.

Author:
jgarnett
Module:

Field Summary
protected  Map memory
          Memory holds Map of Feature by fid by typeName.
protected  Map schema
          Schema holds FeatureType by typeName
 
Fields inherited from class AbstractDataStore
isWriteable, listenerManager, LOGGER
 
Constructor Summary
MemoryDataStore()
           
MemoryDataStore(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)
           
MemoryDataStore(FeatureIterator<SimpleFeature> reader)
           
MemoryDataStore(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
           
MemoryDataStore(SimpleFeature[] array)
           
 
Method Summary
 void addFeature(SimpleFeature feature)
          Adds a single Feature to the correct typeName entry.
 void addFeatures(Collection collection)
          Configures MemoryDataStore with Collection.
 void addFeatures(FeatureCollection collection)
           
 void addFeatures(FeatureIterator<SimpleFeature> reader)
          Configures MemoryDataStore with FeatureReader.
 void addFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
          Configures MemoryDataStore with FeatureReader.
 void addFeatures(SimpleFeature[] features)
          Configures MemoryDataStore with feature array.
 FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName, Transaction transaction)
          Provides FeatureWriter over the entire contents of typeName.
 void createSchema(SimpleFeatureType featureType)
          Adds support for a new featureType to MemoryDataStore.
protected  Map features(String typeName)
          Access featureMap for typeName.
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(String typeName)
          Provides FeatureReader over the entire contents of typeName.
 SimpleFeatureType getSchema(String typeName)
          SimpleFeatureType access by typeName.
 String[] getTypeNames()
          List of available types provided by this DataStore.
 
Methods inherited from class AbstractDataStore
createLockingManager, createMetadata, dispose, getFeatureReader, getFeatureReader, getFeatureSource, getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getInfo, getLockingManager, getNames, getSchema, getSupportedHints, getUnsupportedFilter, getView, state, updateSchema, updateSchema
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

memory

protected Map memory
Memory holds Map of Feature by fid by typeName.


schema

protected Map schema
Schema holds FeatureType by typeName

Constructor Detail

MemoryDataStore

public MemoryDataStore()

MemoryDataStore

public MemoryDataStore(FeatureCollection<SimpleFeatureType,SimpleFeature> collection)

MemoryDataStore

public MemoryDataStore(SimpleFeature[] array)

MemoryDataStore

public MemoryDataStore(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
                throws IOException
Throws:
IOException

MemoryDataStore

public MemoryDataStore(FeatureIterator<SimpleFeature> reader)
                throws IOException
Throws:
IOException
Method Detail

addFeatures

public void addFeatures(FeatureReader<SimpleFeatureType,SimpleFeature> reader)
                 throws IOException
Configures MemoryDataStore with FeatureReader.

Parameters:
reader - New contents to add
Throws:
IOException - If problems are encountered while adding
DataSourceException - See IOException

addFeatures

public void addFeatures(FeatureIterator<SimpleFeature> reader)
                 throws IOException
Configures MemoryDataStore with FeatureReader.

Parameters:
reader - New contents to add
Throws:
IOException - If problems are encountered while adding
DataSourceException - See IOException

addFeatures

public void addFeatures(Collection collection)
Configures MemoryDataStore with Collection.

You may use this to create a MemoryDataStore from a FeatureCollection.

Parameters:
collection - Collection of features to add
Throws:
IllegalArgumentException - If provided collection is empty

addFeatures

public void addFeatures(FeatureCollection collection)

addFeatures

public void addFeatures(SimpleFeature[] features)
Configures MemoryDataStore with feature array.

Parameters:
features - Array of features to add
Throws:
IllegalArgumentException - If provided feature array is empty

addFeature

public void addFeature(SimpleFeature feature)
Adds a single Feature to the correct typeName entry.

This is an internal opperation used for setting up MemoryDataStore - please use FeatureWriter for generatl use.

This method is willing to create new FeatureTypes for MemoryDataStore.

Parameters:
feature - Individual feature to add

features

protected Map features(String typeName)
                throws IOException
Access featureMap for typeName.

Parameters:
typeName -
Returns:
A Map of Features by FID
Throws:
IOException - If typeName cannot be found

getTypeNames

public String[] getTypeNames()
List of available types provided by this DataStore.

Specified by:
getTypeNames in interface DataStore
Specified by:
getTypeNames in class AbstractDataStore
Returns:
Array of type names
See Also:
org.geotools.data.AbstractDataStore#getFeatureTypes()

getSchema

public SimpleFeatureType getSchema(String typeName)
                            throws IOException
SimpleFeatureType access by typeName.

Specified by:
getSchema in interface DataStore
Specified by:
getSchema in class AbstractDataStore
Parameters:
typeName -
Returns:
SimpleFeatureType for typeName
Throws:
IOException
SchemaNotFoundException - DOCUMENT ME!
See Also:
AbstractDataStore.getSchema(java.lang.String)

createSchema

public void createSchema(SimpleFeatureType featureType)
                  throws IOException
Adds support for a new featureType to MemoryDataStore.

FeatureTypes are stored by typeName, an IOException will be thrown if the requested typeName is already in use.

Specified by:
createSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Overrides:
createSchema in class AbstractDataStore
Parameters:
featureType - SimpleFeatureType to be added
Throws:
IOException - If featureType already exists
See Also:
org.geotools.data.DataStore#createSchema(org.geotools.feature.SimpleFeatureType)

getFeatureReader

public FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName)
                                                                throws IOException
Provides FeatureReader over the entire contents of typeName.

Implements getFeatureReader contract for AbstractDataStore.

Specified by:
getFeatureReader in class AbstractDataStore
Parameters:
typeName -
Returns:
FeatureReader over contents of typeName
Throws:
IOException - If typeName could not be found
DataSourceException - See IOException
See Also:
AbstractDataStore.getFeatureSource(java.lang.String)

createFeatureWriter

public FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName,
                                                                          Transaction transaction)
                                                                   throws IOException
Provides FeatureWriter over the entire contents of typeName.

Implements getFeatureWriter contract for AbstractDataStore.

Overrides:
createFeatureWriter in class AbstractDataStore
Parameters:
typeName - name of FeatureType we wish to modify
transaction - a feature writer
Returns:
FeatureWriter of entire contents of typeName
Throws:
IOException - If writer cannot be obtained for typeName
DataSourceException - See IOException
See Also:
AbstractDataStore.getFeatureSource(java.lang.String)

getBounds

protected ReferencedEnvelope getBounds(Query query)
                                throws IOException
Description copied from class: AbstractDataStore
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

Overrides:
getBounds in class AbstractDataStore
Returns:
the bounds, or null if too expensive
Throws:
SchemaNotFoundException
IOException
See Also:
org.geotools.data.AbstractDataStore#getBounds(java.lang.String, org.geotools.data.Query)

getCount

protected int getCount(Query query)
                throws IOException
Description copied from class: AbstractDataStore
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.

Overrides:
getCount in class AbstractDataStore
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
See Also:
org.geotools.data.AbstractDataStore#getCount(java.lang.String, org.geotools.data.Query)


Copyright © 1996-2009 Geotools. All Rights Reserved.