Class EmbeddedDatabaseFactory
- Direct Known Subclasses:
- EmbeddedDatabaseFactoryBean
EmbeddedDatabase instance.
 Callers are guaranteed that the returned database has been fully initialized and populated.
The factory can be configured as follows:
- Call generateUniqueDatabaseNameto set a unique, random name for the database.
- Call setDatabaseName(java.lang.String)to set an explicit name for the database.
- Call setDatabaseType(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType)to set the database type if you wish to use one of the supported types.
- Call setDatabaseConfigurer(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurer)to configure support for a custom embedded database type.
- Call setDatabasePopulator(org.springframework.jdbc.datasource.init.DatabasePopulator)to change the algorithm used to populate the database.
- Call setDataSourceFactory(org.springframework.jdbc.datasource.embedded.DataSourceFactory)to change the type ofDataSourceused to connect to the database.
After configuring the factory, call getDatabase() to obtain
 a reference to the EmbeddedDatabase instance.
- Since:
- 3.0
- Author:
- Keith Donald, Juergen Hoeller, Sam Brannen
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringDefault name for an embedded database: "testdb".
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionFactory method that returns the embedded database instance, which is also aDataSource.protected final DataSourceHook that gets theDataSourcethat provides the connectivity to the embedded database.protected voidHook to initialize the embedded database.voidsetDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer) Set the strategy that will be used to configure the embedded database instance.voidsetDatabaseName(String databaseName) Set the name of the database.voidsetDatabasePopulator(DatabasePopulator populator) Set the strategy that will be used to initialize or populate the embedded database.voidSet the type of embedded database to use.voidsetDataSourceFactory(DataSourceFactory dataSourceFactory) Set the factory to use to create theDataSourceinstance that connects to the embedded database.voidsetGenerateUniqueDatabaseName(boolean generateUniqueDatabaseName) Set thegenerateUniqueDatabaseNameflag to enable or disable generation of a pseudo-random unique ID to be used as the database name.protected voidHook to shut down the embedded database.
- 
Field Details- 
DEFAULT_DATABASE_NAMEDefault name for an embedded database: "testdb".- See Also:
 
 
- 
- 
Constructor Details- 
EmbeddedDatabaseFactorypublic EmbeddedDatabaseFactory()
 
- 
- 
Method Details- 
setGenerateUniqueDatabaseNamepublic void setGenerateUniqueDatabaseName(boolean generateUniqueDatabaseName) Set thegenerateUniqueDatabaseNameflag to enable or disable generation of a pseudo-random unique ID to be used as the database name.Setting this flag to trueoverrides any explicit name set viasetDatabaseName(java.lang.String).- Since:
- 4.2
- See Also:
 
- 
setDatabaseNameSet the name of the database.Defaults to "testdb". Will be overridden if the generateUniqueDatabaseNameflag has been set totrue.- Parameters:
- databaseName- name of the embedded database
- See Also:
 
- 
setDataSourceFactorySet the factory to use to create theDataSourceinstance that connects to the embedded database.Defaults to SimpleDriverDataSourceFactory.
- 
setDatabaseTypeSet the type of embedded database to use.Call this when you wish to configure one of the pre-supported types. Defaults to HSQL. - Parameters:
- type- the database type
 
- 
setDatabaseConfigurerSet 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. 
- 
setDatabasePopulatorSet the strategy that will be used to initialize or populate the embedded database.Defaults to null.
- 
getDatabaseFactory method that returns the embedded database instance, which is also aDataSource.
- 
initDatabaseprotected void initDatabase()Hook to initialize the embedded database.If the generateUniqueDatabaseNameflag has been set totrue, the current value of the database name will be overridden with an auto-generated name.Subclasses may call this method to force initialization; however, this method should only be invoked once. After calling this method, getDataSource()returns theDataSourceproviding connectivity to the database.
- 
shutdownDatabaseprotected void shutdownDatabase()Hook to shut down the embedded database. Subclasses may call this method to force shutdown.After calling, getDataSource()returnsnull.Does nothing if no embedded database has been initialized. 
- 
getDataSourceHook that gets theDataSourcethat provides the connectivity to the embedded database.Returns nullif theDataSourcehas not been initialized or if the database has been shut down. Subclasses may call this method to access theDataSourceinstance directly.
 
-