spring-framework / org.springframework.jdbc.datasource.embedded / EmbeddedDatabaseFactory

EmbeddedDatabaseFactory

open class EmbeddedDatabaseFactory

Factory for creating an EmbeddedDatabase instance.

Callers are guaranteed that the returned database has been fully initialized and populated.

The factory can be configured as follows:

After configuring the factory, call #getDatabase() to obtain a reference to the EmbeddedDatabase instance.

Author
Keith Donald

Author
Juergen Hoeller

Author
Sam Brannen

Since
3.0

Constructors

<init>

EmbeddedDatabaseFactory()

Factory for creating an EmbeddedDatabase instance.

Callers are guaranteed that the returned database has been fully initialized and populated.

The factory can be configured as follows:

After configuring the factory, call #getDatabase() to obtain a reference to the EmbeddedDatabase instance.

Properties

DEFAULT_DATABASE_NAME

static val DEFAULT_DATABASE_NAME: String

Default name for an embedded database: {@value}

Functions

getDatabase

open fun getDatabase(): EmbeddedDatabase

Factory method that returns the EmbeddedDatabase instance, which is also a DataSource.

setDataSourceFactory

open fun setDataSourceFactory(dataSourceFactory: DataSourceFactory): Unit

Set the factory to use to create the DataSource instance that connects to the embedded database.

Defaults to SimpleDriverDataSourceFactory.

setDatabaseConfigurer

open fun setDatabaseConfigurer(configurer: EmbeddedDatabaseConfigurer): Unit

Set the strategy that will be used to configure the embedded database instance.

Call this when you wish to use an embedded database type not already supported.

setDatabaseName

open fun setDatabaseName(databaseName: String): Unit

Set the name of the database.

Defaults to {@value #DEFAULT_DATABASE_NAME}.

Will be overridden if the generateUniqueDatabaseName flag has been set to true.

setDatabasePopulator

open fun setDatabasePopulator(populator: DatabasePopulator): Unit

Set the strategy that will be used to initialize or populate the embedded database.

Defaults to null.

setDatabaseType

open fun setDatabaseType(type: EmbeddedDatabaseType): Unit

Set the type of embedded database to use.

Call this when you wish to configure one of the pre-supported types.

Defaults to HSQL.

setGenerateUniqueDatabaseName

open fun setGenerateUniqueDatabaseName(generateUniqueDatabaseName: Boolean): Unit

Set the generateUniqueDatabaseName flag to enable or disable generation of a pseudo-random unique ID to be used as the database name.

Setting this flag to true overrides any explicit name set via #setDatabaseName.

Inheritors

EmbeddedDatabaseFactoryBean

open class EmbeddedDatabaseFactoryBean : EmbeddedDatabaseFactory, FactoryBean<DataSource>, InitializingBean, DisposableBean

A subclass of EmbeddedDatabaseFactory that implements FactoryBean for registration as a Spring bean. Returns the actual DataSource that provides connectivity to the embedded database to Spring.

The target DataSource is returned instead of an EmbeddedDatabase proxy since the FactoryBean will manage the initialization and destruction lifecycle of the embedded database instance.

Implements DisposableBean to shutdown the embedded database when the managing Spring container is being closed.