org.wamblee.test.persistence
Class DatabaseBuilder

java.lang.Object
  extended by org.wamblee.test.persistence.DatabaseBuilder

public class DatabaseBuilder
extends java.lang.Object

DatabaseBuilder is used from unit test to obtain a reference to a database from unit test. This database is either an inmemory database or represents an external database. Purpose of this utility is to make test code independent of the particular database used and specifically to be able to run database tests without any configuration at all (using an inmemory database). The type of database to use can be overridden by specifying either a system property or an environment variable (DB_CAPABILITIES_PROP) that contains the comma-separated capabilities of the database. Each database type provides its own capabilities (see DatabaseProvider implementations}. There are currently two database types available:

The DatabaseBuilder uses the ServiceLoader mechanism to find implementations of DatabaseProvider on the classpath. In the getDatabase(String...) method a number of capabilities are passed. The database providers are then searched in (arbitrary) order and the first one that has all required capabilities is returned. getSupportedDatabases() gives a list of all available databases.


Field Summary
static java.lang.String DB_CAPABILITIES_PROP
          Environmment variable by which capabilities of the requested database can be defined
 
Method Summary
static Database getDatabase(java.lang.String... aCapabilities)
          Gets the first database that has all required capabilities.
static java.util.List<DatabaseDescription> getSupportedDatabases()
          Gets a list of available databases.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_CAPABILITIES_PROP

public static final java.lang.String DB_CAPABILITIES_PROP
Environmment variable by which capabilities of the requested database can be defined

See Also:
Constant Field Values
Method Detail

getDatabase

public static Database getDatabase(java.lang.String... aCapabilities)
Gets the first database that has all required capabilities.

Parameters:
aCapabilities - Capabilities.
Returns:
Database to use.

getSupportedDatabases

public static java.util.List<DatabaseDescription> getSupportedDatabases()
Gets a list of available databases.

Returns:
List of databases.


Copyright © 2010. All Rights Reserved.