org.unitils.database
Class DatabaseUnitils

java.lang.Object
  extended by org.unitils.database.DatabaseUnitils

public class DatabaseUnitils
extends Object

Class providing access to the functionality of the database module using static methods. Meant to be used directly in unit tests.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
DatabaseUnitils()
           
 
Method Summary
static void cleanSchemas()
          Cleans all configured schema's.
static void clearSchemas()
          Clears all configured schema's.
static void commitTransaction()
          Commits the current unitils transaction
static void disableConstraints()
          Disables all foreign key and not-null constraints on the configured schema's.
static void flushDatabaseUpdates()
          Flushes all pending updates to the database.
static void generateDatasetDefinition()
          Generates a definition file that defines the structure of dataset's, i.e. a XSD of DTD that describes the structure of the database.
static DataSource getDataSource()
          Returns the DataSource that connects to the test database
static void resetDatabaseState()
          Updates the database version to the current version, without issuing any other updates to the database.
static void rollbackTransaction()
          Performs a rollback of the current unitils transaction
static void startTransaction()
          Starts a new transaction on the transaction manager configured in unitils
static void updateDatabase()
          Determines whether the test database is outdated and, if that is the case, updates the database with the latest changes.
static void updateSequences()
          Updates all sequences that have a value below a certain configurable treshold to become equal to this treshold
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseUnitils

public DatabaseUnitils()
Method Detail

getDataSource

public static DataSource getDataSource()
Returns the DataSource that connects to the test database

Returns:
The DataSource that connects to the test database

flushDatabaseUpdates

public static void flushDatabaseUpdates()
Flushes all pending updates to the database. This method is useful when the effect of updates needs to be checked directly on the database.

A typical usage of this method is, when updates were issues to the database using hibernate, making sure that these updates are flushed, to be able to check the effect of these updates using plain old JDBC.


startTransaction

public static void startTransaction()
Starts a new transaction on the transaction manager configured in unitils


commitTransaction

public static void commitTransaction()
Commits the current unitils transaction


rollbackTransaction

public static void rollbackTransaction()
Performs a rollback of the current unitils transaction


updateDatabase

public static void updateDatabase()
Determines whether the test database is outdated and, if that is the case, updates the database with the latest changes. See DBMaintainer for more information.


resetDatabaseState

public static void resetDatabaseState()
Updates the database version to the current version, without issuing any other updates to the database. This method can be used for example after you've manually brought the database to the latest version, but the database version is not yet set to the current one. This method can also be useful for example for reinitializing the database after having reorganized the scripts folder.


clearSchemas

public static void clearSchemas()
Clears all configured schema's. I.e. drops all tables, views and other database objects.


cleanSchemas

public static void cleanSchemas()
Cleans all configured schema's. I.e. removes all data from its database tables.


disableConstraints

public static void disableConstraints()
Disables all foreign key and not-null constraints on the configured schema's.


updateSequences

public static void updateSequences()
Updates all sequences that have a value below a certain configurable treshold to become equal to this treshold


generateDatasetDefinition

public static void generateDatasetDefinition()
Generates a definition file that defines the structure of dataset's, i.e. a XSD of DTD that describes the structure of the database.



Copyright © 2011. All Rights Reserved.