Class MemoryDataStore

  • All Implemented Interfaces:
    DataAccess<SimpleFeatureType,​SimpleFeature>, DataStore

    public class MemoryDataStore
    extends ContentDataStore
    This is an example implementation of a DataStore used for testing.

    It serves as an example implementation of:

    • FeatureListenerManager use: allows handling of FeatureEvents

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

    Author:
    jgarnett
    • Constructor Detail

      • MemoryDataStore

        public MemoryDataStore()
      • MemoryDataStore

        public MemoryDataStore​(SimpleFeatureType featureType)
        Construct an MemoryDataStore around an empty collection of the provided SimpleFeatureType
        Parameters:
        featureType - The initial feature type for the memory data store, an empty feature collection of this type will be made available
      • MemoryDataStore

        public MemoryDataStore​(SimpleFeature... array)
      • MemoryDataStore

        public MemoryDataStore​(SimpleFeatureIterator reader)
                        throws IOException
        Throws:
        IOException
    • Method Detail

      • addFeatures

        public void addFeatures​(SimpleFeatureIterator 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​(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 operation used for setting up MemoryDataStore - please use FeatureWriter for general use.

        This method is willing to create new FeatureTypes for MemoryDataStore.

        Parameters:
        feature - Individual feature to add
      • entry

        protected MemoryEntry entry​(String typeName)
                             throws IOException
        Access MemoryState for typeName.

        Technically this is accessing the MemoryState for Transaction.AUTO_COMMIT, which is the definitive storage for the feature content.

        Returns:
        MemoryState storing feature (by FeatureID)
        Throws:
        IOException - If typeName cannot be found
      • entry

        protected MemoryEntry entry​(SimpleFeatureType schema)
                             throws IOException
        Access to entry to store content of the provided schema, will create new entry if needed.

        Returns:
        MemoryState used for content storage
        Throws:
        IOException - If new entry could not be created due to typeName conflict
      • createTypeNames

        protected List<Name> createTypeNames()
        List of available types provided by this DataStore.
        Specified by:
        createTypeNames in class ContentDataStore
        Returns:
        List of type names
        See Also:
        org.geotools.data.ContentDataStore#getFeatureTypes()
      • 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 ContentDataStore
        Parameters:
        featureType - SimpleFeatureType to be added
        Throws:
        IOException - If featureType already exists
        See Also:
        DataStore#createSchema(org.geotools.feature.SimpleFeatureType)
      • 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
        Overrides:
        removeSchema in class ContentDataStore
        Throws:
        IOException - if the operation failed
        See Also:
        DataStore.removeSchema(String)