org.geotools.jdbc
Class JDBCFeatureStore

java.lang.Object
  extended by org.geotools.data.store.ContentFeatureSource
      extended by org.geotools.data.store.ContentFeatureStore
          extended by org.geotools.jdbc.JDBCFeatureStore
All Implemented Interfaces:
FeatureLocking<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>

public final class JDBCFeatureStore
extends ContentFeatureStore

FeatureStore implementation for jdbc based relational database tables.

All read only methods are delegated to JDBCFeatureSource.

Author:
Justin Deoliveira, The Open Planning Project

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.geotools.data.FeatureLocking
FeatureLocking.Response
 
Field Summary
 
Fields inherited from class org.geotools.data.store.ContentFeatureStore
lock, WRITER_ADD, WRITER_UPDATE
 
Fields inherited from class org.geotools.data.store.ContentFeatureSource
entry, hints, query, queryCapabilities, schema, transaction
 
Constructor Summary
JDBCFeatureStore(ContentEntry entry, Query query)
          Creates the new feature store.
 
Method Summary
protected  org.opengis.feature.simple.SimpleFeatureType buildFeatureType()
          Creates the feature type or schema for the feature source.
protected  boolean canFilter()
          Determines if the datastore can natively perform a filtering.
protected  boolean canLimit()
          Determines if the datastore can natively limit the number of features returned in a query.
protected  boolean canOffset()
          Determines if the datastore can natively skip the first offset number of features returned in a query.
protected  boolean canRetype()
          Determines if the datasatore can natively perform "retyping" which includes limiting the number of attributes returned and reordering of those attributes
protected  boolean canSort()
          Determines if the datastore can natively perform sorting.
protected  ReferencedEnvelope getBoundsInternal(Query query)
          Calculates the bounds of a specified query.
protected  int getCountInternal(Query query)
          Calculates the number of features of a specified query.
 JDBCDataStore getDataStore()
          The datastore that this feature source originated from.
 ContentEntry getEntry()
          The entry for the feature source.
 ResourceInfo getInfo()
          A default ResourceInfo with a generic description.
 org.opengis.feature.type.Name getName()
          Returns the same name than the feature type (ie, getSchema().getName() to honor the simple feature land common practice of calling the same both the Features produces and their types
 PrimaryKey getPrimaryKey()
           
 QueryCapabilities getQueryCapabilities()
          FeatureCollection optimized for read-only access.
protected  FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getReaderInternal(Query query)
          Subclass method for returning a native reader from the datastore.
 JDBCState getState()
          The current state for the feature source.
 Transaction getTransaction()
          The current transaction the feature source is working against.
protected  FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getWriterInternal(Query query, int flags)
          Subclass method for returning a native writer from the datastore.
protected  boolean handleVisitor(Query query, org.opengis.feature.FeatureVisitor visitor)
          Subclass method which allows subclasses to natively handle a visitor.
 boolean isExposePrimaryKeyColumns()
          The flag which will expose columns which compose a tables identifying or primary key, through feature type attributes.
 void modifyFeatures(org.opengis.feature.type.AttributeDescriptor[] types, java.lang.Object[] values, org.opengis.filter.Filter filter)
          Modifies/updates the features of the store which match the specified filter.
 void removeFeatures(org.opengis.filter.Filter filter)
          Removes the features from the store which match the specified filter.
 void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
          Sets the flag which will expose columns which compose a tables identifying or primary key, through feature type attributes.
 void setTransaction(Transaction transaction)
          Sets the current transaction the feature source is working against.
 
Methods inherited from class org.geotools.data.store.ContentFeatureStore
addFeatures, addFeatures, getWriter, getWriter, getWriter, getWriter, lockFeatures, lockFeatures, lockFeatures, modifyFeatures, setFeatureLock, setFeatures, unLockFeatures, unLockFeatures, unLockFeatures
 
Methods inherited from class org.geotools.data.store.ContentFeatureSource
accepts, addFeatureListener, addHints, buildQueryCapabilities, canReproject, getAbsoluteSchema, getBounds, getBounds, getCount, getFeatures, getFeatures, getFeatures, getReader, getReader, getReader, getSchema, getSupportedHints, getView, getView, isView, joinQuery, removeFeatureListener, resolvePropertyNames, resolvePropertyNames
 
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, getBounds, getBounds, getCount, getFeatures, getFeatures, getFeatures, getSchema, getSupportedHints, removeFeatureListener
 

Constructor Detail

JDBCFeatureStore

public JDBCFeatureStore(ContentEntry entry,
                        Query query)
                 throws java.io.IOException
Creates the new feature store.

Parameters:
entry - The datastore entry.
query - The defining query.
Throws:
java.io.IOException
Method Detail

getDataStore

public JDBCDataStore getDataStore()
Description copied from class: ContentFeatureSource
The datastore that this feature source originated from.

Subclasses may wish to extend this method in order to type narrow its return type.

Specified by:
getDataStore in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getDataStore in class ContentFeatureSource
Returns:
DataStore implementing this FeatureStore

getEntry

public ContentEntry getEntry()
Description copied from class: ContentFeatureSource
The entry for the feature source.

Overrides:
getEntry in class ContentFeatureSource

getInfo

public ResourceInfo getInfo()
Description copied from class: ContentFeatureSource
A default ResourceInfo with a generic description.

Subclasses should override to provide an explicit ResourceInfo object for their content.

Specified by:
getInfo in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getInfo in class ContentFeatureSource
Returns:
description of features contents

getName

public org.opengis.feature.type.Name getName()
Description copied from class: ContentFeatureSource
Returns the same name than the feature type (ie, getSchema().getName() to honor the simple feature land common practice of calling the same both the Features produces and their types

Specified by:
getName in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getName in class ContentFeatureSource
Returns:
the name of the AttributeDescriptor for the Features served by this FeatureSource
See Also:
FeatureSource.getName()

getQueryCapabilities

public QueryCapabilities getQueryCapabilities()
Description copied from class: ContentFeatureSource
FeatureCollection optimized for read-only access.

Available via getView( filter ):

  • getFeatures().sort( sort )
  • getFeatures( filter ).sort( sort )

In particular this method of data access is intended for rendering and other high speed operations; care should be taken to optimize the use of FeatureVisitor.

Specified by:
getQueryCapabilities in interface FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getQueryCapabilities in class ContentFeatureSource
Returns:
readonly access

getState

public JDBCState getState()
Description copied from class: ContentFeatureSource
The current state for the feature source.

This value is derived from current transaction of the feature source.

Overrides:
getState in class ContentFeatureSource
See Also:
#setTransaction(Transaction)}.

getTransaction

public Transaction getTransaction()
Description copied from class: ContentFeatureSource
The current transaction the feature source is working against.

This transaction is used to derive the state for the feature source. A null value for a transaction represents the auto commit transaction: Transaction.AUTO_COMMIT.

Specified by:
getTransaction in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
getTransaction in class ContentFeatureSource
Returns:
Transaction in use, or Transaction.AUTO_COMMIT
See Also:
#getState()}.

setTransaction

public void setTransaction(Transaction transaction)
Description copied from class: ContentFeatureSource
Sets the current transaction the feature source is working against.

transaction may be null. This signifies that the auto-commit transaction is used: Transaction.AUTO_COMMIT.

Specified by:
setTransaction in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
setTransaction in class ContentFeatureSource
Parameters:
transaction - The new transaction, or null.

getPrimaryKey

public PrimaryKey getPrimaryKey()

setExposePrimaryKeyColumns

public void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
Sets the flag which will expose columns which compose a tables identifying or primary key, through feature type attributes.

Note: setting this flag which affect all feature sources created from or working against the current transaction.


isExposePrimaryKeyColumns

public boolean isExposePrimaryKeyColumns()
The flag which will expose columns which compose a tables identifying or primary key, through feature type attributes.


buildFeatureType

protected org.opengis.feature.simple.SimpleFeatureType buildFeatureType()
                                                                 throws java.io.IOException
Description copied from class: ContentFeatureSource
Creates the feature type or schema for the feature source.

Implementations should use SimpleFeatureTypeBuilder to build the feature type. Also, the builder should be injected with the feature factory which has been set on the datastore (see ContentDataStore.getFeatureFactory(). Example:

   SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
   b.setFeatureTypeFactory( getDataStore().getFeatureTypeFactory() );
   
   //build the feature type
   ...
 

Specified by:
buildFeatureType in class ContentFeatureSource
Throws:
java.io.IOException

getCountInternal

protected int getCountInternal(Query query)
                        throws java.io.IOException
Description copied from class: ContentFeatureSource
Calculates the number of features of a specified query. Subclasses must implement this method.

Specified by:
getCountInternal in class ContentFeatureSource
Throws:
java.io.IOException

getBoundsInternal

protected ReferencedEnvelope getBoundsInternal(Query query)
                                        throws java.io.IOException
Description copied from class: ContentFeatureSource
Calculates the bounds of a specified query. Subclasses must implement this method.

Specified by:
getBoundsInternal in class ContentFeatureSource
Throws:
java.io.IOException

canFilter

protected boolean canFilter()
Description copied from class: ContentFeatureSource
Determines if the datastore can natively perform a filtering.

If the subclass can handle filtering natively it should override this method to return true. In this case it must do the filtering or throw an exception. This includes the case of partial native filtering where the datastore can only handle part of the filter natively. In these cases it is up to the subclass to apply a decorator to the reader it returns which will handle any part of the filter can was not applied natively. See FilteringFeatureReader.

Not overriding this method or returning false will cause the feature reader created by the subclass to be wrapped in a filtering feature reader when the query specifies a filter. See FilteringFeatureReader.

Overrides:
canFilter in class ContentFeatureSource

canSort

protected boolean canSort()
Description copied from class: ContentFeatureSource
Determines if the datastore can natively perform sorting.

If the subclass can handle retyping natively it should override this method to return true. In this case it must do the retyping or throw an exception.

Not overriding this method or returning false will cause an exception to be thrown when the query specifies sorting.

Overrides:
canSort in class ContentFeatureSource

canRetype

protected boolean canRetype()
Description copied from class: ContentFeatureSource
Determines if the datasatore can natively perform "retyping" which includes limiting the number of attributes returned and reordering of those attributes

If the subclass can handle retyping natively it should override this method to return true. In this case it must do the retyping or throw an exception.

Not overriding this method or returning false will cause the feature reader created by the subclass to be wrapped in a retyping feature reader when the query specifies a retype.

TODO: link to feature decorator

Overrides:
canRetype in class ContentFeatureSource

canLimit

protected boolean canLimit()
Description copied from class: ContentFeatureSource
Determines if the datastore can natively limit the number of features returned in a query.

If the subclass can handle a map feature cap natively then it should override this method to return true. In this case it must do the cap or throw an exception.

Not overriding this method or returning false will case the feature reader created by the subclass to be wrapped in a max feature capping decorator when the query specifies a max feature cap.

Overrides:
canLimit in class ContentFeatureSource
See Also:
MaxFeatureReader

canOffset

protected boolean canOffset()
Description copied from class: ContentFeatureSource
Determines if the datastore can natively skip the first offset number of features returned in a query.

If the subclass can handle a map feature cap natively then it should override this method to return true. In this case it must do the cap or throw an exception.

Not overriding this method or returning false will case the feature reader created by the subclass to be be accesset offset times before being returned to the caller.

Overrides:
canOffset in class ContentFeatureSource

getReaderInternal

protected FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getReaderInternal(Query query)
                                                                                                                          throws java.io.IOException
Description copied from class: ContentFeatureSource
Subclass method for returning a native reader from the datastore.

It is important to note that if the native reader intends to handle any of the following natively:

Then it *must* set the corresonding flags to true:

Specified by:
getReaderInternal in class ContentFeatureSource
Throws:
java.io.IOException

handleVisitor

protected boolean handleVisitor(Query query,
                                org.opengis.feature.FeatureVisitor visitor)
                         throws java.io.IOException
Description copied from class: ContentFeatureSource
Subclass method which allows subclasses to natively handle a visitor.

Subclasses would override this method and return true in cases where the specific visitor could be handled without iterating over the entire result set of query. An example would be handling visitors that calculate aggregate values.

Overrides:
handleVisitor in class ContentFeatureSource
Parameters:
query - The query being made.
visitor - The visitor to
Returns:
true if the visitor can be handled natively, otherwise false.
Throws:
java.io.IOException

getWriterInternal

protected FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getWriterInternal(Query query,
                                                                                                                                 int flags)
                                                                                                                          throws java.io.IOException
Description copied from class: ContentFeatureStore
Subclass method for returning a native writer from the datastore.

It is important to note that if the native writer intends to handle any of the following natively:

Then it *must* set the corresponding flags to true:

Specified by:
getWriterInternal in class ContentFeatureStore
Throws:
java.io.IOException

modifyFeatures

public void modifyFeatures(org.opengis.feature.type.AttributeDescriptor[] types,
                           java.lang.Object[] values,
                           org.opengis.filter.Filter filter)
                    throws java.io.IOException
Description copied from class: ContentFeatureStore
Modifies/updates the features of the store which match the specified filter.

This method operates by obtaining an updating feature writer based on the specified filter and writing the updated values to it.

The filter must not be null, in this case this method will throw an IllegalArgumentException.

Specified by:
modifyFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
modifyFeatures in class ContentFeatureStore
Parameters:
types - The attributes to modify.
values - The values to put in the attribute types.
filter - An OGC filter to note which attributes to modify.
Throws:
java.io.IOException - if the attribute and object arrays are not eqaul length, if the object types do not match the attribute types, or if there are backend errors.

removeFeatures

public void removeFeatures(org.opengis.filter.Filter filter)
                    throws java.io.IOException
Description copied from class: ContentFeatureStore
Removes the features from the store which match the specified filter.

This method operates by obtaining an updating feature writer based on the specified filter and removing every feature from it.

The filter must not be null, in this case this method will throw an IllegalArgumentException.

Specified by:
removeFeatures in interface FeatureStore<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
Overrides:
removeFeatures in class ContentFeatureStore
Parameters:
filter - An OpenGIS filter; specifies which features to remove.
Throws:
java.io.IOException - If anything goes wrong.


Copyright © 1996-2010 Geotools. All Rights Reserved.