org.geotools.data.postgis.synch
Class SynchronizedPostgisDataStore

java.lang.Object
  extended by org.geotools.data.postgis.synch.SynchronizedPostgisDataStore
All Implemented Interfaces:
DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, DataStore, VersioningDataStore

public class SynchronizedPostgisDataStore
extends java.lang.Object
implements VersioningDataStore

This DataStore provides a wrapper for the VersionedPostgisDataStore that hides the existence of the synchronizing metadata tables.

Author:
markles

Field Summary
 
Fields inherited from interface org.geotools.data.VersioningDataStore
AUTHOR, MESSAGE
 
Constructor Summary
SynchronizedPostgisDataStore(javax.sql.DataSource dataSource)
           
SynchronizedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String namespace)
           
SynchronizedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String schema, java.lang.String namespace)
           
SynchronizedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String schema, java.lang.String namespace, int optimizeMode)
           
 
Method Summary
 void createSchema(org.opengis.feature.simple.SimpleFeatureType featureType)
          Creates storage for a new featureType.
 void dispose()
          Disposes of this data store and releases any resource that it is using.
 boolean equals(java.lang.Object obj)
           
 java.sql.Connection getConnection(Transaction t)
           
 FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureReader(Query query, Transaction trans)
          Access a FeatureReader providing access to Feature information.
 FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(org.opengis.feature.type.Name typeName)
          Access to the named resource.
 FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(java.lang.String typeName)
          Access a FeatureSource for typeName providing a high-level API.
 FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriter(java.lang.String typeName, org.opengis.filter.Filter filter, Transaction transaction)
          Access FeatureWriter for modification of existing DataStore contents.
 FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriter(java.lang.String typeName, Transaction transaction)
          Access FeatureWriter for modification of the DataStore typeName.
 FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterAppend(java.lang.String typeName, Transaction transaction)
          Aquire a FeatureWriter for adding new content to a FeatureType.
 FIDMapper getFIDMapper(java.lang.String tableName)
           
 ServiceInfo getInfo()
          Information about this service.
 long getLastRevision()
           
 LockingManager getLockingManager()
          Retrieve a per featureID based locking service from this DataStore.
 ModifiedFeatureIds getModifiedFeatureFIDs(java.lang.String typeName, java.lang.String version1, java.lang.String version2, org.opengis.filter.Filter originalFilter, java.lang.String[] users, Transaction transaction)
           
 java.lang.String[] getModifiedFeatureTypes(java.lang.String version1, java.lang.String version2)
           
 java.util.List<org.opengis.feature.type.Name> getNames()
          This is stolen verbatim from VersionedPostgisDataStore
 org.opengis.feature.simple.SimpleFeatureType getSchema(org.opengis.feature.type.Name name)
          We're intercepting malicious requests for our metadata tables and failing, but delegating all other requests.
 org.opengis.feature.simple.SimpleFeatureType getSchema(java.lang.String typeName)
          Intercept all requests for our metadata tables and fail.
 java.lang.String[] getTypeNames()
          Retrieves a list of all available featuretypes.
 FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getView(Query query)
          Access a FeatureSource for Query providing a high-level API.
 int hashCode()
           
 boolean isVersioned(java.lang.String typeName)
          Returns true if the specified feature type is versioned, false otherwise
 boolean isVersionedFeatureCollection(java.lang.String typeName)
           
 void setLooseBbox(boolean enabled)
           
 void setVersioned(java.lang.String typeName, boolean versioned, java.lang.String author, java.lang.String message)
          Alters the versioned state of a feature type
 void setWKBEnabled(boolean enabled)
           
 java.lang.String toString()
           
 void updateSchema(org.opengis.feature.type.Name typeName, org.opengis.feature.simple.SimpleFeatureType featureType)
          Used to update a schema in place.
 void updateSchema(java.lang.String typeName, org.opengis.feature.simple.SimpleFeatureType featureType)
          Used to force namespace and CS info into a persistent change.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SynchronizedPostgisDataStore

public SynchronizedPostgisDataStore(javax.sql.DataSource dataSource,
                                    java.lang.String schema,
                                    java.lang.String namespace,
                                    int optimizeMode)
                             throws java.io.IOException
Throws:
java.io.IOException

SynchronizedPostgisDataStore

public SynchronizedPostgisDataStore(javax.sql.DataSource dataSource,
                                    java.lang.String schema,
                                    java.lang.String namespace)
                             throws java.io.IOException
Throws:
java.io.IOException

SynchronizedPostgisDataStore

public SynchronizedPostgisDataStore(javax.sql.DataSource dataSource,
                                    java.lang.String namespace)
                             throws java.io.IOException
Throws:
java.io.IOException

SynchronizedPostgisDataStore

public SynchronizedPostgisDataStore(javax.sql.DataSource dataSource)
                             throws java.io.IOException
Throws:
java.io.IOException
Method Detail

createSchema

public void createSchema(org.opengis.feature.simple.SimpleFeatureType featureType)
                  throws java.io.IOException
Description copied from interface: DataAccess
Creates storage for a new featureType.

The provided featureType we be accessable by the typeName provided by featureType.getTypeName().

Specified by:
createSchema in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Parameters:
featureType -
Throws:
java.io.IOException
See Also:
VersionedPostgisDataStore.createSchema(org.opengis.feature.simple.SimpleFeatureType)

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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
See Also:
VersionedPostgisDataStore.dispose()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
Parameters:
obj -
Returns:
See Also:
Object.equals(java.lang.Object)

getConnection

public java.sql.Connection getConnection(Transaction t)
                                  throws java.io.IOException
Parameters:
t -
Returns:
Throws:
java.io.IOException
See Also:
VersionedPostgisDataStore.getConnection(org.geotools.data.Transaction)

getFeatureReader

public FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureReader(Query query,
                                                                                                                             Transaction trans)
                                                                                                                      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.EXCLUDE) {
      return new EmptyFeatureReader(featureType);
  }

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

  if (filter != Filter.INCLUDE) {
      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.

Specified by:
getFeatureReader in interface DataStore
Parameters:
query -
trans -
Returns:
Throws:
java.io.IOException
See Also:
VersionedPostgisDataStore.getFeatureReader(org.geotools.data.Query, org.geotools.data.Transaction)

getFeatureSource

public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(org.opengis.feature.type.Name typeName)
                                                                                                                      throws java.io.IOException
Description copied from interface: DataAccess
Access to the named resource.

The level of access is represented by the instance of the FeatureSource being returned.

Formally:


getFeatureSource

public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(java.lang.String typeName)
                                                                                                                      throws java.io.IOException
Description copied from interface: DataStore
Access a FeatureSource for typeName providing a high-level API.

The resulting FeatureSource may implment more functionality:



 FeatureSource fsource = dataStore.getFeatureSource( "roads" );
 FeatureStore fstore = null;
 if( fsource instanceof FeatureLocking ){
     fstore = (FeatureStore) fs;
 }
 else {
     System.out.println("We do not have write access to roads");
 }
 
 

Specified by:
getFeatureSource in interface DataStore
Parameters:
typeName -
Returns:
Throws:
java.io.IOException
See Also:
VersionedPostgisDataStore.getFeatureSource(java.lang.String)

getFeatureWriter

public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriter(java.lang.String typeName,
                                                                                                                             org.opengis.filter.Filter filter,
                                                                                                                             Transaction transaction)
                                                                                                                      throws java.io.IOException
Description copied from interface: DataStore
Access FeatureWriter for modification of existing DataStore contents.

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 )

The FeatureWriter will provide access to the existing contents of the FeatureType referenced by typeName. The provided filter will be used to skip over Features as required.

Notes For Implementing DataStore

The returned FeatureWriter does not support the addition of 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.EXCLUDE optimizations
  • Specified by:
    getFeatureWriter in interface DataStore
    Parameters:
    typeName -
    filter -
    transaction -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getFeatureWriter(java.lang.String, org.opengis.filter.Filter, org.geotools.data.Transaction)

    getFeatureWriter

    public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> 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 -
    transaction -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getFeatureWriter(java.lang.String, org.geotools.data.Transaction)

    getFeatureWriterAppend

    public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> 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
    See Also:
    VersionedPostgisDataStore.getFeatureWriterAppend(java.lang.String, org.geotools.data.Transaction)

    getFIDMapper

    public FIDMapper getFIDMapper(java.lang.String tableName)
                           throws java.io.IOException
    Parameters:
    tableName -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getFIDMapper(java.lang.String)

    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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
    Returns:
    See Also:
    VersionedPostgisDataStore.getInfo()

    getLastRevision

    public long getLastRevision()
                         throws java.io.IOException
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getLastRevision()

    getLockingManager

    public 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:
    See Also:
    VersionedPostgisDataStore.getLockingManager()

    getModifiedFeatureFIDs

    public ModifiedFeatureIds getModifiedFeatureFIDs(java.lang.String typeName,
                                                     java.lang.String version1,
                                                     java.lang.String version2,
                                                     org.opengis.filter.Filter originalFilter,
                                                     java.lang.String[] users,
                                                     Transaction transaction)
                                              throws java.io.IOException
    Parameters:
    typeName -
    version1 -
    version2 -
    originalFilter -
    users -
    transaction -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getModifiedFeatureFIDs(java.lang.String, java.lang.String, java.lang.String, org.opengis.filter.Filter, java.lang.String[], org.geotools.data.Transaction)

    getModifiedFeatureTypes

    public java.lang.String[] getModifiedFeatureTypes(java.lang.String version1,
                                                      java.lang.String version2)
                                               throws java.io.IOException
    Parameters:
    version1 -
    version2 -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getModifiedFeatureTypes(java.lang.String, java.lang.String)

    getNames

    public java.util.List<org.opengis.feature.type.Name> getNames()
                                                           throws java.io.IOException
    This is stolen verbatim from VersionedPostgisDataStore

    Specified by:
    getNames in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getNames()

    getSchema

    public org.opengis.feature.simple.SimpleFeatureType getSchema(org.opengis.feature.type.Name name)
                                                           throws java.io.IOException
    We're intercepting malicious requests for our metadata tables and failing, but delegating all other requests.

    Specified by:
    getSchema in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
    Parameters:
    name -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getSchema(org.opengis.feature.type.Name)

    getSchema

    public org.opengis.feature.simple.SimpleFeatureType getSchema(java.lang.String typeName)
                                                           throws java.io.IOException
    Intercept all requests for our metadata tables and fail. Delegate all others.

    Specified by:
    getSchema in interface DataStore
    Parameters:
    typeName -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getSchema(java.lang.String)

    getTypeNames

    public java.lang.String[] getTypeNames()
                                    throws java.io.IOException
    Retrieves a list of all available featuretypes. Removes any references to our synchronized metadata tables.

    Specified by:
    getTypeNames in interface DataStore
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.getTypeNames()

    getView

    public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getView(Query query)
                                                                                                                 throws java.io.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 -
    Returns:
    Throws:
    java.io.IOException
    SchemaException
    See Also:
    VersionedPostgisDataStore.getView(org.geotools.data.Query)

    hashCode

    public int hashCode()
    Overrides:
    hashCode in class java.lang.Object
    Returns:
    See Also:
    Object.hashCode()

    isVersioned

    public boolean isVersioned(java.lang.String typeName)
                        throws java.io.IOException
    Description copied from interface: VersioningDataStore
    Returns true if the specified feature type is versioned, false otherwise

    Specified by:
    isVersioned in interface VersioningDataStore
    Parameters:
    typeName -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.isVersioned(java.lang.String)

    isVersionedFeatureCollection

    public boolean isVersionedFeatureCollection(java.lang.String typeName)
                                         throws java.io.IOException
    Parameters:
    typeName -
    Returns:
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.isVersionedFeatureCollection(java.lang.String)

    setLooseBbox

    public void setLooseBbox(boolean enabled)
    Parameters:
    enabled -
    See Also:
    VersionedPostgisDataStore.setLooseBbox(boolean)

    setVersioned

    public void setVersioned(java.lang.String typeName,
                             boolean versioned,
                             java.lang.String author,
                             java.lang.String message)
                      throws java.io.IOException
    Description copied from interface: VersioningDataStore
    Alters the versioned state of a feature type

    Specified by:
    setVersioned in interface VersioningDataStore
    Parameters:
    typeName -
    versioned -
    author -
    message -
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.setVersioned(java.lang.String, boolean, java.lang.String, java.lang.String)

    setWKBEnabled

    public void setWKBEnabled(boolean enabled)
    Parameters:
    enabled -
    See Also:
    VersionedPostgisDataStore.setWKBEnabled(boolean)

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object
    Returns:
    See Also:
    Object.toString()

    updateSchema

    public void updateSchema(org.opengis.feature.type.Name typeName,
                             org.opengis.feature.simple.SimpleFeatureType featureType)
                      throws java.io.IOException
    Description copied from interface: DataAccess
    Used to update a schema in place.

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

    Specified by:
    updateSchema in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
    Parameters:
    typeName -
    featureType -
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.updateSchema(org.opengis.feature.type.Name, org.opengis.feature.simple.SimpleFeatureType)

    updateSchema

    public void updateSchema(java.lang.String typeName,
                             org.opengis.feature.simple.SimpleFeatureType 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 -
    featureType -
    Throws:
    java.io.IOException
    See Also:
    VersionedPostgisDataStore.updateSchema(java.lang.String, org.opengis.feature.simple.SimpleFeatureType)


    Copyright © 1996-2010 Geotools. All Rights Reserved.