org.springframework.jdbc.datasource.embedded
Class EmbeddedDatabaseBuilder

java.lang.Object
  extended by org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder

public class EmbeddedDatabaseBuilder
extends Object

A builder that provides a convenient 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();
 

Since:
3.0
Author:
Keith Donald, Juergen Hoeller, Dave Syer

Constructor Summary
EmbeddedDatabaseBuilder()
          Create a new embedded database builder.
EmbeddedDatabaseBuilder(ResourceLoader resourceLoader)
          Create a new embedded database builder with the given ResourceLoader.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmbeddedDatabaseBuilder

public EmbeddedDatabaseBuilder()
Create a new embedded database builder.


EmbeddedDatabaseBuilder

public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader)
Create a new embedded database builder with the given ResourceLoader.

Parameters:
resourceLoader - the ResourceLoader to delegate to
Method Detail

setName

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, to facilitate method chaining

setType

public EmbeddedDatabaseBuilder setType(EmbeddedDatabaseType databaseType)
Sets the type of embedded database. Defaults to HSQL if not called.

Parameters:
databaseType - the database type
Returns:
this, to facilitate method chaining

addScript

public EmbeddedDatabaseBuilder addScript(String sqlResource)
Adds a SQL script to execute to populate the database.

Parameters:
sqlResource - the sql resource location
Returns:
this, to facilitate method chaining

addDefaultScripts

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, to facilitate method chaining

build

public EmbeddedDatabase build()
Build the embedded database.

Returns:
the embedded database