deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.io.datastore.sql
Class AbstractSQLDatastore

java.lang.Object
  extended by org.deegree.io.datastore.Datastore
      extended by org.deegree.io.datastore.sql.AbstractSQLDatastore
Direct Known Subclasses:
GenericSQLDatastore, MySQLDatastore, OracleDatastore, PostGISDatastore

public abstract class AbstractSQLDatastore
extends Datastore

This abstract class implements the common functionality of Datastore implementations that use SQL databases as backend.

Version:
$Revision: 20115 $, $Date: 2009-10-14 10:57:39 +0200 (Mi, 14 Okt 2009) $
Author:
Markus Schneider , last edited by: $Author: aschmitz $
See Also:
QueryHandler

Field Summary
protected  DBConnectionPool pool
          Pool of database connections.
protected static int SRS_UNDEFINED
          Database specific SRS code for an unspecified SRS.
 
Constructor Summary
AbstractSQLDatastore()
           
 
Method Summary
protected  java.sql.Connection acquireConnection()
          Returns the database connection requested for.
 DatastoreTransaction acquireTransaction()
          Acquires transactional access to the datastore.
 void appendGeometryColumnGet(StatementBuffer query, java.lang.String tableAlias, java.lang.String column)
           
 SQLFunctionCall buildSRSTransformCall(MappedGeometryPropertyType geoProperty, java.lang.String targetSRS)
          Returns an SQLFunctionCall that refers to the given MappedGeometryPropertyType in the specified target SRS using a database specific SQL function.
 java.lang.String buildSRSTransformCall(java.lang.String geomIdentifier, int nativeSRSCode)
          Builds an SQL fragment that converts the given geometry to the specified SRS.
(package private)  java.lang.String checkTransformation(MappedGeometryPropertyType pt, java.lang.String queriedSrs)
          Checks whether the (native) coordinate transformation of the specified geometry property to the given SRS is possible (and necessary), i.e.
 void close()
          Closes the datastore so it can free dependent resources.
 void configure(DatastoreConfiguration datastoreConfiguration)
          Configures the datastore with the supplied configuration.
abstract  Geometry convertDBToDeegreeGeometry(java.lang.Object value, CoordinateSystem targetSRS, java.sql.Connection conn)
          Converts a database specific geometry Object from the ResultSet to a deegree Geometry.
abstract  java.lang.Object convertDeegreeToDBGeometry(Geometry geometry, int nativeSRSCode, java.sql.Connection conn)
          Converts a deegree Geometry to a database specific geometry Object.
 java.lang.Object convertFromDBType(java.lang.Object rsObject, int sqlTypeCode)
          Converts the given object from a java.sql.ResultSet column to the common type to be used as a feature property.
protected  SQLTransaction createTransaction()
          Creates a new SQLTransaction that provides transactional access.
 java.util.Set<FeatureId> determineFidsToLock(java.util.List<Lock> requestParts)
          Determines the ids of all features to be locked by the given parts of a LockFeature request, this includes all descendant and super features of the targeted features as well.
 AnnotationDocument getAnnotationParser()
          Returns the datastore specific annotation parser.
 int getMaxValue(java.sql.Connection conn, java.lang.String tableName, java.lang.String columnName)
          Returns the maximum (integer) value stored in a certain table column.
 int getNativeSRSCode(java.lang.String srsName)
          Returns the database specific code for the given SRS name.
 java.lang.Object getSequenceCurrValPlusOffset(java.sql.Connection conn, java.lang.String sequence, int offset)
          Overwrite this to enable the datastore to fetch the current value (plus an offset) of a SQL sequence.
 java.lang.Object getSequenceNextVal(java.sql.Connection conn, java.lang.String sequence)
          Overwrite this to enable the datastore to fetch the next value of a SQL sequence.
 WhereBuilder getWhereBuilder(MappedFeatureType[] rootFts, java.lang.String[] aliases, Filter filter, SortProperty[] sortProperties, TableAliasGenerator aliasGenerator, VirtualContentProvider vcProvider)
          Overwrite this to return a database specific (spatial capable) WhereBuilder implementation.
 FeatureCollection performQuery(Query query, MappedFeatureType[] rootFts)
          Performs a query against the datastore.
protected  FeatureCollection performQuery(Query query, MappedFeatureType[] rootFts, java.sql.Connection conn)
          Performs a Query against the datastore.
 FeatureCollection performQuery(Query query, MappedFeatureType[] rootFts, DatastoreTransaction context)
          Performs a query against the datastore (in the given transaction context).
 java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, StatementBuffer statementBuffer)
          Converts the StatementBuffer into a PreparedStatement, which is initialized and ready to be performed.
 void releaseConnection(java.sql.Connection conn)
          Releases the connection.
 void releaseTransaction(DatastoreTransaction ta)
          Returns the transaction to the datastore.
 
Methods inherited from class org.deegree.io.datastore.Datastore
bindSchema, canTransformTo, getConfiguration, getFeatureType, getSchemas, transformQuery, transformResult
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SRS_UNDEFINED

protected static final int SRS_UNDEFINED
Database specific SRS code for an unspecified SRS.

See Also:
Constant Field Values

pool

protected DBConnectionPool pool
Pool of database connections.

Constructor Detail

AbstractSQLDatastore

public AbstractSQLDatastore()
Method Detail

getAnnotationParser

public AnnotationDocument getAnnotationParser()
Description copied from class: Datastore
Returns the datastore specific annotation parser.

Specified by:
getAnnotationParser in class Datastore
Returns:
the datastore specific annotation parser

configure

public void configure(DatastoreConfiguration datastoreConfiguration)
               throws DatastoreException
Description copied from class: Datastore
Configures the datastore with the supplied configuration.

Overrides:
configure in class Datastore
Parameters:
datastoreConfiguration - configuration
Throws:
DatastoreException

close

public void close()
           throws DatastoreException
Description copied from class: Datastore
Closes the datastore so it can free dependent resources.

Specified by:
close in class Datastore
Throws:
DatastoreException

getWhereBuilder

public WhereBuilder getWhereBuilder(MappedFeatureType[] rootFts,
                                    java.lang.String[] aliases,
                                    Filter filter,
                                    SortProperty[] sortProperties,
                                    TableAliasGenerator aliasGenerator,
                                    VirtualContentProvider vcProvider)
                             throws DatastoreException
Overwrite this to return a database specific (spatial capable) WhereBuilder implementation.

Parameters:
rootFts - involved (requested) feature types
aliases - aliases for the feature types, may be null
filter - filter that restricts the matched features
sortProperties - sort criteria for the result, may be null or empty
aliasGenerator - used to generate unique table aliases
vcProvider -
Returns:
WhereBuilder implementation suitable for this datastore
Throws:
DatastoreException

performQuery

public FeatureCollection performQuery(Query query,
                                      MappedFeatureType[] rootFts)
                               throws DatastoreException,
                                      UnknownCRSException
Description copied from class: Datastore
Performs a query against the datastore.

Specified by:
performQuery in class Datastore
Parameters:
query - query to be performed
rootFts - the root feature types that are queried, more than one type means that the types are joined
Returns:
requested feature instances
Throws:
DatastoreException
UnknownCRSException

performQuery

public FeatureCollection performQuery(Query query,
                                      MappedFeatureType[] rootFts,
                                      DatastoreTransaction context)
                               throws DatastoreException,
                                      UnknownCRSException
Description copied from class: Datastore
Performs a query against the datastore (in the given transaction context).

Specified by:
performQuery in class Datastore
Parameters:
query - query to be performed
rootFts - the root feature types that are queried, more than one type means that the types are joined
context - context (used to specify the JDBCConnection, for example)
Returns:
requested feature instances
Throws:
DatastoreException
UnknownCRSException

performQuery

protected FeatureCollection performQuery(Query query,
                                         MappedFeatureType[] rootFts,
                                         java.sql.Connection conn)
                                  throws DatastoreException,
                                         UnknownCRSException
Performs a Query against the datastore.

Note that this method is responsible for the coordinate system tranformation of the input Query and the output FeatureCollection.

Parameters:
query - query to be performed
rootFts - the root feature types that are queried, more than one type means that the types are joined
conn - JDBC connection to use
Returns:
requested feature instances
Throws:
DatastoreException
UnknownCRSException

acquireTransaction

public DatastoreTransaction acquireTransaction()
                                        throws DatastoreException
Acquires transactional access to the datastore. There's only one active transaction per datastore instance allowed at a time.

Overrides:
acquireTransaction in class Datastore
Returns:
transaction object that allows to perform transaction operations on the datastore
Throws:
DatastoreException

createTransaction

protected SQLTransaction createTransaction()
                                    throws DatastoreException
Creates a new SQLTransaction that provides transactional access.

Returns:
new SQLTransaction instance
Throws:
DatastoreException

releaseTransaction

public void releaseTransaction(DatastoreTransaction ta)
                        throws DatastoreException
Returns the transaction to the datastore. This makes the transaction available to other clients again (via acquireTransaction). Underlying resources (such as JDBCConnections are freed).

The transaction should be terminated, i.e. commit() or rollback() must have been called before.

Overrides:
releaseTransaction in class Datastore
Parameters:
ta - the DatastoreTransaction to be returned
Throws:
DatastoreException

determineFidsToLock

public java.util.Set<FeatureId> determineFidsToLock(java.util.List<Lock> requestParts)
                                             throws DatastoreException
Description copied from class: Datastore
Determines the ids of all features to be locked by the given parts of a LockFeature request, this includes all descendant and super features of the targeted features as well.

Overrides:
determineFidsToLock in class Datastore
Parameters:
requestParts - the parts of a LockFeature request that this Datastore is responsible for
Returns:
the ids of all features that have to be locked
Throws:
DatastoreException

convertDBToDeegreeGeometry

public abstract Geometry convertDBToDeegreeGeometry(java.lang.Object value,
                                                    CoordinateSystem targetSRS,
                                                    java.sql.Connection conn)
                                             throws java.sql.SQLException
Converts a database specific geometry Object from the ResultSet to a deegree Geometry.

Parameters:
value -
targetSRS -
conn -
Returns:
corresponding deegree geometry
Throws:
java.sql.SQLException

convertDeegreeToDBGeometry

public abstract java.lang.Object convertDeegreeToDBGeometry(Geometry geometry,
                                                            int nativeSRSCode,
                                                            java.sql.Connection conn)
                                                     throws DatastoreException
Converts a deegree Geometry to a database specific geometry Object.

Parameters:
geometry -
nativeSRSCode -
conn -
Returns:
corresponding database specific geometry object
Throws:
DatastoreException

acquireConnection

protected java.sql.Connection acquireConnection()
                                         throws DatastoreException
Returns the database connection requested for.

Returns:
Connection
Throws:
DatastoreException

releaseConnection

public void releaseConnection(java.sql.Connection conn)
                       throws DatastoreException
Releases the connection.

Parameters:
conn - connection to be released.
Throws:
DatastoreException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.sql.Connection conn,
                                                   StatementBuffer statementBuffer)
                                            throws java.sql.SQLException,
                                                   DatastoreException
Converts the StatementBuffer into a PreparedStatement, which is initialized and ready to be performed.

Parameters:
conn - connection to be used to create the PreparedStatement
statementBuffer -
Returns:
the PreparedStatment, ready to be performed
Throws:
java.sql.SQLException - if a JDBC related error occurs
DatastoreException

convertFromDBType

public java.lang.Object convertFromDBType(java.lang.Object rsObject,
                                          int sqlTypeCode)
                                   throws DatastoreException
Converts the given object from a java.sql.ResultSet column to the common type to be used as a feature property.

Parameters:
rsObject -
sqlTypeCode -
Returns:
an object that is suitable for a table column of the specified SQL type
Throws:
DatastoreException

getSequenceNextVal

public java.lang.Object getSequenceNextVal(java.sql.Connection conn,
                                           java.lang.String sequence)
                                    throws DatastoreException
Overwrite this to enable the datastore to fetch the next value of a SQL sequence.

Parameters:
conn - JDBC connection to be used.
sequence - name of the SQL sequence.
Returns:
next value of the given SQL sequence
Throws:
DatastoreException - if the value could not be retrieved

getSequenceCurrValPlusOffset

public java.lang.Object getSequenceCurrValPlusOffset(java.sql.Connection conn,
                                                     java.lang.String sequence,
                                                     int offset)
                                              throws DatastoreException
Overwrite this to enable the datastore to fetch the current value (plus an offset) of a SQL sequence.

Parameters:
conn - JDBC connection to be used.
sequence - name of the SQL sequence
offset - offset added to the sequence value
Returns:
next value of the given SQL sequence
Throws:
DatastoreException - if the value could not be retrieved

getMaxValue

public int getMaxValue(java.sql.Connection conn,
                       java.lang.String tableName,
                       java.lang.String columnName)
                throws IdGenerationException
Returns the maximum (integer) value stored in a certain table column.

Parameters:
conn - JDBC connection to be used
tableName - name of the table
columnName - name of the column
Returns:
the maximum value
Throws:
IdGenerationException - if the value could not be retrieved

buildSRSTransformCall

public SQLFunctionCall buildSRSTransformCall(MappedGeometryPropertyType geoProperty,
                                             java.lang.String targetSRS)
                                      throws DatastoreException
Returns an SQLFunctionCall that refers to the given MappedGeometryPropertyType in the specified target SRS using a database specific SQL function.

Parameters:
geoProperty - geometry property
targetSRS - target spatial reference system (usually "EPSG:XYZ")
Returns:
an SQLFunctionCall that refers to the geometry in the specified srs
Throws:
DatastoreException

buildSRSTransformCall

public java.lang.String buildSRSTransformCall(java.lang.String geomIdentifier,
                                              int nativeSRSCode)
                                       throws DatastoreException
Builds an SQL fragment that converts the given geometry to the specified SRS.

Parameters:
geomIdentifier -
nativeSRSCode -
Returns:
an SQL fragment that converts the given geometry to the specified SRS
Throws:
DatastoreException

getNativeSRSCode

public int getNativeSRSCode(java.lang.String srsName)
                     throws DatastoreException
Returns the database specific code for the given SRS name.

Parameters:
srsName - spatial reference system name (usually "EPSG:XYZ")
Returns:
the database specific SRS code, or -1 if no corresponding native code is known
Throws:
DatastoreException

checkTransformation

java.lang.String checkTransformation(MappedGeometryPropertyType pt,
                                     java.lang.String queriedSrs)
                               throws DatastoreException
Checks whether the (native) coordinate transformation of the specified geometry property to the given SRS is possible (and necessary), i.e. If this is not the case, a DatastoreException is thrown to indicate the problem.

Parameters:
pt -
queriedSrs -
Returns:
the srs to transform to, or null, if transformation is unnecessary
Throws:
DatastoreException

appendGeometryColumnGet

public void appendGeometryColumnGet(StatementBuffer query,
                                    java.lang.String tableAlias,
                                    java.lang.String column)

deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org