|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.data.postgis.VersionedPostgisDataStore
public class VersionedPostgisDataStore
Postgis datastore with versioning support. On the implementation level, this subclass basically acts as a mapper between the base class, that sees the data structures as how they really are, and the outside view, that hides versioning columns and extra versioning tables from feature types.
Assumptions made by the data store:
Field Summary | |
---|---|
static java.lang.String |
DIRTYTYPES
Key used to store the feature types touched by the current transaction |
protected org.opengis.filter.FilterFactory2 |
ff
The filter factory used for all filter operations |
protected FeatureListenerManager |
listenerManager
Manages listener lists for FeatureSource |
protected static java.util.logging.Logger |
LOGGER
The logger for the postgis module. |
static java.lang.String |
TBL_CHANGESETS
|
static java.lang.String |
TBL_TABLESCHANGED
|
static java.lang.String |
TBL_VERSIONEDTABLES
|
protected java.util.Map |
versionedMap
Holds boolean markers used to determine wheter a table is versioned or not (caching to increase speed since isVersioned() check is required in every other public API) |
protected org.geotools.data.postgis.WrappedPostgisDataStore |
wrapped
The wrapped postgis datastore that we leverage for most operations |
Fields inherited from interface org.geotools.data.VersioningDataStore |
---|
AUTHOR, MESSAGE |
Constructor Summary | |
---|---|
VersionedPostgisDataStore(javax.sql.DataSource dataSource)
|
|
VersionedPostgisDataStore(javax.sql.DataSource dataSource,
java.lang.String namespace)
|
|
VersionedPostgisDataStore(javax.sql.DataSource dataSource,
java.lang.String schema,
java.lang.String namespace)
|
|
VersionedPostgisDataStore(javax.sql.DataSource dataSource,
java.lang.String schema,
java.lang.String namespace,
int optimizeMode)
|
Method Summary | |
---|---|
protected void |
checkVersioningDataStructures()
Makes sure the required versioning data structures are available in the database |
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. |
protected void |
execute(java.sql.Statement st,
java.lang.String sql)
Logs the sql at info level, then executes the command |
protected java.sql.ResultSet |
executeQuery(java.sql.Statement st,
java.lang.String sql)
Logs the sql at info level, then executes the command |
protected JDBCDataStoreConfig |
getConfig()
|
java.sql.Connection |
getConnection(Transaction t)
Gets a connection for the provided transaction. |
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)
Delegates to getFeatureSource(String) with
name.getLocalPart() |
FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> |
getFeatureSource(java.lang.String typeName)
Access a FeatureSource |
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. |
protected FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> |
getFeatureWriterInternal(java.lang.String typeName,
org.opengis.filter.Filter filter,
Transaction transaction,
boolean append)
Returns either a standard feature writer, or a pure append feature writer |
FIDMapper |
getFIDMapper(java.lang.String tableName)
|
ServiceInfo |
getInfo()
Information about this service. |
long |
getLastRevision()
Returns the last revision of the repository |
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)
Returns a set of feature ids for features that where modified, created or deleted between version1 and version2 and that matched the specified filter at least in one revision between version1 and version2. |
java.lang.String[] |
getModifiedFeatureTypes(java.lang.String version1,
java.lang.String version2)
Returns a list of type names modified between version1 and
version2 , with the first version excluded. |
java.util.List<org.opengis.feature.type.Name> |
getNames()
Returns the same list of names than getTypeNames() meaning the
returned Names have no namespace set. |
org.opengis.feature.simple.SimpleFeatureType |
getSchema(org.opengis.feature.type.Name name)
Delegates to getSchema(String) with name.getLocalPart() |
org.opengis.feature.simple.SimpleFeatureType |
getSchema(java.lang.String typeName)
Retrieve FeatureType metadata by typeName . |
java.lang.String[] |
getTypeNames()
Retrieves a list of of the available FeatureTypes. |
static java.lang.String |
getVFCTableName(java.lang.String vfcTypeName)
Given a versioned feature collection view name returns the base table name |
static java.lang.String |
getVFCViewName(java.lang.String typeName)
Given a type name returns the name of the versioned feature collection view associated to it |
FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> |
getView(Query query)
Access a FeatureSource |
boolean |
isVersioned(java.lang.String typeName)
Returns true if the specified feature type is versioned, false otherwise |
protected boolean |
isVersioned(java.lang.String typeName,
Transaction transaction)
Checks wheter a type name is versioned or not. |
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)
|
protected org.opengis.filter.Filter |
transformFidFilter(java.lang.String featureTypeName,
org.opengis.filter.Filter filter)
Takes a fid filter with external fids and turns it into a set of filters against internal feature type attributes, that is, an equivalent filter that can run against the internal, versioned feature type |
void |
updateSchema(org.opengis.feature.type.Name typeName,
org.opengis.feature.simple.SimpleFeatureType featureType)
Delegates to updateSchema(String, SimpleFeatureType) with
name.getLocalPart() |
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, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.util.logging.Logger LOGGER
public static final java.lang.String TBL_VERSIONEDTABLES
public static final java.lang.String TBL_TABLESCHANGED
public static final java.lang.String TBL_CHANGESETS
public static final java.lang.String DIRTYTYPES
protected org.geotools.data.postgis.WrappedPostgisDataStore wrapped
protected java.util.Map versionedMap
protected org.opengis.filter.FilterFactory2 ff
protected FeatureListenerManager listenerManager
Constructor Detail |
---|
public VersionedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String schema, java.lang.String namespace, int optimizeMode) throws java.io.IOException
java.io.IOException
public VersionedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String schema, java.lang.String namespace) throws java.io.IOException
java.io.IOException
public VersionedPostgisDataStore(javax.sql.DataSource dataSource, java.lang.String namespace) throws java.io.IOException
java.io.IOException
public VersionedPostgisDataStore(javax.sql.DataSource dataSource) throws java.io.IOException
java.io.IOException
Method Detail |
---|
protected JDBCDataStoreConfig getConfig()
public ServiceInfo getInfo()
DataAccess
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).
getInfo
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
public java.lang.String[] getTypeNames() throws java.io.IOException
DataStore
This is simply a list of the FeatureType names as aquiring the actual FeatureType schemas may be expensive.
Warning: this list may not be unique - the types may be in separate namespaces.
If you need to worry about such things please consider the use of the Catalog and CatalogEntry interface - many DataStores support this. getTypeNames is really a convience method for a Catalog.iterator() where the name of each entry is returned.
getTypeNames
in interface DataStore
java.io.IOException
public org.opengis.feature.simple.SimpleFeatureType getSchema(java.lang.String typeName) throws java.io.IOException
DataStore
typeName
.
Retrieves the Schema information as a FeatureType object.
getSchema
in interface DataStore
typeName
- typeName of requested FeatureType
java.io.IOException
- If typeName cannot be foundpublic void createSchema(org.opengis.feature.simple.SimpleFeatureType featureType) throws java.io.IOException
DataAccess
featureType
.
The provided featureType
we be accessable by the typeName
provided by featureType.getTypeName().
createSchema
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
featureType
- FetureType to add to DataStore
java.io.IOException
- If featureType cannot be createdpublic void updateSchema(java.lang.String typeName, org.opengis.feature.simple.SimpleFeatureType featureType) throws java.io.IOException
DataStore
The provided featureType should completely cover the existing schema. All attributes should be accounted for and the typeName should match.
Suggestions:
updateSchema
in interface DataStore
java.io.IOException
public FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureReader(Query query, Transaction trans) throws java.io.IOException
DataStore
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.
getFeatureReader
in interface DataStore
query
- Requested form of the returned Features and the filter used
to constraints the resultstrans
- Transaction this query operates against
java.io.IOException
public LockingManager getLockingManager()
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.
getLockingManager
in interface DataStore
null
, if the handling locking
in another fashion.public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriter(java.lang.String typeName, Transaction transaction) throws java.io.IOException
DataStore
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.
getFeatureWriter
in interface DataStore
typeName
- Indicates featureType to be modifiedtransaction
- Transaction to operates against
java.io.IOException
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
DataStore
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):
getFeatureWriter
in interface DataStore
typeName
- Indicates featureType to be modifiedfilter
- constraints used to limit the modificationtransaction
- Transaction this query operates against
java.io.IOException
protected FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterInternal(java.lang.String typeName, org.opengis.filter.Filter filter, Transaction transaction, boolean append) throws java.io.IOException, DataSourceException
java.io.IOException
DataSourceException
public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterAppend(java.lang.String typeName, Transaction transaction) throws java.io.IOException
DataStore
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.
getFeatureWriterAppend
in interface DataStore
typeName
- Indicates featureType to be modifiedtransaction
- Transaction to operates against
java.io.IOException
public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(java.lang.String typeName) throws java.io.IOException
DataStore
The resulting FeatureSource
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");
}
getFeatureSource
in interface DataStore
java.io.IOException
public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getView(Query query) throws java.io.IOException, SchemaException
DataStore
The provided Query does not need to completely cover the existing
schema for Query.getTypeName(). The result will mostly likely only be
a FeatureSource
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.
getView
in interface DataStore
query
- Query.getTypeName() locates FeatureType being viewed
java.io.IOException
- If FeatureSourceSchemaException
- If fetureType is not covered by existing schemapublic boolean isVersioned(java.lang.String typeName) throws java.io.IOException
isVersioned
in interface VersioningDataStore
typeName
-
java.io.IOException
public void setVersioned(java.lang.String typeName, boolean versioned, java.lang.String author, java.lang.String message) throws java.io.IOException
setVersioned
in interface VersioningDataStore
typeName
- the type name that must be changedversioned
- if true, the type gets version enabled, if false versioning is disabledt
- the transaction used to performe version enabling. It shall contain user and
commit message as properties.
java.io.IOException
protected boolean isVersioned(java.lang.String typeName, Transaction transaction) throws java.io.IOException
typeName
- the feature type to checktransaction
- a transaction, or null if you don't have one (use null to avoid a new revision
being created for this operation)
java.io.IOException
public java.sql.Connection getConnection(Transaction t) throws java.io.IOException
java.io.IOException
public boolean isVersionedFeatureCollection(java.lang.String typeName) throws java.io.IOException
java.io.IOException
public void setWKBEnabled(boolean enabled)
enabled
- PostgisDataStore.setWKBEnabled(boolean)
public void setLooseBbox(boolean enabled)
enabled
- PostgisDataStore.setWKBEnabled(boolean)
public FIDMapper getFIDMapper(java.lang.String tableName) throws java.io.IOException
java.io.IOException
public long getLastRevision() throws java.io.IOException
java.io.IOException
public java.lang.String[] getModifiedFeatureTypes(java.lang.String version1, java.lang.String version2) throws java.io.IOException
version1
and
version2
, with the first version excluded.
version1
- the first versionversion2
- the second version, which may be null, if you need to refer the latest version
java.io.IOException
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
The semantics is a little complex, so here is a more detailed explaination:
v1 v2 | | f1 ======]..........................|........... Not returned f2 ======][-------------------------|----------- Not returned f3 ======|==].......................|........... Returned (deleted) f4 ======|==][----------------------|---]....... Returned (modified) f5 ......|.[=======]................|........... Returned (created/deleted) f5 ......[=========]................|........... Returned (deleted) f5 ......[-------------------][=====|====]...... Returned (modified) f6 [-----|----][=============][-----|----------- Returned (modified)Legend:
version1
- -
the first revisionversion2
- -
the second revision, or null if you want the diff between version1 and currentfilter
- a filter to limit the features that must be taken into considerationusers
- an eventual list of user ids that can be used to further filter the features,
only features touched by any of these users will betransaction
-
java.io.IOException
IllegalAttributeException
java.util.NoSuchElementException
protected void checkVersioningDataStructures() throws java.io.IOException
java.io.IOException
public static java.lang.String getVFCViewName(java.lang.String typeName)
typeName
-
public static java.lang.String getVFCTableName(java.lang.String vfcTypeName) throws java.io.IOException
vfcTypeName
-
java.io.IOException
protected void execute(java.sql.Statement st, java.lang.String sql) throws java.sql.SQLException
st
- sql
-
java.sql.SQLException
protected java.sql.ResultSet executeQuery(java.sql.Statement st, java.lang.String sql) throws java.sql.SQLException
st
- sql
-
java.sql.SQLException
protected org.opengis.filter.Filter transformFidFilter(java.lang.String featureTypeName, org.opengis.filter.Filter filter) throws java.io.IOException, FactoryRegistryException
featureTypeName
- filter
-
java.io.IOException
FactoryRegistryException
public void dispose()
DataAccess
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.
dispose
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
public FeatureSource<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureSource(org.opengis.feature.type.Name typeName) throws java.io.IOException
getFeatureSource(String)
with
name.getLocalPart()
getFeatureSource
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
java.io.IOException
DataAccess.getFeatureSource(Name)
public java.util.List<org.opengis.feature.type.Name> getNames() throws java.io.IOException
getTypeNames()
meaning the
returned Names have no namespace set.
getNames
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
java.io.IOException
DataAccess.getNames()
public org.opengis.feature.simple.SimpleFeatureType getSchema(org.opengis.feature.type.Name name) throws java.io.IOException
getSchema(String)
with name.getLocalPart()
getSchema
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
name
- Type name a the resource from getNames()
java.io.IOException
DataAccess.getSchema(Name)
public void updateSchema(org.opengis.feature.type.Name typeName, org.opengis.feature.simple.SimpleFeatureType featureType) throws java.io.IOException
updateSchema(String, SimpleFeatureType)
with
name.getLocalPart()
updateSchema
in interface DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>
java.io.IOException
- if the operation failedDataAccess.getFeatureSource(Name)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |