org.geotools.data.db2
Class DB2DataStore

Object
  extended by JDBC1DataStore
      extended by JDBC2DataStore
          extended by JDBCDataStore
              extended by DB2DataStore
All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>, DataStore

public class DB2DataStore
extends JDBCDataStore
implements DataStore

DB2 DataStore implementation.

Instances of this class should only be obtained via DB2DataStoreFactory.createDataStore or DataStoreFinder.getDataStore.

Author:
David Adler - IBM Corporation
Module:

Field Summary
 
Fields inherited from class JDBC2DataStore
dataSource
 
Fields inherited from class JDBC1DataStore
allowWriteOnVolatileFIDs, config, listenerManager, sqlNameEscape, transactionIsolation, TYPE_MAPPINGS, typeHandler
 
Constructor Summary
DB2DataStore(DataSource dataSource, JDBCDataStoreConfig config, String dbURL)
          The only supported constructor for a DB2DataStore.
 
Method Summary
protected  AttributeDescriptor buildAttributeType(ResultSet rs)
          Handles DB2-specific geometry types.
protected  FIDMapperFactory buildFIDMapperFactory(JDBCDataStoreConfig config)
          Creates a DB2-specific FIDMapperFactory.
protected  JDBCFeatureWriter createFeatureWriter(FeatureReader featureReader, QueryData queryData)
          Overrides the method in JDBCDataStore so that a DB2FeatureWriter is created.
protected  int determineSRID(String tableName, String geometryColumnName)
          Get the SRID associated with a geometry column.
protected  QueryData executeQuery(FeatureTypeInfo featureTypeInfo, String tableName, String sqlQuery, Transaction transaction, boolean forWrite)
          Overrides the method in JDBCDataStore because it includes PostGIS-specific handling to setAutoCommit(false) which causes problems for DB2 because the transaction is still uncommitted when the connection is closed.
 DataSource getDataSource()
           
 FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(SimpleFeatureType requestType, Filter filter, Transaction transaction)
          This is a public entry point to the DataStore.
 FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource(String typeName)
          Gets a DB2-specific feature source.
protected  FeatureTypeHandler getFeatureTypeHandler(JDBCDataStoreConfig config)
          Create a DB2-specific FeatureTypeHandler.
protected  AttributeIO getGeometryAttributeIO(AttributeDescriptor type, QueryData queryData)
          Gets the handler to convert a geometry database value to a JTS geometry.
 SQLBuilder getSqlBuilder(String typeName)
          Gets the DB2-specific SQL builder object.
 String getTableSchema()
          Gets the table schema associated with this data store.
 String[] getTypeNames()
          Gets the names of tables (types) that contain a spatial column.
 void refreshCatalog()
          Reloads the spatial catalog from the database.
 
Methods inherited from class JDBC2DataStore
createConnection, dispose, finalize
 
Methods inherited from class JDBC1DataStore
allowTable, allSameOrder, attributeNames, buildFIDMapper, buildSchema, createFeatureReader, createLockingManager, createSchema, determineFidColumnName, executeQuery, getAttributeIO, getAttributeTypes, getConcurrency, getConnection, getDatabaseSchemaName, getEnvelope, getFeatureReader, getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getFIDMapper, getFIDMapperFactory, getInfo, getJDBCFeatureReader, getLockingManager, getNames, getNameSpace, getResultSetType, getSchema, getSchema, getSqlNameEscape, getSupportedHints, getTransactionIsolation, getView, propertyNames, requireAutoCommit, setAutoCommit, setFIDMapper, setFIDMapperFactory, setSqlNameEscape, setTransactionIsolation, updateSchema, updateSchema
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface DataStore
getFeatureReader, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getLockingManager, getSchema, getView, updateSchema
 
Methods inherited from interface DataAccess
createSchema, dispose, getFeatureSource, getInfo, getNames, getSchema, updateSchema
 

Constructor Detail

DB2DataStore

public DB2DataStore(DataSource dataSource,
                    JDBCDataStoreConfig config,
                    String dbURL)
             throws IOException
The only supported constructor for a DB2DataStore. This constructor is mainly intended to be called from DB2DataStoreFactory.

Parameters:
connectionPool - the initialized DB2 connection pool
config - the JDBCDataStoreConfiguration
dbURL - the database URL of the form jdbc:db2://hostname:hostport/dbname
Throws:
IOException
Method Detail

getDataSource

public DataSource getDataSource()

buildAttributeType

protected AttributeDescriptor buildAttributeType(ResultSet rs)
                                          throws IOException
Handles DB2-specific geometry types. If it isn't one, just let the parent method handle it.

Overrides:
buildAttributeType in class JDBC1DataStore
Parameters:
rs - The ResultSet containing the result of a DatabaseMetaData.getColumns call.
Returns:
The AttributeType built from the ResultSet.
Throws:
IOException - If an error occurs processing the ResultSet.

buildFIDMapperFactory

protected FIDMapperFactory buildFIDMapperFactory(JDBCDataStoreConfig config)
Creates a DB2-specific FIDMapperFactory.

Overrides:
buildFIDMapperFactory in class JDBC1DataStore
Parameters:
config - not used.
Returns:
a DB2FIDMapperFactory

determineSRID

protected int determineSRID(String tableName,
                            String geometryColumnName)
                     throws IOException
Get the SRID associated with a geometry column.

The value returned is the EPSG coordinate system identifier, not the DB2 srs_id.

Overrides:
determineSRID in class JDBC1DataStore
Parameters:
tableName - The name of the table to get the SRID for.
geometryColumnName - The name of the geometry column within the table to get SRID for.
Returns:
The SRID for the geometry column or -1.
Throws:
IOException

getFeatureTypeHandler

protected FeatureTypeHandler getFeatureTypeHandler(JDBCDataStoreConfig config)
                                            throws IOException
Create a DB2-specific FeatureTypeHandler.

Overrides:
getFeatureTypeHandler in class JDBC1DataStore
Parameters:
config - a JDBCDataStoreConfig.
Returns:
a DB2FeatureTypeHandler.
Throws:
IOException - if the feature type handler could not be created.

getGeometryAttributeIO

protected AttributeIO getGeometryAttributeIO(AttributeDescriptor type,
                                             QueryData queryData)
Gets the handler to convert a geometry database value to a JTS geometry.

Specified by:
getGeometryAttributeIO in class JDBC1DataStore
Parameters:
type - not used.
queryData - not used.
Returns:
AttributIO

getSqlBuilder

public SQLBuilder getSqlBuilder(String typeName)
                         throws IOException
Gets the DB2-specific SQL builder object.

Overrides:
getSqlBuilder in class JDBC1DataStore
Parameters:
typeName - Name of the type to build the SQL for.
Returns:
DB2SQLBuilder
Throws:
IOException

getTypeNames

public String[] getTypeNames()
                      throws IOException
Gets the names of tables (types) that contain a spatial column. Note that there is still an issue concerning the ambiguity of spatial tables that have the same table name but different table schema names.

Specified by:
getTypeNames in interface DataStore
Overrides:
getTypeNames in class JDBC1DataStore
Returns:
Array of type names as Strings.
Throws:
IOException - if the spatial catalog can not be accessed.
See Also:
org.geotools.data.DataStore#getFeatureTypes()

refreshCatalog

public void refreshCatalog()
                    throws IOException
Reloads the spatial catalog from the database.

This is useful in case anything changed after the datastore was initialized.

Throws:
IOException
SQLException

getTableSchema

public String getTableSchema()
Gets the table schema associated with this data store.

At some point this may change if multiple schemas are supported by a data store.

Returns:
the schema name that will prefix table names.

getFeatureSource

public FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource(String typeName)
                                                                throws IOException
Gets a DB2-specific feature source.

Specified by:
getFeatureSource in interface DataStore
Overrides:
getFeatureSource in class JDBC1DataStore
Parameters:
typeName -
Returns:
a DB2Feature Source, Store or Locking
Throws:
IOException - if the feature source could not be created.
See Also:
DataStore.getFeatureSource(java.lang.String)

executeQuery

protected QueryData executeQuery(FeatureTypeInfo featureTypeInfo,
                                 String tableName,
                                 String sqlQuery,
                                 Transaction transaction,
                                 boolean forWrite)
                          throws IOException
Overrides the method in JDBCDataStore because it includes PostGIS-specific handling to setAutoCommit(false) which causes problems for DB2 because the transaction is still uncommitted when the connection is closed.

Overrides:
executeQuery in class JDBC1DataStore
Parameters:
featureTypeInfo -
tableName -
sqlQuery - The SQL query to execute.
transaction - The Transaction is included here for handling transaction connections at a later stage. It is not currently used.
forWrite -
Returns:
The QueryData object that contains the resources for the query.
Throws:
IOException
DataSourceException - If an error occurs performing the query.

createFeatureWriter

protected JDBCFeatureWriter createFeatureWriter(FeatureReader featureReader,
                                                QueryData queryData)
                                         throws IOException
Overrides the method in JDBCDataStore so that a DB2FeatureWriter is created.

Overrides:
createFeatureWriter in class JDBC1DataStore
Parameters:
featureReader -
queryData -
Returns:
The DB2FeatureWriter
Throws:
IOException
See Also:
JDBC1DataStore.createFeatureWriter(org.geotools.data.FeatureReader, org.geotools.data.jdbc.QueryData)

getFeatureReader

public FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(SimpleFeatureType requestType,
                                                                       Filter filter,
                                                                       Transaction transaction)
                                                                throws IOException
This is a public entry point to the DataStore.

We have given some though to changing this api to be based on query.

Currently the is is the only way to retype your features to different name spaces.

(non-Javadoc)

Overrides:
getFeatureReader in class JDBC1DataStore
Throws:
IOException
See Also:
org.geotools.data.DataStore#getFeatureReader(org.geotools.feature.FeatureType, org.geotools.filter.Filter, org.geotools.data.Transaction)


Copyright © 1996-2009 Geotools. All Rights Reserved.