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 fluent API for constructing an embedded database.

Usage example:

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

Since:
3.0
Author:
Keith Donald, Juergen Hoeller

Constructor Summary
EmbeddedDatabaseBuilder()
          Create a new embedded database builder.
EmbeddedDatabaseBuilder(ResourceLoader resourceLoader)
          Create a new embedded database builder withfor the given ResourceLoader.
 
Method Summary
 EmbeddedDatabase build()
          Build the embedded database.
static EmbeddedDatabase buildDefault()
          Factory method that builds a default EmbeddedDatabase instance.
 EmbeddedDatabaseBuilder name(String databaseName)
          Sets the name of the embedded database Defaults to 'testdb' if not called.
static EmbeddedDatabaseBuilder relativeTo(Class clazz)
          Factory method that creates a EmbeddedDatabaseBuilder that loads SQL resources relative to the provided class.
 EmbeddedDatabaseBuilder script(String sqlResource)
          Adds a SQL script to execute to populate the database.
 EmbeddedDatabaseBuilder type(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 withfor the given ResourceLoader.

Parameters:
resourceLoader - the ResourceLoader to delegate to
Method Detail

name

public EmbeddedDatabaseBuilder name(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

type

public EmbeddedDatabaseBuilder type(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

script

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

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

build

public EmbeddedDatabase build()
Build the embedded database.

Returns:
the embedded database

buildDefault

public static EmbeddedDatabase buildDefault()
Factory method that builds a default EmbeddedDatabase instance.

The default instance is HSQL with a schema created from "classpath:schema.sql" and data loaded from "classpath:data.sql".

Returns:
an embedded database

relativeTo

public static EmbeddedDatabaseBuilder relativeTo(Class clazz)
Factory method that creates a EmbeddedDatabaseBuilder that loads SQL resources relative to the provided class.

Parameters:
clazz - the class to load relative to
Returns:
the embedded database builder