|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.geotools.data.AbstractDataSource | +--org.geotools.data.postgis.PostgisDataSource
Connects to a Postgis database and returns properly formatted GML.
This standard class must exist for every supported datastore.
Simple Lockings Support:SELECT * FOR UPDATE
to lock individual rows
CREATE FUNCTION lockcheck(TEXT,TEXT) RETURNS TRIGGER AS
'/data1/Refractions/Projects/PostGIS/work_dave/postgis/libpostgis.so.0.8' LANGUAGE C;
This function will be built into postgis in the future.
CREATE TABLE geo_table (id int primary key,the_geom geometry, name text);
INSERT INTO geo_table VALUES (1, 'POINT(0 0)', 'dave');
INSERT INTO geo_table VALUES (2, 'POINT(1 0)', 'jody');
INSERT INTO geo_table VALUES (3, 'POINT(2 0)', 'brent');
INSERT INTO geo_table VALUES (4, 'POINT(3 0)', 'justin');
A locking table will be required:
CREATE TABLE geo_table_loc (id int, lock_key int, expires date);
CREATE TRIGGER locktrig_geo_table BEFORE UPDATE OR DELETE
ON geo_table FOR EACH ROW
EXECUTE PROCEDURE lockcheck('id','geo_table_loc');
BEGIN;
select geo_table where id=2 for update;
insert into geo_table_loc values (2, 666, '2100-1-1');
COMMIT;
Constructs a lock on row 2 with lock id 666. Select for update is still used
so as not to work against Postgres's normal row locking.
BEGIN;
select have_lock_for(666);
select have_lock_for(667);
select geo_table where id=1 for update;
select geo_table where id=2 for update;
update geo_table set name = 'nexus' where id =1;
update geo_table set name = 'tenderflake' where id =2;
COMMIT;
Multiple locks (666 and 667 above) are supported. You can modify rows (id 1 above) that are not locked,
or rows that you have a lock for (id 2 above); Select for update is still used.
DataSource knows enough information to create the locking table by itself - the lockcheck function if the only gotcha in this setup it will be another thing to add to Postgis.
The main advantage to this solution is that Locks are present across transactions and other applications can continue to use the database safely concurrently with DataSource access. These locks have an associated exparation date which the lockcheck function will compare to the start of the current transaction.
Nested Class Summary |
Nested classes inherited from class org.geotools.data.AbstractDataSource |
AbstractDataSource.MetaDataSupport |
Field Summary | |
private static AttributeTypeFactory |
attFactory
Factory to create Attributes |
(package private) java.util.Set |
authorization
|
private java.sql.Connection |
dbConnection
A postgis connection. |
static java.lang.String |
DEFAULT_FID_COLUMN
|
private SQLEncoderPostgis |
encoder
To create the sql where statement |
private java.lang.String |
fidColumn
the name of the column to use for the featureId |
private static com.vividsolutions.jts.geom.GeometryFactory |
geometryFactory
Factory for producing geometries (from JTS). |
private static com.vividsolutions.jts.io.WKTReader |
geometryReader
Well Known Text reader (from JTS). |
private static java.util.Map |
geometryTypeMap
|
private static com.vividsolutions.jts.io.WKTWriter |
geometryWriter
Well Known Text writer (from JTS). |
private static int |
HARD_MAX_FEATURES
The limit on a select statement. |
protected Lock |
lock
Gets the bounding box of this datasource using the default speed of this datasource as set by the implementer. |
private static java.util.logging.Logger |
LOGGER
The logger for the filter module. |
private int |
maxFeatures
The maximum features allowed by the server for any given response. |
private FeatureType |
schema
The maximum features allowed by the server for any given response. |
private static java.util.Map |
sqlTypeMap
|
private int |
srid
The srid of the data in the table. |
private java.lang.String |
tableName
A tablename. |
Fields inherited from class org.geotools.data.AbstractDataSource |
|
Constructor Summary | |
PostgisDataSource(java.sql.Connection dbConnection,
java.lang.String tableName)
Sets the table and datasource, rolls a new schema from the db. |
Method Summary | |
java.util.Set |
addFeatures(FeatureCollection collection)
Returns a feature collection, based on the passed filter. |
private java.lang.String |
addQuotes(java.lang.Object value)
Adds quotes to an object for storage in postgis. |
private static void |
closeResultSet(java.sql.ResultSet result)
Closes the result set. |
void |
commit()
Makes all transactions made since the previous commit/rollback permanent. |
private java.lang.String |
createFid(java.lang.String featureId)
|
protected DataSourceMetaData |
createMetaData()
Creates the a metaData object. |
private java.lang.String |
formatFid(Feature feature)
strips the tableName from the fid for those in the format featureName.3534 should maybe just strip out all alpha-numeric characters. |
private AttributeType[] |
getAttTypes(Query query)
|
boolean |
getAutoCommit()
Retrieves the current autoCommit mode for the current DataSource. |
private java.util.Set |
getFeatureIds(Query query)
Helper method used to aquire id numbers for query. |
void |
getFeatures(FeatureCollection collection,
Query query)
Loads features from the datasource into the passed collection, based on the passed query. |
static java.lang.String |
getFidColumn(java.sql.Connection dbConnection,
java.lang.String tableName)
Figures out what database column to use as the identifier for the feature. |
private java.util.Set |
getFidSet()
|
private static AttributeType |
getGeometryAttribute(java.sql.Connection dbConnection,
java.lang.String tableName,
java.lang.String columnName)
Returns an attribute type for a geometry column in a feature table. |
FeatureType |
getSchema()
Retrieves the featureType that features extracted from this datasource will be created with. |
private static void |
initMaps()
Initializes the mappings for mapping from sql columns to classes for attributes |
void |
lockFeatures()
Lock entire table - don't think this is supposed to prevent addsFeatures(). |
void |
lockFeatures(Filter filter)
Lock features refered to by filter. |
void |
lockFeatures(Query query)
Lock features refered to by Query |
private java.lang.String |
makeInsertSql(java.lang.String tableName,
Feature feature)
Creates a sql insert statement. |
private java.lang.String |
makeModifySql(AttributeType[] types,
java.lang.Object[] values,
java.lang.String whereStmt)
Creates a sql update statement. |
static FeatureType |
makeSchema(java.lang.String tableName,
java.sql.Connection dbConnection)
Creates a schema from the information in the tablename. |
static FeatureType |
makeSchema(java.lang.String tableName,
java.sql.Connection dbConnection,
java.lang.String fidColumnName)
Creates a schema from the information in the tablename. |
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. |
static int |
querySRID(java.sql.Connection dbConnection,
java.lang.String tableName)
Gets the srid from the geometry_columns table of the datasource. |
void |
removeFeatures(Filter filter)
Removes the features specified by the passed filter from the PostGIS database. |
void |
rollback()
Undoes all transactions made since the last commit or rollback. |
void |
setAuthorization(java.lang.String[] lockIds)
Provide Lock authorizations removeFeatures(), modifyFeatures() and unLockFeatures() operations. |
void |
setAutoCommit(boolean autoCommit)
Sets this datasources auto-commit mode to the given state. |
void |
setCurrentLock(Lock lock)
Configures lock operations to work against provided Lock. |
void |
setFeatures(FeatureCollection features)
Deletes the all the current Features of this datasource and adds the new collection. |
private void |
sql(java.lang.String statement)
|
void |
unLockFeatures(Query query)
Remove Locks held on Features, authorization must be held in order to unlock. |
Methods inherited from class org.geotools.data.AbstractDataSource |
abortLoading, getBounds, getFeatures, getFeatures, getFeatures, getFeatures, getMetaData, makeDefaultQuery |
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.TransactionalDataSource |
unLockFeatures, unLockFeatures |
Methods inherited from interface org.geotools.data.DataSource |
abortLoading, getBounds, getFeatures, getFeatures, getFeatures, getFeatures, getMetaData |
Field Detail |
private static java.util.Map sqlTypeMap
private static java.util.Map geometryTypeMap
private static final java.util.logging.Logger LOGGER
private static com.vividsolutions.jts.geom.GeometryFactory geometryFactory
private static com.vividsolutions.jts.io.WKTReader geometryReader
private static com.vividsolutions.jts.io.WKTWriter geometryWriter
private static final int HARD_MAX_FEATURES
public static final java.lang.String DEFAULT_FID_COLUMN
private static AttributeTypeFactory attFactory
private int maxFeatures
private int srid
private SQLEncoderPostgis encoder
private java.lang.String fidColumn
private FeatureType schema
private java.sql.Connection dbConnection
private java.lang.String tableName
protected Lock lock
java.util.Set authorization
Constructor Detail |
public PostgisDataSource(java.sql.Connection dbConnection, java.lang.String tableName) throws DataSourceException
dbConnection
- The datasource holding the table.tableName
- the name of the table that holds the features.
DataSourceException
- if there were problems constructing the
schema.Method Detail |
private static void initMaps()
public static FeatureType makeSchema(java.lang.String tableName, java.sql.Connection dbConnection) throws DataSourceException
tableName
- The name of the table that holds the features.dbConnection
- The connection to the database holding the table.
DataSourceException
- DOCUMENT ME!public static FeatureType makeSchema(java.lang.String tableName, java.sql.Connection dbConnection, java.lang.String fidColumnName) throws DataSourceException
tableName
- The name of the table that holds the features.dbConnection
- The connection to the database holding the table.fidColumnName
- the name of the column to use as the fid.
DataSourceException
- if there were problems reading sql or
making the schema.public static int querySRID(java.sql.Connection dbConnection, java.lang.String tableName) throws DataSourceException
dbConnection
- The connection to the database.tableName
- the name of the table to find the srid.
DataSourceException
- DOCUMENT ME!public static java.lang.String getFidColumn(java.sql.Connection dbConnection, java.lang.String tableName)
dbConnection
- The connection to the database.tableName
- The name of the table to get the id for.
private static AttributeType getGeometryAttribute(java.sql.Connection dbConnection, java.lang.String tableName, java.lang.String columnName) throws DataSourceException
dbConnection
- The JDBC connection.tableName
- The feature table name.columnName
- The geometry column name.
java.lang.Exception
- DOCUMENT ME!
DataSourceException
public java.lang.String makeSql(SQLUnpacker unpacker, Query query) throws DataSourceException
query
- the getFeature query - for the tableName, properties and
maxFeatures.
DataSourceException
- DOCUMENT ME!private AttributeType[] getAttTypes(Query query) throws DataSourceException
DataSourceException
private static void closeResultSet(java.sql.ResultSet result)
result
- The servlet request object.public void getFeatures(FeatureCollection collection, Query query) throws DataSourceException
getFeatures
in interface DataSource
getFeatures
in class AbstractDataSource
collection
- The collection to put the features into.query
- a datasource query object. It encapsulates requested
information, such as typeName, maxFeatures and filter.
DataSourceException
- For all data source errors.Query
private java.lang.String createFid(java.lang.String featureId)
public java.util.Set addFeatures(FeatureCollection collection) throws DataSourceException
addFeatures
in interface DataSource
addFeatures
in class AbstractDataSource
collection
- Add features to the PostGIS database.
DataSourceException
- if anything went wrong.private java.util.Set getFidSet() throws DataSourceException
DataSourceException
private java.lang.String makeInsertSql(java.lang.String tableName, Feature feature)
tableName
- the name of the feature table being inserted into.feature
- the feature to add.
private java.lang.String addQuotes(java.lang.Object value)
value
- The object to add quotes to.
public void removeFeatures(Filter filter) throws DataSourceException
removeFeatures
in interface DataSource
removeFeatures
in class AbstractDataSource
filter
- An OpenGIS filter; specifies which features to remove.
DataSourceException
- If anything goes wrong or if deleting is not
supported.public void modifyFeatures(AttributeType[] type, java.lang.Object[] value, Filter filter) throws DataSourceException
modifyFeatures
in interface DataSource
modifyFeatures
in class AbstractDataSource
type
- The attributes to modify.value
- The values to put in the attribute types.filter
- An OGC filter to note which attributes to modify.
DataSourceException
- 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.private java.lang.String formatFid(Feature feature)
feature
- DOCUMENT ME!
public void modifyFeatures(AttributeType type, java.lang.Object value, Filter filter) throws DataSourceException
modifyFeatures
in interface DataSource
modifyFeatures
in class AbstractDataSource
type
- The attributes to modify.value
- The values to put in the attribute types.filter
- An OGC filter to note which attributes to modify.
DataSourceException
- If modificaton is not supported, if the
object type do not match the attribute type.private java.lang.String makeModifySql(AttributeType[] types, java.lang.Object[] values, java.lang.String whereStmt) throws DataSourceException
types
- the attribute to be changed.values
- the value to change it to.whereStmt
- the feature to update.
DataSourceException
- DOCUMENT ME!public FeatureType getSchema() throws DataSourceException
getSchema
in interface DataSource
getSchema
in class AbstractDataSource
DataSourceException
- if there are any problems getting the
schema.public void setFeatures(FeatureCollection features) throws DataSourceException
DataSource
setFeatures
in interface DataSource
setFeatures
in class AbstractDataSource
features
- - the collection to be written
DataSourceException
- if there are any datasource errors.public void commit() throws DataSourceException
commit
in interface DataSource
commit
in class AbstractDataSource
DataSourceException
- if there are any datasource errors.setAutoCommit(boolean)
public void rollback() throws DataSourceException
rollback
in interface DataSource
rollback
in class AbstractDataSource
DataSourceException
- if there are problems with the datasource.setAutoCommit(boolean)
public void setAutoCommit(boolean autoCommit) throws DataSourceException
setAutoCommit
in interface DataSource
setAutoCommit
in class AbstractDataSource
autoCommit
- true to enable auto-commit mode,
false to disable it.
DataSourceException
- DOCUMENT ME!setAutoCommit(boolean)
public boolean getAutoCommit() throws DataSourceException
getAutoCommit
in interface DataSource
getAutoCommit
in class AbstractDataSource
DataSourceException
- if a datasource access error occurs.setAutoCommit(boolean)
protected DataSourceMetaData createMetaData()
createMetaData
in class AbstractDataSource
#MetaDataSupport
public void setCurrentLock(Lock lock)
setCurrentLock
in interface TransactionalDataSource
lock
- TransactionalDataSource.setCurrentLock(org.geotools.data.Lock)
public void lockFeatures() throws DataSourceException
lockFeatures
in interface TransactionalDataSource
DataSourceException
org.geotools.data.TransactionalDataSource#lock()
public void lockFeatures(Filter filter) throws DataSourceException
lockFeatures
in interface TransactionalDataSource
filter
-
DataSourceException
org.geotools.data.TransactionalDataSource#lock(org.geotools.filter.Filter)
public void lockFeatures(Query query) throws DataSourceException
lockFeatures
in interface TransactionalDataSource
query
-
DataSourceException
org.geotools.data.TransactionalDataSource#lock(org.geotools.data.Query)
private void sql(java.lang.String statement)
public void setAuthorization(java.lang.String[] lockIds)
Authorization is only provided for the current transaction. That is locks are not released - the transaction is ended.
setAuthorization
in interface TransactionalDataSource
lockIds
- LockIds for Long Transaction operationsTransactionalDataSource.setAuthorization(java.lang.String[])
private java.util.Set getFeatureIds(Query query)
query
-
public void unLockFeatures(Query query)
Detailed Description of removeLock.
unLockFeatures
in interface TransactionalDataSource
query
- Query describing features to unlock.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |