Class H2DataStoreFactory
- Object
-
- JDBCDataStoreFactory
-
- H2DataStoreFactory
-
- All Implemented Interfaces:
DataAccessFactory
,DataStoreFactorySpi
,Factory
public class H2DataStoreFactory extends JDBCDataStoreFactory
DataStoreFacotry for H2 database.- 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
ASSOCIATIONS
parameter for how to handle associationsstatic DataAccessFactory.Param
AUTO_SERVER
optional auto server mode parameterstatic DataAccessFactory.Param
DBTYPE
parameter for database typestatic DataAccessFactory.Param
HOST
optional host parameterstatic DataAccessFactory.Param
MVCC
optional parameter to handle MVCC.static DataAccessFactory.Param
PORT
optional port parameterstatic DataAccessFactory.Param
USER
optional user parameter-
Fields inherited from class JDBCDataStoreFactory
BATCH_INSERT_SIZE, CALLBACK_FACTORY, DATABASE, DATASOURCE, EVICTOR_TESTS_PER_RUN, EXPOSE_PK, FETCHSIZE, MAX_OPEN_PREPARED_STATEMENTS, MAXCONN, MAXWAIT, MIN_EVICTABLE_TIME, MINCONN, NAMESPACE, PASSWD, PK_METADATA_TABLE, SCHEMA, SQL_ON_BORROW, SQL_ON_RELEASE, TEST_WHILE_IDLE, TIME_BETWEEN_EVICTOR_RUNS, VALIDATECONN
-
-
Constructor Summary
Constructors Constructor Description H2DataStoreFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DataSource
createDataSource(Map<String,?> params, SQLDialect dialect)
Creates the datasource for the data store.protected JDBCDataStore
createDataStoreInternal(JDBCDataStore dataStore, Map<String,?> params)
Subclass hook to do additional initialization of a newly created datastore.protected SQLDialect
createSQLDialect(JDBCDataStore dataStore)
Creates the dialect that the datastore uses for communication with the underlying database.File
getBaseDirectory()
The base location to store h2 database files.protected String
getDatabaseID()
Returns a string to identify the type of the database.String
getDescription()
Describe the nature of the datasource constructed by this factory.String
getDisplayName()
Name suitable for display to end user.protected String
getDriverClassName()
Returns the fully qualified class name of the jdbc driver.protected String
getJDBCUrl(Map<String,?> params)
Builds up the JDBC url in a jdbc::// : / Override if you need a different setup protected 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.void
setBaseDirectory(File baseDirectory)
Sets the base location to store h2 database files.protected void
setupParameters(Map<String,Object> parameters)
Sets up the database connection parameters.-
Methods inherited from class JDBCDataStoreFactory
canProcess, checkDBType, checkDBType, createDataSource, createDataStore, createNewDataStore, createSQLDialect, getImplementationHints, getParametersInfo, isAvailable
-
-
-
-
Field Detail
-
DBTYPE
public static final DataAccessFactory.Param DBTYPE
parameter for database type
-
ASSOCIATIONS
public static final DataAccessFactory.Param ASSOCIATIONS
parameter for how to handle associations
-
USER
public static final DataAccessFactory.Param USER
optional user parameter
-
HOST
public static final DataAccessFactory.Param HOST
optional host parameter
-
PORT
public static final DataAccessFactory.Param PORT
optional port parameter
-
AUTO_SERVER
public static final DataAccessFactory.Param AUTO_SERVER
optional auto server mode parameter
-
MVCC
public static final DataAccessFactory.Param MVCC
optional parameter to handle MVCC.
-
-
Method Detail
-
setBaseDirectory
public void setBaseDirectory(File baseDirectory)
Sets the base location to store h2 database files.- Parameters:
baseDirectory
- A directory.
-
getBaseDirectory
public File getBaseDirectory()
The base location to store h2 database files.
-
setupParameters
protected void setupParameters(Map<String,Object> parameters)
Description copied from class:JDBCDataStoreFactory
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.- Overrides:
setupParameters
in classJDBCDataStoreFactory
- Parameters:
parameters
- Map ofDataAccessFactory.Param
objects.
-
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
- Overrides:
getDisplayName
in classJDBCDataStoreFactory
- Returns:
- A short name suitable for display in a user interface.
-
getDescription
public String getDescription()
Description copied from interface:DataAccessFactory
Describe the nature of the datasource constructed by this factory.A non localized description of this data store type.
- Returns:
- A human readable description that is suitable for inclusion in a list of available datasources.
-
getDatabaseID
protected String getDatabaseID()
Description copied from class:JDBCDataStoreFactory
Returns a string to identify the type of the database.Example: 'postgis'.
- Specified by:
getDatabaseID
in classJDBCDataStoreFactory
-
getDriverClassName
protected String getDriverClassName()
Description copied from class:JDBCDataStoreFactory
Returns the fully qualified class name of the jdbc driver.For example: org.postgresql.Driver
- Specified by:
getDriverClassName
in classJDBCDataStoreFactory
-
createSQLDialect
protected SQLDialect createSQLDialect(JDBCDataStore dataStore)
Description copied from class:JDBCDataStoreFactory
Creates the dialect that the datastore uses for communication with the underlying database.- Specified by:
createSQLDialect
in classJDBCDataStoreFactory
- Parameters:
dataStore
- The datastore.
-
createDataSource
protected DataSource createDataSource(Map<String,?> params, SQLDialect dialect) throws IOException
Description copied from class:JDBCDataStoreFactory
Creates the datasource for the data store.This method creates a
BasicDataSource
instance and populates it as follows:- poolPreparedStatements -> false
- driverClassName ->
JDBCDataStoreFactory.getDriverClassName()
- url -> 'jdbc:<
JDBCDataStoreFactory.getDatabaseID()
>://<JDBCDataStoreFactory.HOST
>/<JDBCDataStoreFactory.DATABASE
>' - username -> <
JDBCDataStoreFactory.USER
> - password -> <
JDBCDataStoreFactory.PASSWD
>
- Overrides:
createDataSource
in classJDBCDataStoreFactory
- Throws:
IOException
-
getJDBCUrl
protected String getJDBCUrl(Map<String,?> params) throws IOException
Description copied from class:JDBCDataStoreFactory
Builds up the JDBC url in a jdbc::// : / Override if you need a different setup - Overrides:
getJDBCUrl
in classJDBCDataStoreFactory
- Throws:
IOException
-
createDataStoreInternal
protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map<String,?> params) throws IOException
Description copied from class:JDBCDataStoreFactory
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.
- Overrides:
createDataStoreInternal
in classJDBCDataStoreFactory
- Parameters:
dataStore
- The newly created datastore.params
- THe datastore parameters.- Throws:
IOException
-
getValidationQuery
protected String getValidationQuery()
Description copied from class:JDBCDataStoreFactory
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.- Specified by:
getValidationQuery
in classJDBCDataStoreFactory
-
-