deegree 2.3 (2010/04/09 10:10 build-4-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  Connection acquireConnection()
          Returns the database connection requested for.
 DatastoreTransaction acquireTransaction()
          Acquires transactional access to the datastore.
 void appendGeometryColumnGet(StatementBuffer query, String tableAlias, String column)
           
 SQLFunctionCall buildSRSTransformCall(MappedGeometryPropertyType geoProperty, String targetSRS)
          Returns an SQLFunctionCall that refers to the given MappedGeometryPropertyType in the specified target SRS using a database specific SQL function.
 String buildSRSTransformCall(String geomIdentifier, int nativeSRSCode)
          Builds an SQL fragment that converts the given geometry to the specified SRS.
(package private)  String checkTransformation(MappedGeometryPropertyType pt, 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(Object value, CoordinateSystem targetSRS, Connection conn)
          Converts a database specific geometry Object from the ResultSet to a deegree Geometry.
abstract  Object convertDeegreeToDBGeometry(Geometry geometry, int nativeSRSCode, Connection conn)
          Converts a deegree Geometry to a database specific geometry Object.
 Object convertFromDBType(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.
 Set<FeatureId> determineFidsToLock(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(Connection conn, String tableName, String columnName)
          Returns the maximum (integer) value stored in a certain table column.
 int getNativeSRSCode(String srsName)
          Returns the database specific code for the given SRS name.
 Object getSequenceCurrValPlusOffset(Connection conn, String sequence, int offset)
          Overwrite this to enable the datastore to fetch the current value (plus an offset) of a SQL sequence.
 Object getSequenceNextVal(Connection conn, String sequence)
          Overwrite this to enable the datastore to fetch the next value of a SQL sequence.
 WhereBuilder getWhereBuilder(MappedFeatureType[] rootFts, 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, 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).
 PreparedStatement prepareStatement(Connection conn, StatementBuffer statementBuffer)
          Converts the StatementBuffer into a PreparedStatement, which is initialized and ready to be performed.
 void releaseConnection(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,
                                    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,
                                         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 Set<FeatureId> determineFidsToLock(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(Object value,
                                                    CoordinateSystem targetSRS,
                                                    Connection conn)
                                             throws SQLException
Converts a database specific geometry Object from the ResultSet to a deegree Geometry.

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

convertDeegreeToDBGeometry

public abstract Object convertDeegreeToDBGeometry(Geometry geometry,
                                                  int nativeSRSCode,
                                                  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 Connection acquireConnection()
                                throws DatastoreException
Returns the database connection requested for.

Returns:
Connection
Throws:
DatastoreException

releaseConnection

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

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

prepareStatement

public PreparedStatement prepareStatement(Connection conn,
                                          StatementBuffer statementBuffer)
                                   throws 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:
SQLException - if a JDBC related error occurs
DatastoreException

convertFromDBType

public Object convertFromDBType(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 Object getSequenceNextVal(Connection conn,
                                 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 Object getSequenceCurrValPlusOffset(Connection conn,
                                           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(Connection conn,
                       String tableName,
                       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,
                                             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 String buildSRSTransformCall(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(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

String checkTransformation(MappedGeometryPropertyType pt,
                           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,
                                    String tableAlias,
                                    String column)

deegree 2.3 (2010/04/09 10:10 build-4-official)

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