org.geotools.data.jdbc.fidmapper
Class DefaultFIDMapperFactory

java.lang.Object
  extended byorg.geotools.data.jdbc.fidmapper.DefaultFIDMapperFactory
All Implemented Interfaces:
FIDMapperFactory
Direct Known Subclasses:
DB2FIDMapperFactory, HsqlFIDMapperFactory, PostgisFIDMapperFactory

public class DefaultFIDMapperFactory
extends java.lang.Object
implements FIDMapperFactory

Default FID mapper that works with default FID mappers.

May also be used a base class for more specific and feature rich factories

Author:
Andrea Aime

Nested Class Summary
protected  class DefaultFIDMapperFactory.ColumnInfo
          Simple class used as a struct to hold column informations used in this factory
 
Field Summary
protected  boolean returnFIDColumnsAsAttributes
          Set if table FID columns are to be returned as business attributes.
 
Constructor Summary
DefaultFIDMapperFactory()
          Constructs a DefaultFIDMapperFactory which will not return FID columns as business attributes.
DefaultFIDMapperFactory(boolean returnFIDColumnsAsAttributes)
          Constructs a DefaultFIDMapperFactory with user specification of whether to return FID columns as business attributes.
 
Method Summary
protected  FIDMapper buildLastResortFidMapper(java.lang.String schema, java.lang.String tableName, java.sql.Connection connection, DefaultFIDMapperFactory.ColumnInfo[] colInfos)
          Builds a FidMapper when every other tentative of building one fails.
protected  FIDMapper buildMultiColumnFIDMapper(java.lang.String schema, java.lang.String tableName, java.sql.Connection connection, DefaultFIDMapperFactory.ColumnInfo[] colInfos)
          Builds a FID mapper for multi column public columns
protected  FIDMapper buildNoPKMapper(java.lang.String schema, java.lang.String tableName, java.sql.Connection connection)
          DOCUMENT ME!
protected  FIDMapper buildSingleColumnFidMapper(java.lang.String schema, java.lang.String tableName, java.sql.Connection connection, DefaultFIDMapperFactory.ColumnInfo ci)
          Builds a FID mapper based on a single column primary key.
protected  java.util.List getColumnInfoList(DefaultFIDMapperFactory.ColumnInfo[] colInfos)
          Retuns a List of column infos, nice for logging the column infos leveraging the complete toString() method provided by lists
 FIDMapper getMapper(FeatureType featureType)
          Returns a FIDMapper for the specified feature type.
 FIDMapper getMapper(java.lang.String catalog, java.lang.String schema, java.lang.String tableName, java.sql.Connection connection)
          Gets the appropriate FIDMapper for the specified table.
protected  DefaultFIDMapperFactory.ColumnInfo[] getPkColumnInfo(java.lang.String catalog, java.lang.String schema, java.lang.String typeName, java.sql.Connection conn)
           
protected  boolean isAutoIncrement(java.lang.String catalog, java.lang.String schema, java.lang.String tableName, java.sql.Connection conn, java.sql.ResultSet tableInfo, java.lang.String columnName, int dataType)
          Returns true if the specified column is auto-increment.
protected  boolean isIntegralType(int dataType)
          Returns true if the dataType for the column can serve as a primary key.
protected  boolean isTextType(int dataType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

returnFIDColumnsAsAttributes

protected boolean returnFIDColumnsAsAttributes
Set if table FID columns are to be returned as business attributes.

Constructor Detail

DefaultFIDMapperFactory

public DefaultFIDMapperFactory()
Constructs a DefaultFIDMapperFactory which will not return FID columns as business attributes.


DefaultFIDMapperFactory

public DefaultFIDMapperFactory(boolean returnFIDColumnsAsAttributes)
Constructs a DefaultFIDMapperFactory with user specification of whether to return FID columns as business attributes.

Parameters:
returnFIDColumnsAsAttributes - true if FID columns should be returned as business attributes.
Method Detail

getMapper

public FIDMapper getMapper(java.lang.String catalog,
                           java.lang.String schema,
                           java.lang.String tableName,
                           java.sql.Connection connection)
                    throws java.io.IOException
Gets the appropriate FIDMapper for the specified table.

Specified by:
getMapper in interface FIDMapperFactory
Parameters:
catalog -
schema -
tableName -
connection - the active database connection to get table key information
Returns:
the appropriate FIDMapper for the specified table.
Throws:
java.io.IOException - if any error occurs.

getColumnInfoList

protected java.util.List getColumnInfoList(DefaultFIDMapperFactory.ColumnInfo[] colInfos)
Retuns a List of column infos, nice for logging the column infos leveraging the complete toString() method provided by lists

Parameters:
colInfos -
Returns:

buildLastResortFidMapper

protected FIDMapper buildLastResortFidMapper(java.lang.String schema,
                                             java.lang.String tableName,
                                             java.sql.Connection connection,
                                             DefaultFIDMapperFactory.ColumnInfo[] colInfos)
Builds a FidMapper when every other tentative of building one fails. This method is used as a last resort fall back, use it if you can provide a FIDMapper that works on every kind of table, but it's usually suboptimal. The default behaviour is to return no FID mapper at all.

Parameters:
schema -
tableName -
connection -
colInfos -
Returns:

buildSingleColumnFidMapper

protected FIDMapper buildSingleColumnFidMapper(java.lang.String schema,
                                               java.lang.String tableName,
                                               java.sql.Connection connection,
                                               DefaultFIDMapperFactory.ColumnInfo ci)
Builds a FID mapper based on a single column primary key. Default version tries the auto-increment way, then a mapping on an MaxIncFIDMapper type for numeric columns, and a plain BasicFIDMapper of text based columns.

Parameters:
schema -
tableName -
connection - an open database connection.
ci - the column information for the FID column.
Returns:
the appropriate FIDMapper.

buildNoPKMapper

protected FIDMapper buildNoPKMapper(java.lang.String schema,
                                    java.lang.String tableName,
                                    java.sql.Connection connection)
DOCUMENT ME!

Parameters:
schema -
tableName -
connection -
Returns:

buildMultiColumnFIDMapper

protected FIDMapper buildMultiColumnFIDMapper(java.lang.String schema,
                                              java.lang.String tableName,
                                              java.sql.Connection connection,
                                              DefaultFIDMapperFactory.ColumnInfo[] colInfos)
Builds a FID mapper for multi column public columns

Parameters:
schema -
tableName -
connection -
colInfos -
Returns:

getPkColumnInfo

protected DefaultFIDMapperFactory.ColumnInfo[] getPkColumnInfo(java.lang.String catalog,
                                                               java.lang.String schema,
                                                               java.lang.String typeName,
                                                               java.sql.Connection conn)
                                                        throws SchemaNotFoundException,
                                                               DataSourceException
Throws:
SchemaNotFoundException
DataSourceException

isAutoIncrement

protected boolean isAutoIncrement(java.lang.String catalog,
                                  java.lang.String schema,
                                  java.lang.String tableName,
                                  java.sql.Connection conn,
                                  java.sql.ResultSet tableInfo,
                                  java.lang.String columnName,
                                  int dataType)
                           throws java.sql.SQLException
Returns true if the specified column is auto-increment. This method is left protected so that specific datastore implementations can put their own logic, should the default one be ineffective or have bad performance. NOTE: the postgis subclass will call this with the columnname and table name pre-double-quoted! Other DB may have to do the same - please check your DB's documentation.

Parameters:
catalog -
schema -
tableName -
conn -
tableInfo -
columnName -
dataType -
Returns:
Throws:
java.sql.SQLException

isIntegralType

protected boolean isIntegralType(int dataType)
Returns true if the dataType for the column can serve as a primary key. Note that this now returns true for a DECIMAL type, because oracle Numbers are returned in jdbc as DECIMAL. This may cause errors in very rare cases somewhere down the line, but only if users do something incredibly silly like defining a primary key with a double.

Parameters:
dataType - DOCUMENT ME!
Returns:
DOCUMENT ME!

isTextType

protected boolean isTextType(int dataType)

getMapper

public FIDMapper getMapper(FeatureType featureType)
Description copied from interface: FIDMapperFactory
Returns a FIDMapper for the specified feature type. This one is called when creating new tables if the user did not provide a FIDMapper

Specified by:
getMapper in interface FIDMapperFactory
Parameters:
featureType -
Returns:
See Also:
FIDMapperFactory.getMapper(org.geotools.feature.FeatureType)


Copyright © GeoTools. All Rights Reserved.