EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.setType(H2)
.setScriptEncoding("UTF-8")
.ignoreFailedDrops(true)
.addScript("schema.sql")
.addScripts("user_data.sql", "country_data.sql")
.build();
// perform actions against the db (EmbeddedDatabase extends javax.sql.DataSource)
db.shutdown();
org.springframework.jdbc.datasource.init.ScriptUtils , org.springframework.jdbc.datasource.init.ResourceDatabasePopulator , org.springframework.jdbc.datasource.init.DatabasePopulatorUtils
| Modifier and Type | Field and Description |
|---|---|
| private final EmbeddedDatabaseFactory | |
| private final ResourceDatabasePopulator | |
| private final ResourceLoader |
| Access | Constructor and Description |
|---|---|
| public | |
| public | EmbeddedDatabaseBuilder(ResourceLoader
the resourceLoader)ResourceLoader to delegate toCreate a new embedded database builder with the given |
| Modifier and Type | Method and Description |
|---|---|
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingAdd default SQL scripts to execute to populate the database. |
| public EmbeddedDatabaseBuilder | |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe scripts to execute scripts)Add multiple SQL scripts to execute to initialize or populate the database. |
| public EmbeddedDatabase | |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingtrue if script execution should continue on errorSpecify that all failures which occur while executing SQL scripts should be logged but should not cause a failure. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingtrue if a unique database name should be generatedSpecify whether a unique ID should be generated and used as the database name. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingtrue if failed drop statements should be ignoredSpecify that a failed SQL |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe end delimiter for block comments blockCommentEndDelimiter)Specify the end delimiter for block comments in all SQL scripts. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe start delimiter for block comments blockCommentStartDelimiter)Specify the start delimiter for block comments in all SQL scripts. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe prefix for single-line comments commentPrefix)Specify the single-line comment prefix used in all SQL scripts. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe prefixes for single-line comments commentPrefixes)Specify the prefixes that identify single-line comments within all SQL scripts. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingSet the factory to use to create the |
| public EmbeddedDatabaseBuilder | |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe encoding used in scripts scriptEncoding)Specify the character encoding used in all SQL scripts, if different from the platform encoding. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe statement separator separator)Specify the statement separator used in all SQL scripts, if a custom one. |
| public EmbeddedDatabaseBuilder | Returns: this, to facilitate method chainingthe type of embedded database to build databaseType)Set the type of embedded database. |
| databaseFactory | back to summary |
|---|---|
| private final EmbeddedDatabaseFactory databaseFactory | |
| databasePopulator | back to summary |
|---|---|
| private final ResourceDatabasePopulator databasePopulator | |
| resourceLoader | back to summary |
|---|---|
| private final ResourceLoader resourceLoader | |
| EmbeddedDatabaseBuilder | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder() Create a new embedded database builder with a | |
| EmbeddedDatabaseBuilder | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader) Create a new embedded database builder with the given
| |
| addDefaultScripts | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder addDefaultScripts() Add default SQL scripts to execute to populate the database. The default scripts are
| |
| addScript | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder addScript(String script) Add an SQL script to execute to initialize or populate the database.
| |
| addScripts | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder addScripts(String... scripts) Add multiple SQL scripts to execute to initialize or populate the database.
| |
| build | back to summary |
|---|---|
| public EmbeddedDatabase build() Build the embedded database.
| |
| continueOnError | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder continueOnError(boolean flag) Specify that all failures which occur while executing SQL scripts should be logged but should not cause a failure. Defaults to
| |
| generateUniqueName | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder generateUniqueName(boolean flag) Specify whether a unique ID should be generated and used as the database name. If the configuration for this builder is reused across multiple
application contexts within a single JVM, this flag should be enabled
(i.e., set to Enabling this flag overrides any explicit name set via
| |
| ignoreFailedDrops | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder ignoreFailedDrops(boolean flag) Specify that a failed SQL This is useful for a database whose SQL dialect does not support an
The default is
| |
| setBlockCommentEndDelimiter | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setBlockCommentEndDelimiter(String blockCommentEndDelimiter) Specify the end delimiter for block comments in all SQL scripts. Defaults to
| |
| setBlockCommentStartDelimiter | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setBlockCommentStartDelimiter(String blockCommentStartDelimiter) Specify the start delimiter for block comments in all SQL scripts. Defaults to
| |
| setCommentPrefix | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setCommentPrefix(String commentPrefix) Specify the single-line comment prefix used in all SQL scripts. Defaults to
| |
| setCommentPrefixes | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setCommentPrefixes(String... commentPrefixes) Specify the prefixes that identify single-line comments within all SQL scripts. Defaults to
| |
| setDataSourceFactory | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setDataSourceFactory(DataSourceFactory dataSourceFactory) Set the factory to use to create the Defaults to
| |
| setName | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setName(String databaseName) Set the name of the embedded database. Defaults to Will be overridden if the
| |
| setScriptEncoding | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setScriptEncoding(String scriptEncoding) Specify the character encoding used in all SQL scripts, if different from the platform encoding.
| |
| setSeparator | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setSeparator(String separator) Specify the statement separator used in all SQL scripts, if a custom one. Defaults to
| |
| setType | back to summary |
|---|---|
| public EmbeddedDatabaseBuilder setType(EmbeddedDatabaseType databaseType) Set the type of embedded database. Defaults to HSQL if not called.
| |