public class EmbeddedDatabaseFactory extends Object
EmbeddedDatabase
instances.
Callers are guaranteed that a returned database has been fully initialized and populated.
Can be configured:
setDatabaseName(String)
to change the name of the database.
setDatabaseType(EmbeddedDatabaseType)
to set the database
type if you wish to use one of the supported types.
setDatabaseConfigurer(EmbeddedDatabaseConfigurer)
to
configure support for your own embedded database type.
setDatabasePopulator(DatabasePopulator)
to change the
algorithm used to populate the database.
setDataSourceFactory(DataSourceFactory)
to change the type
of DataSource
used to connect to the database.
Call getDatabase()
to get the EmbeddedDatabase
instance.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DATABASE_NAME
Default name for an embedded database: "testdb".
|
Constructor and Description |
---|
EmbeddedDatabaseFactory() |
Modifier and Type | Method and Description |
---|---|
EmbeddedDatabase |
getDatabase()
Factory method that returns the
embedded database
instance, which is also a DataSource . |
protected DataSource |
getDataSource()
Hook that gets the
DataSource that provides the connectivity to the
embedded database. |
protected void |
initDatabase()
Hook to initialize the embedded database.
|
void |
setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer)
Set the strategy that will be used to configure the embedded database instance.
|
void |
setDatabaseName(String databaseName)
Set the name of the database.
|
void |
setDatabasePopulator(DatabasePopulator populator)
Set the strategy that will be used to initialize or populate the embedded
database.
|
void |
setDatabaseType(EmbeddedDatabaseType type)
Set the type of embedded database to use.
|
void |
setDataSourceFactory(DataSourceFactory dataSourceFactory)
Set the factory to use to create the
DataSource instance that
connects to the embedded database. |
protected void |
shutdownDatabase()
Hook to shutdown the embedded database.
|
public static final String DEFAULT_DATABASE_NAME
public void setDatabaseName(String databaseName)
Defaults to "testdb".
databaseName
- name of the embedded databasepublic void setDataSourceFactory(DataSourceFactory dataSourceFactory)
DataSource
instance that
connects to the embedded database.
Defaults to SimpleDriverDataSourceFactory
.
public void setDatabaseType(EmbeddedDatabaseType type)
Call this when you wish to configure one of the pre-supported types.
Defaults to HSQL.
type
- the database typepublic void setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer)
Call this when you wish to use an embedded database type not already supported.
public void setDatabasePopulator(DatabasePopulator populator)
Defaults to null
.
public EmbeddedDatabase getDatabase()
embedded database
instance, which is also a DataSource
.protected void initDatabase()
After calling this method, getDataSource()
returns the
DataSource
providing connectivity to the database.
protected void shutdownDatabase()
After calling, getDataSource()
returns null
.
Does nothing if no embedded database has been initialized.
protected final DataSource getDataSource()
DataSource
that provides the connectivity to the
embedded database.
Returns null
if the DataSource
has not been initialized
or if the database has been shut down. Subclasses may call this method to
access the DataSource
instance directly.