Class JDBCDataStoreFactory
- Object
-
- JDBCDataStoreFactory
-
- All Implemented Interfaces:
DataAccessFactory
,DataStoreFactorySpi
,Factory
- Direct Known Subclasses:
DB2NGDataStoreFactory
,GeoPkgDataStoreFactory
,H2DataStoreFactory
,H2GISDataStoreFactory
,HanaDataStoreFactory
,InformixDataStoreFactory
,JDBCJNDIDataStoreFactory
,MySQLDataStoreFactory
,OracleNGDataStoreFactory
,PostgisNGDataStoreFactory
,SQLServerDataStoreFactory
,TeradataDataStoreFactory
public abstract class JDBCDataStoreFactory extends Object implements DataStoreFactorySpi
Abstract implementation of DataStoreFactory for jdbc datastores.- Author:
- Justin Deoliveira, The Open Planning Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface DataAccessFactory
DataAccessFactory.Param
-
-
Field Summary
Fields Modifier and Type Field Description static DataAccessFactory.Param
BATCH_INSERT_SIZE
If different from one, the JDBCInsertFeatureWriter will buffer the features and insert them in batchesstatic DataAccessFactory.Param
CALLBACK_FACTORY
JDBC callback factorystatic DataAccessFactory.Param
DATABASE
parameter for database instancestatic DataAccessFactory.Param
DATASOURCE
parameter for data sourcestatic DataAccessFactory.Param
DBTYPE
parameter for database typestatic DataAccessFactory.Param
EVICTOR_TESTS_PER_RUN
Number of connections checked during a single evictor run *static DataAccessFactory.Param
EXPOSE_PK
expose primary key columns as attributesstatic DataAccessFactory.Param
FETCHSIZE
Number of records readstatic DataAccessFactory.Param
HOST
parameter for database hoststatic 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 poolstatic DataAccessFactory.Param
MAXWAIT
Maximum amount of time the pool will wait when trying to grab a new connection *static DataAccessFactory.Param
MIN_EVICTABLE_TIME
Min time for a connection to be idle in order to be evicted *static DataAccessFactory.Param
MINCONN
Minimum number of connections in the connection poolstatic DataAccessFactory.Param
NAMESPACE
parameter for namespace of the datastorestatic DataAccessFactory.Param
PASSWD
parameter for database passwordstatic DataAccessFactory.Param
PK_METADATA_TABLE
Metadata table providing information about primary keys *static DataAccessFactory.Param
PORT
parameter for database portstatic DataAccessFactory.Param
SCHEMA
parameter for database schemastatic DataAccessFactory.Param
SQL_ON_BORROW
SQL executed when the session beginsstatic DataAccessFactory.Param
SQL_ON_RELEASE
SQL executed when the session endsstatic DataAccessFactory.Param
TEST_WHILE_IDLE
If IDLE connections should be validated before using them *static DataAccessFactory.Param
TIME_BETWEEN_EVICTOR_RUNS
Idle object evictor periodicity *static DataAccessFactory.Param
USER
parameter for database userstatic DataAccessFactory.Param
VALIDATECONN
If connections should be validated before using them
-
Constructor Summary
Constructors Constructor Description JDBCDataStoreFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canProcess(Map<String,?> params)
Default implementation verifies the Map against the Param information.protected boolean
checkDBType(Map<String,?> params)
protected boolean
checkDBType(Map<String,?> params, String dbtype)
BasicDataSource
createDataSource(Map<String,?> params)
DataSource access allowing SQL use: intended to allow client code to query available schemas.protected DataSource
createDataSource(Map<String,?> params, SQLDialect dialect)
Creates the datasource for the data store.JDBCDataStore
createDataStore(Map<String,?> params)
Construct a live data source using the params specifed.protected JDBCDataStore
createDataStoreInternal(JDBCDataStore dataStore, Map<String,?> params)
Subclass hook to do additional initialization of a newly created datastore.DataStore
createNewDataStore(Map<String,?> params)
protected abstract SQLDialect
createSQLDialect(JDBCDataStore dataStore)
Creates the dialect that the datastore uses for communication with the underlying database.protected SQLDialect
createSQLDialect(JDBCDataStore dataStore, Map<String,?> params)
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()
Name suitable for display to end user.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<String,?> 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<String,Object> parameters)
Sets up the database connection parameters.-
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
Number of records read
-
BATCH_INSERT_SIZE
public static final DataAccessFactory.Param BATCH_INSERT_SIZE
If different from one, the JDBCInsertFeatureWriter will buffer the features and insert them in batches
-
MAXWAIT
public static final DataAccessFactory.Param MAXWAIT
Maximum amount of time the pool will wait when trying to grab a new connection *
-
TEST_WHILE_IDLE
public static final DataAccessFactory.Param TEST_WHILE_IDLE
If IDLE connections should be validated before using them *
-
TIME_BETWEEN_EVICTOR_RUNS
public static final DataAccessFactory.Param TIME_BETWEEN_EVICTOR_RUNS
Idle object evictor periodicity *
-
MIN_EVICTABLE_TIME
public static final DataAccessFactory.Param MIN_EVICTABLE_TIME
Min time for a connection to be idle in order to be evicted *
-
EVICTOR_TESTS_PER_RUN
public static final DataAccessFactory.Param EVICTOR_TESTS_PER_RUN
Number of connections checked during a single evictor run *
-
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
-
SQL_ON_BORROW
public static final DataAccessFactory.Param SQL_ON_BORROW
SQL executed when the session begins
-
SQL_ON_RELEASE
public static final DataAccessFactory.Param SQL_ON_RELEASE
SQL executed when the session ends
-
CALLBACK_FACTORY
public static final DataAccessFactory.Param CALLBACK_FACTORY
JDBC callback factory
-
-
Method Detail
-
getDisplayName
public String getDisplayName()
Description copied from interface:DataAccessFactory
Name suitable for display to end user.A non localized display name for this data store type.
- Specified by:
getDisplayName
in interfaceDataAccessFactory
- Returns:
- A short name suitable for display in a user interface.
-
canProcess
public boolean canProcess(Map<String,?> params)
Default implementation verifies the Map against the Param information.It will ensure that:
- params is not null
- Everything is of the correct type (or upcovertable to the correct type without Error)
- Required Parameters are present
- Specified by:
canProcess
in interfaceDataAccessFactory
- Parameters:
params
- The full set of information needed to construct a live data source.- Returns:
- true if params is in agreement with getParametersInfo and checkDBType
-
createDataStore
public final JDBCDataStore createDataStore(Map<String,?> params) throws 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.
- "user": is taken to be the user name
- "passwd": is taken to be the password
- "namespace": is taken to be the namespace prefix (and will be kept in sync with GeoServer namespace management.
- Specified by:
createDataStore
in interfaceDataAccessFactory
- Specified by:
createDataStore
in interfaceDataStoreFactorySpi
- 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<String,?> 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<String,?> params) throws IOException
- Specified by:
createNewDataStore
in interfaceDataStoreFactorySpi
- Throws:
IOException
-
getParametersInfo
public final DataAccessFactory.Param[] getParametersInfo()
Description copied from interface:DataAccessFactory
MetaData about the required Parameters (for createDataStore).Interpretation of FeatureDescriptor values:
- getDisplayName(): Gets the localized display name of this feature.
- getName(): Gets the programmatic name of this feature (used as the key in params)
- getShortDescription(): Gets the short description of this feature.
This should be the same as:
Object params = factory.getParameters(); BeanInfo info = getBeanInfo( params ); return info.getPropertyDescriptors();
- Specified by:
getParametersInfo
in interfaceDataAccessFactory
- Returns:
- Param array describing the Map for createDataStore
-
setupParameters
protected void setupParameters(Map<String,Object> 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 ofDataAccessFactory.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 interfaceDataAccessFactory
- Returns:
- true if and only if this factory has all the appropriate jars on the classpath to create DataStores.
-
getImplementationHints
public Map<RenderingHints.Key,?> getImplementationHints()
Returns the implementation hints for the datastore.Subclasses may override, this implementation returns
null
.- Specified by:
getImplementationHints
in interfaceFactory
- Returns:
- The map of hints, or an {@linkplain java.util.Collections.emptyMap() 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 SQLDialect createSQLDialect(JDBCDataStore dataStore, Map<String,?> params)
Creates the dialect that the datastore uses for communication with the underlying database.- Parameters:
dataStore
- The datastore.params
- The connection parameters
-
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<String,?> params, SQLDialect dialect) throws IOException
Creates the datasource for the data store.This method creates a
BasicDataSource
instance and populates it as follows:- poolPreparedStatements -> false
- driverClassName ->
getDriverClassName()
- url -> 'jdbc:<
getDatabaseID()
>://<HOST
>/<DATABASE
>' - username -> <
USER
> - password -> <
PASSWD
>
- Throws:
IOException
-
createDataSource
public BasicDataSource createDataSource(Map<String,?> 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.
-
getJDBCUrl
protected String getJDBCUrl(Map<String,?> params) throws IOException
Builds up the JDBC url in a jdbc::// : / Override if you need a different setup - Throws:
IOException
-
-