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

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.

Author
Keith Donald

Author
Juergen Hoeller

Since
3.0

Constructors

<init>

EmbeddedDatabaseFactoryBean()

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.

Inherited Properties

DEFAULT_DATABASE_NAME

static val DEFAULT_DATABASE_NAME: String

Default name for an embedded database: {@value}

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

destroy

open fun destroy(): Unit

getObject

open fun getObject(): DataSource

getObjectType

open fun getObjectType(): Class<out DataSource>

isSingleton

open fun isSingleton(): Boolean

setDatabaseCleaner

open fun setDatabaseCleaner(databaseCleaner: DatabasePopulator): Unit

Set a script execution to be run in the bean destruction callback, cleaning up the database and leaving it in a known state for others.

Inherited 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.