org.geotools.data.postgis
Class PostgisFeatureStore

java.lang.Object
  extended byorg.geotools.data.jdbc.JDBCFeatureSource
      extended byorg.geotools.data.jdbc.JDBCFeatureStore
          extended byorg.geotools.data.postgis.PostgisFeatureStore
All Implemented Interfaces:
FeatureSource, FeatureStore
Direct Known Subclasses:
PostgisFeatureLocking

public class PostgisFeatureStore
extends JDBCFeatureStore

Implementation of a Postgis specific FeatureStore.

This mostly just rips off code from PostgisDataSource It could definitely use some nice code reuse with PostgisDataStore, as they have a number of similar if not identical methods right now.

Approaching deadlines, however, mean that we're sticking with the code that works, instead of getting all kinds of nice reuse. This'll hopefully change. This bypasses the writers used in JDBCFeatureStore, as I'm just not yet confident in them. We also should do some solid tests to see which is actually faster.

Version:
$Id: PostgisFeatureStore.java 17700 2006-01-22 23:30:39Z desruisseaux $
Author:
Chris Holmes, TOPP
Task:
HACK: too little code reuse with PostgisDataStore., TODO: make individual operations truly atomic. If the transaction is an auto-commit one, then it should make a a new jdbc transaction that rollsback if there are errors while performing its action., TODO: don't use encoder at all, only access it through PostgisSQLBuilder

Field Summary
protected static java.lang.String CONN_ERROR
          Error message prefix for sql connection errors
protected  SQLEncoderPostgis encoder
           
protected  FIDMapper fidMapper
          the name of the column to use for the featureId
protected static com.vividsolutions.jts.geom.GeometryFactory geometryFactory
          Factory for producing geometries (from JTS).
protected static com.vividsolutions.jts.io.WKTReader geometryReader
          Well Known Text reader (from JTS).
protected static com.vividsolutions.jts.io.WKTWriter geometryWriter
          Well Known Text writer (from JTS).
protected  PostgisSQLBuilder sqlBuilder
          To create the sql where statement
protected  java.lang.String tableName
           
 
Fields inherited from class org.geotools.data.jdbc.JDBCFeatureStore
transaction
 
Constructor Summary
PostgisFeatureStore(PostgisDataStore postgisDataStore, FeatureType featureType)
           
 
Method Summary
protected  com.vividsolutions.jts.geom.Envelope bounds(Query query)
           
 com.vividsolutions.jts.geom.Envelope getBounds()
          Gets the bounding box of this datasource.
 com.vividsolutions.jts.geom.Envelope getBounds(Query query)
          Retrieve Bounds of Query results.
protected  com.vividsolutions.jts.geom.Envelope getEnvelope(java.sql.Connection conn, java.lang.String geomName, SQLBuilder sqlBuilder, Filter filter)
           
protected  PostgisDataStore getPostgisDataStore()
          Performs the setFeautres operation by removing all and then adding the full collection.
protected  int getSRID(java.lang.String geomName)
           
 java.lang.String makeSql(SQLUnpacker unpacker, Query query)
          Creates a SQL statement for the PostGIS database.
 void modifyFeatures(AttributeType[] type, java.lang.Object[] value, Filter filter)
          Modifies the passed attribute types with the passed objects in all features that correspond to the passed OGS filter.
 void modifyFeatures(AttributeType type, java.lang.Object value, Filter filter)
          Modifies the passed attribute types with the passed objects in all features that correspond to the passed OGS filter.
 void removeFeatures(Filter filter)
          Removes the features specified by the passed filter from the PostGIS database.
 
Methods inherited from class org.geotools.data.jdbc.JDBCFeatureStore
addFeatures, assertFids, assertFilter, fids, getInProcessLockingManager, getTransaction, modifyFeatures, setFeatures, setTransaction
 
Methods inherited from class org.geotools.data.jdbc.JDBCFeatureSource
addFeatureListener, close, close, close, count, getConnection, getCount, getDataStore, getFeatures, getFeatures, getFeatures, getJDBCDataStore, getSchema, removeFeatureListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.data.FeatureSource
addFeatureListener, getCount, getDataStore, getFeatures, getFeatures, getFeatures, getSchema, removeFeatureListener
 

Field Detail

geometryWriter

protected static com.vividsolutions.jts.io.WKTWriter geometryWriter
Well Known Text writer (from JTS).


geometryFactory

protected static com.vividsolutions.jts.geom.GeometryFactory geometryFactory
Factory for producing geometries (from JTS).


geometryReader

protected static com.vividsolutions.jts.io.WKTReader geometryReader
Well Known Text reader (from JTS).


CONN_ERROR

protected static final java.lang.String CONN_ERROR
Error message prefix for sql connection errors

See Also:
Constant Field Values

sqlBuilder

protected PostgisSQLBuilder sqlBuilder
To create the sql where statement


encoder

protected SQLEncoderPostgis encoder

tableName

protected java.lang.String tableName

fidMapper

protected FIDMapper fidMapper
the name of the column to use for the featureId

Constructor Detail

PostgisFeatureStore

public PostgisFeatureStore(PostgisDataStore postgisDataStore,
                           FeatureType featureType)
                    throws java.io.IOException
Method Detail

getSRID

protected int getSRID(java.lang.String geomName)
               throws java.io.IOException
Throws:
java.io.IOException

removeFeatures

public void removeFeatures(Filter filter)
                    throws java.io.IOException
Removes the features specified by the passed filter from the PostGIS database.

Specified by:
removeFeatures in interface FeatureStore
Overrides:
removeFeatures in class JDBCFeatureStore
Parameters:
filter - An OpenGIS filter; specifies which features to remove.
Throws:
java.io.IOException - If anything goes wrong or if deleting is not supported.
DataSourceException - DOCUMENT ME!
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

modifyFeatures

public void modifyFeatures(AttributeType[] type,
                           java.lang.Object[] value,
                           Filter filter)
                    throws java.io.IOException
Modifies the passed attribute types with the passed objects in all features that correspond to the passed OGS filter.

Specified by:
modifyFeatures in interface FeatureStore
Overrides:
modifyFeatures in class JDBCFeatureStore
Parameters:
type - The attributes to modify.
value - The values to put in the attribute types.
filter - An OGC filter to note which attributes to modify.
Throws:
java.io.IOException - If modificaton is not supported, if the attribute and object arrays are not eqaul length, or if the object types do not match the attribute types.
DataSourceException - DOCUMENT ME!
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)
Task:
REVISIT: validate values with types. Database does this a bit now, but should be more fully implemented., REVISIT: do some nice prepared statement stuff like oracle.

modifyFeatures

public void modifyFeatures(AttributeType type,
                           java.lang.Object value,
                           Filter filter)
                    throws java.io.IOException
Modifies the passed attribute types with the passed objects in all features that correspond to the passed OGS filter. A convenience method for single attribute modifications.

Specified by:
modifyFeatures in interface FeatureStore
Overrides:
modifyFeatures in class JDBCFeatureStore
Parameters:
type - The attributes to modify.
value - The values to put in the attribute types.
filter - An OGC filter to note which attributes to modify.
Throws:
java.io.IOException - If modificaton is not supported, if the object type do not match the attribute type.
See Also:
FeatureStore.modifyFeatures(org.geotools.feature.AttributeType, java.lang.Object, org.geotools.filter.Filter)

getPostgisDataStore

protected PostgisDataStore getPostgisDataStore()
Performs the setFeautres operation by removing all and then adding the full collection. This is not efficient, the add, modify and remove operations should be used instead, this is just to follow the interface.

Returns:
DOCUMENT ME!
Task:
REVISIT: to abstract class, same as oracle.

makeSql

public java.lang.String makeSql(SQLUnpacker unpacker,
                                Query query)
                         throws java.io.IOException
Creates a SQL statement for the PostGIS database.

Parameters:
unpacker - the object to get the encodable filter.
query - the getFeature query - for the tableName, properties and maxFeatures.
Returns:
Full SQL statement.
Throws:
java.io.IOException - if there are problems encoding the sql.
DataSourceException - DOCUMENT ME!
Task:
HACK: Use the postgis SQLBuilder, REVISIT: rewrite the unpacker.

getBounds

public com.vividsolutions.jts.geom.Envelope getBounds()
                                               throws java.io.IOException
Description copied from interface: FeatureSource
Gets the bounding box of this datasource.

With getBounds(Query) this becomes a convenience method for getBounds(Query.ALL), that is the bounds for all features contained here.

If getBounds() returns null due to expense consider using getFeatures().getBounds() as a an alternative.

Specified by:
getBounds in interface FeatureSource
Overrides:
getBounds in class JDBCFeatureSource
Returns:
null representing the lack of an optimization
Throws:
java.io.IOException - DOCUMENT ME!

getBounds

public com.vividsolutions.jts.geom.Envelope getBounds(Query query)
                                               throws java.io.IOException
Retrieve Bounds of Query results.

Currently returns null, consider getFeatures( query ).getBounds() instead.

Subclasses may override this method to perform the appropriate optimization for this result.

Specified by:
getBounds in interface FeatureSource
Overrides:
getBounds in class JDBCFeatureSource
Parameters:
query - Query we are requesting the bounds of
Returns:
null representing the lack of an optimization
Throws:
java.io.IOException - DOCUMENT ME!

bounds

protected com.vividsolutions.jts.geom.Envelope bounds(Query query)
                                               throws java.io.IOException
Throws:
java.io.IOException

getEnvelope

protected com.vividsolutions.jts.geom.Envelope getEnvelope(java.sql.Connection conn,
                                                           java.lang.String geomName,
                                                           SQLBuilder sqlBuilder,
                                                           Filter filter)
                                                    throws java.sql.SQLException,
                                                           SQLEncoderException,
                                                           java.io.IOException,
                                                           com.vividsolutions.jts.io.ParseException
Throws:
java.sql.SQLException
SQLEncoderException
java.io.IOException
com.vividsolutions.jts.io.ParseException


Copyright © GeoTools. All Rights Reserved.