org.geotools.jdbc
Class JDBCDataStoreFactory

Object
  extended by AbstractDataStoreFactory
      extended by JDBCDataStoreFactory
All Implemented Interfaces:
DataAccessFactory, DataStoreFactorySpi, Factory
Direct Known Subclasses:
DB2NGDataStoreFactory, H2DataStoreFactory, JDBCJNDIDataStoreFactory, OracleNGDataStoreFactory, PostgisNGDataStoreFactory

public abstract class JDBCDataStoreFactory
extends AbstractDataStoreFactory

Abstract implementation of DataStoreFactory for jdbc datastores.

Author:
Justin Deoliveira, The Open Planning Project
Module:
modules/library/jdbc (gt-jdbc.jar)

Nested Class Summary
 
Nested classes/interfaces inherited from interface DataAccessFactory
DataAccessFactory.Param
 
Field Summary
static DataAccessFactory.Param DATABASE
          parameter for database instance
static DataAccessFactory.Param DATASOURCE
          parameter for data source
static DataAccessFactory.Param DBTYPE
          parameter for database type
static DataAccessFactory.Param FETCHSIZE
          If connections should be validated before using them
static DataAccessFactory.Param HOST
          parameter for database host
static DataAccessFactory.Param MAXCONN
          Maximum number of connections in the connection pool
static DataAccessFactory.Param MAXWAIT
          Maximum amount of time the pool will wait when trying to grab a new connection
static DataAccessFactory.Param MINCONN
          Minimum number of connections in the connection pool
static DataAccessFactory.Param NAMESPACE
          parameter for namespace of the datastore
static DataAccessFactory.Param PASSWD
          parameter for database password
static DataAccessFactory.Param PORT
          parameter for database port
static DataAccessFactory.Param SCHEMA
          parameter for database schema
static DataAccessFactory.Param USER
          parameter for database user
static DataAccessFactory.Param VALIDATECONN
          If connections should be validated before using them
 
Constructor Summary
JDBCDataStoreFactory()
           
 
Method Summary
 boolean canProcess(Map params)
          Default implementation verifies the Map against the Param information.
 BasicDataSource createDataSource(Map params)
          DataSource access allowing SQL use: intended to allow client code to query available schemas.
protected  DataSource createDataSource(Map params, SQLDialect dialect)
          Creates the datasource for the data store.
 JDBCDataStore createDataStore(Map params)
          Construct a live DataAccess using the connection parameters provided.
protected  JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params)
          Subclass hook to do additional initialization of a newly created datastore.
 DataStore createNewDataStore(Map params)
           
protected abstract  SQLDialect createSQLDialect(JDBCDataStore dataStore)
          Creates the dialect that the datastore uses for communication with the underlying database.
protected abstract  String getDatabaseID()
          Returns a string to identify the type of the database.
 String getDisplayName()
          Default Implementation abuses the naming convention.
protected abstract  String getDriverClassName()
          Returns the fully qualified class name of the jdbc driver.
 Map<RenderingHints.Key,?> getImplementationHints()
          Returns the implementation hints for the datastore.
protected  String getJDBCUrl(Map params)
          Builds up the JDBC url in a jdbc:://:/ Override if you need a different setup
 DataAccessFactory.Param[] getParametersInfo()
          MetaData about the required Parameters (for createDataStore).
protected abstract  String getValidationQuery()
          Override this to return a good validation query (a very quick one, such as one that asks the database what time is it) or return null if the factory does not support validation.
 boolean isAvailable()
          Determines if the datastore is available.
protected  void setupParameters(Map parameters)
          Sets up the database connection parameters.
 
Methods inherited from class AbstractDataStoreFactory
getParameters
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface DataAccessFactory
getDescription
 

Field Detail

DBTYPE

public static final DataAccessFactory.Param DBTYPE
parameter for database type


HOST

public static final DataAccessFactory.Param HOST
parameter for database host


PORT

public static final DataAccessFactory.Param PORT
parameter for database port


DATABASE

public static final DataAccessFactory.Param DATABASE
parameter for database instance


SCHEMA

public static final DataAccessFactory.Param SCHEMA
parameter for database schema


USER

public static final DataAccessFactory.Param USER
parameter for database user


PASSWD

public static final DataAccessFactory.Param PASSWD
parameter for database password


NAMESPACE

public static final DataAccessFactory.Param NAMESPACE
parameter for namespace of the datastore


DATASOURCE

public static final DataAccessFactory.Param DATASOURCE
parameter for data source


MAXCONN

public static final DataAccessFactory.Param MAXCONN
Maximum number of connections in the connection pool


MINCONN

public static final DataAccessFactory.Param MINCONN
Minimum number of connections in the connection pool


VALIDATECONN

public static final DataAccessFactory.Param VALIDATECONN
If connections should be validated before using them


FETCHSIZE

public static final DataAccessFactory.Param FETCHSIZE
If connections should be validated before using them


MAXWAIT

public static final DataAccessFactory.Param MAXWAIT
Maximum amount of time the pool will wait when trying to grab a new connection

Constructor Detail

JDBCDataStoreFactory

public JDBCDataStoreFactory()
Method Detail

getDisplayName

public String getDisplayName()
Description copied from class: AbstractDataStoreFactory
Default Implementation abuses the naming convention.

Will return Foo for org.geotools.data.foo.FooFactory.

Specified by:
getDisplayName in interface DataAccessFactory
Overrides:
getDisplayName in class AbstractDataStoreFactory
Returns:
return display name based on class name

canProcess

public boolean canProcess(Map params)
Description copied from class: AbstractDataStoreFactory
Default implementation verifies the Map against the Param information.

It will ensure that:

Why would you ever want to override this method? If you want to check that a expected file exists and is a directory.

Overrride:

 public boolean canProcess( Map params ) {
     if( !super.canProcess( params ) ){
          return false; // was not in agreement with getParametersInfo
     }
     // example check
     File file = (File) DIRECTORY.lookup( params ); // DIRECTORY is a param
     return file.exists() && file.isDirectory();
 }
 

Specified by:
canProcess in interface DataAccessFactory
Overrides:
canProcess in class AbstractDataStoreFactory
Parameters:
params - The full set of information needed to construct a live data source.
Returns:
true if params is in agreement with getParametersInfo, override for additional checks.

createDataStore

public final JDBCDataStore createDataStore(Map params)
                                    throws IOException
Description copied from interface: DataAccessFactory
Construct a live DataAccess using the connection parameters provided.

You can think of this class as setting up a connection to the back end data source. The required parameters are described by the getParameterInfo() method.

Magic Params: the following params are magic and are honoured by convention by the GeoServer and uDig application.

When we eventually move over to the use of OpperationalParam we will have to find someway to codify this convention.

Parameters:
params - The full set of information needed to construct a live data store. Typical key values for the map include: url - location of a resource, used by file reading datasources. dbtype - the type of the database to connect to, e.g. postgis, mysql
Returns:
The created DataStore, this may be null if the required resource was not found or if insufficent parameters were given. Note that canProcess() should have returned false if the problem is to do with insuficent parameters.
Throws:
IOException - if there were any problems setting up (creating or connecting) the datasource.

createDataStoreInternal

protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore,
                                                Map params)
                                         throws IOException
Subclass hook to do additional initialization of a newly created datastore.

Typically subclasses will want to override this method in the case where they provide additional datastore parameters, those should be processed here.

This method is provided with an instance of the datastore. In some cases subclasses may wish to create a new instance of the datastore, for instance in order to wrap the original instance. This is supported but the new datastore must be returned from this method. If not is such the case this method should still return the original passed in.

Parameters:
dataStore - The newly created datastore.
params - THe datastore parameters.
Throws:
IOException

createNewDataStore

public DataStore createNewDataStore(Map params)
                             throws IOException
Throws:
IOException

getParametersInfo

public final DataAccessFactory.Param[] getParametersInfo()
Description copied from interface: DataAccessFactory
MetaData about the required Parameters (for createDataStore).

Interpretation of FeatureDescriptor values:

This should be the same as:


 Object params = factory.getParameters();
 BeanInfo info = getBeanInfo( params );

 return info.getPropertyDescriptors();
 

Returns:
Param array describing the Map for createDataStore

setupParameters

protected void setupParameters(Map parameters)
Sets up the database connection parameters.

Subclasses may extend, but should not override. This implementation registers the following parameters.

Subclass implementation may remove any parameters from the map, or may overrwrite any parameters in the map.

Parameters:
parameters - Map of Param objects.

isAvailable

public boolean isAvailable()
Determines if the datastore is available.

Subclasses may with to override or extend this method. This implementation checks whether the jdbc driver class (provided by getDriverClassName() can be loaded.

Specified by:
isAvailable in interface DataAccessFactory
Overrides:
isAvailable in class AbstractDataStoreFactory
Returns:
true, override to check for drivers etc...

getImplementationHints

public Map<RenderingHints.Key,?> getImplementationHints()
Returns the implementation hints for the datastore.

Subclasses may override, this implementation returns null.

Specified by:
getImplementationHints in interface Factory
Overrides:
getImplementationHints in class AbstractDataStoreFactory
Returns:
The map of hints, or an empty map if none.

getDatabaseID

protected abstract String getDatabaseID()
Returns a string to identify the type of the database.

Example: 'postgis'.


getDriverClassName

protected abstract String getDriverClassName()
Returns the fully qualified class name of the jdbc driver.

For example: org.postgresql.Driver


createSQLDialect

protected abstract SQLDialect createSQLDialect(JDBCDataStore dataStore)
Creates the dialect that the datastore uses for communication with the underlying database.

Parameters:
dataStore - The datastore.

createDataSource

protected DataSource createDataSource(Map params,
                                      SQLDialect dialect)
                               throws IOException
Creates the datasource for the data store.

This method creates a BasicDataSource instance and populates it as follows:

If different behaviour is needed, this method should be extended or overridden.

Throws:
IOException

createDataSource

public BasicDataSource createDataSource(Map params)
                                 throws IOException
DataSource access allowing SQL use: intended to allow client code to query available schemas.

This DataSource is the clients responsibility to close() when they are finished using it.

Parameters:
params - Map of connection parameter.
Returns:
DataSource for SQL use
Throws:
IOException

getValidationQuery

protected abstract String getValidationQuery()
Override this to return a good validation query (a very quick one, such as one that asks the database what time is it) or return null if the factory does not support validation.

Returns:

getJDBCUrl

protected String getJDBCUrl(Map params)
                     throws IOException
Builds up the JDBC url in a jdbc:://:/ Override if you need a different setup

Parameters:
params -
Returns:
Throws:
IOException


Copyright © 1996-2009 Geotools. All Rights Reserved.