public class

EmbeddedDatabaseBuilder

extends Object
java.lang.Object
   ↳ org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder

Class Overview

A builder that provides a fluent API for constructing an embedded database.

Usage example:

 EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
 EmbeddedDatabase db = builder.setType(H2).addScript("schema.sql").addScript("data.sql").build();
 db.shutdown();
 

Summary

Public Constructors
EmbeddedDatabaseBuilder()
Create a new embedded database builder.
EmbeddedDatabaseBuilder(ResourceLoader resourceLoader)
Create a new embedded database builder with the given ResourceLoader.
Public Methods
EmbeddedDatabaseBuilder addDefaultScripts()
Add default scripts to execute to populate the database.
EmbeddedDatabaseBuilder addScript(String sqlResource)
Adds a SQL script to execute to populate the database.
EmbeddedDatabase build()
Build the embedded database.
EmbeddedDatabaseBuilder setName(String databaseName)
Sets the name of the embedded database Defaults to 'testdb' if not called.
EmbeddedDatabaseBuilder setType(EmbeddedDatabaseType databaseType)
Sets the type of embedded database.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public EmbeddedDatabaseBuilder ()

Create a new embedded database builder.

public EmbeddedDatabaseBuilder (ResourceLoader resourceLoader)

Create a new embedded database builder with the given ResourceLoader.

Parameters
resourceLoader the ResourceLoader to delegate to

Public Methods

public EmbeddedDatabaseBuilder addDefaultScripts ()

Add default scripts to execute to populate the database. The default scripts are schema.sql to create the db schema and data.sql to populate the db with data.

Returns
  • this, for fluent call chaining

public EmbeddedDatabaseBuilder addScript (String sqlResource)

Adds a SQL script to execute to populate the database.

Parameters
sqlResource the sql resource location
Returns
  • this, for fluent call chaining

public EmbeddedDatabase build ()

Build the embedded database.

Returns
  • the embedded database

public EmbeddedDatabaseBuilder setName (String databaseName)

Sets the name of the embedded database Defaults to 'testdb' if not called.

Parameters
databaseName the database name
Returns
  • this, for fluent call chaining

public EmbeddedDatabaseBuilder setType (EmbeddedDatabaseType databaseType)

Sets the type of embedded database. Defaults to HSQL if not called.

Parameters
databaseType the database type
Returns
  • this, for fluent call chaining