org.geotools.jdbc
Class JDBCDataStoreFactory

java.lang.Object
  extended by org.geotools.data.AbstractDataStoreFactory
      extended by org.geotools.jdbc.JDBCDataStoreFactory
All Implemented Interfaces:
DataAccessFactory, DataStoreFactorySpi, Factory
Direct Known Subclasses:
DB2NGDataStoreFactory, H2DataStoreFactory, JDBCJNDIDataStoreFactory, MySQLDataStoreFactory, OracleNGDataStoreFactory, PostgisNGDataStoreFactory, SpatiaLiteDataStoreFactory, SQLServerDataStoreFactory

public abstract class JDBCDataStoreFactory
extends AbstractDataStoreFactory

Abstract implementation of DataStoreFactory for jdbc datastores.

Author:
Justin Deoliveira, The Open Planning Project

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.geotools.data.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 EXPOSE_PK
          expose primary key columns as attributes
static DataAccessFactory.Param FETCHSIZE
          If connections should be validated before using them
static DataAccessFactory.Param HOST
          parameter for database host
static DataAccessFactory.Param MAX_OPEN_PREPARED_STATEMENTS
          Number of prepared statements cached per connection (this param is exposed only by factories supporting prepared statements
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 PK_METADATA_TABLE
          Metadata table providing information about primary keys
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(java.util.Map params)
          Default implementation verifies the Map against the Param information.
protected  boolean checkDBType(java.util.Map params)
           
protected  boolean checkDBType(java.util.Map params, java.lang.String dbtype)
           
 org.apache.commons.dbcp.BasicDataSource createDataSource(java.util.Map params)
          DataSource access allowing SQL use: intended to allow client code to query available schemas.
protected  javax.sql.DataSource createDataSource(java.util.Map params, SQLDialect dialect)
          Creates the datasource for the data store.
 JDBCDataStore createDataStore(java.util.Map params)
          Construct a live data source using the params specifed.
protected  JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, java.util.Map params)
          Subclass hook to do additional initialization of a newly created datastore.
 DataStore createNewDataStore(java.util.Map params)
           
protected abstract  SQLDialect createSQLDialect(JDBCDataStore dataStore)
          Creates the dialect that the datastore uses for communication with the underlying database.
protected abstract  java.lang.String getDatabaseID()
          Returns a string to identify the type of the database.
 java.lang.String getDisplayName()
          Default Implementation abuses the naming convention.
protected abstract  java.lang.String getDriverClassName()
          Returns the fully qualified class name of the jdbc driver.
 java.util.Map<java.awt.RenderingHints.Key,?> getImplementationHints()
          Returns the implementation hints for the datastore.
protected  java.lang.String getJDBCUrl(java.util.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  java.lang.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(java.util.Map parameters)
          Sets up the database connection parameters.
 
Methods inherited from class org.geotools.data.AbstractDataStoreFactory
getParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.data.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


PK_METADATA_TABLE

public static final DataAccessFactory.Param PK_METADATA_TABLE
Metadata table providing information about primary keys


MAX_OPEN_PREPARED_STATEMENTS

public static final DataAccessFactory.Param MAX_OPEN_PREPARED_STATEMENTS
Number of prepared statements cached per connection (this param is exposed only by factories supporting prepared statements


EXPOSE_PK

public static final DataAccessFactory.Param EXPOSE_PK
expose primary key columns as attributes

Constructor Detail

JDBCDataStoreFactory

public JDBCDataStoreFactory()
Method Detail

getDisplayName

public java.lang.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(java.util.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.

checkDBType

protected boolean checkDBType(java.util.Map params)

checkDBType

protected final boolean checkDBType(java.util.Map params,
                                    java.lang.String dbtype)

createDataStore

public final JDBCDataStore createDataStore(java.util.Map params)
                                    throws java.io.IOException
Description copied from interface: DataStoreFactorySpi
Construct a live data source using the params specifed.

You can think of this as setting up a connection to the back end data source.

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:
java.io.IOException - if there were any problems setting up (creating or connecting) the datasource.

createDataStoreInternal

protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore,
                                                java.util.Map params)
                                         throws java.io.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:
java.io.IOException

createNewDataStore

public DataStore createNewDataStore(java.util.Map params)
                             throws java.io.IOException
Throws:
java.io.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(java.util.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 java.util.Map<java.awt.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 java.lang.String getDatabaseID()
Returns a string to identify the type of the database.

Example: 'postgis'.


getDriverClassName

protected abstract java.lang.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 javax.sql.DataSource createDataSource(java.util.Map params,
                                                SQLDialect dialect)
                                         throws java.io.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:
java.io.IOException

createDataSource

public org.apache.commons.dbcp.BasicDataSource createDataSource(java.util.Map params)
                                                         throws java.io.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:
java.io.IOException

getValidationQuery

protected abstract java.lang.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 java.lang.String getJDBCUrl(java.util.Map params)
                               throws java.io.IOException
Builds up the JDBC url in a jdbc:://:/ Override if you need a different setup

Parameters:
params -
Returns:
Throws:
java.io.IOException


Copyright © 1996-2010 Geotools. All Rights Reserved.