| java.lang.Object org.unitils.database.DatabaseModule
DatabaseModule | public class DatabaseModule implements Module(Code) | | todo add javadoc explaining transaction behavior.
Module that provides basic support for database testing such as the creation of a datasource that connectes to the
test database and the maintaince of the test database structure.
A datasource will be created the first time one is requested. Which type of datasource will be created depends on
the configured
DataSourceFactory . By default this will be a pooled datasource that gets its connection-url
and username and password from the unitils configuration.
The created datasource can be injected into a field of the test by annotating the field with
TestDataSource .
It can then be used to install it in your DAO or other class under test. See the javadoc of the annotation for more info
on how you can use it.
If the DbMaintainer is enabled (by setting
DatabaseModule.PROPKEY_UPDATEDATABASESCHEMA_ENABLED to true), the test database
schema will automatically be updated if needed. This check will be performed once during your test-suite run, namely
when the data source is created. See
DBMaintainer javadoc for more information on how this update is performed.
author: Filip Neven author: Tim Ducheyne |
Inner Class :protected class DatabaseTestListener extends TestListener | |
PROPKEY_UPDATEDATABASESCHEMA_ENABLED | final public static String PROPKEY_UPDATEDATABASESCHEMA_ENABLED(Code) | | |
cleanSchemas | public void cleanSchemas()(Code) | | Cleans all configured schema's. I.e. removes all data from its database tables.
|
clearSchemas | public void clearSchemas()(Code) | | Clears all configured schema's. I.e. drops all tables, views and other database objects.
|
createDataSource | protected TransactionalDataSource createDataSource()(Code) | | Creates a datasource by using the factory that is defined by the dataSourceFactory.className property
the datasource |
createTransactionManager | protected TransactionManager createTransactionManager()(Code) | | An instance of the transactionManager, as configured in the Unitils configuration |
disableConstraints | public void disableConstraints()(Code) | | Disables all foreigh key and not-null constraints on the configured schema's.
|
endTransaction | protected void endTransaction(Object testObject)(Code) | | Commits or rollbacks the current transaction, if transactions are enabled and a transactionManager is
active for the given testObject
Parameters: testObject - The test object, not null |
flushDatabaseUpdates | public void flushDatabaseUpdates(Object testObject)(Code) | | Flushes all pending updates to the database. This method is useful when the effect of updates needs to
be checked directly on the database.
This will look for modules that implement
Flushable and call flushDatabaseUpdates on these module.
Parameters: testObject - TODO |
generateDatasetDefinition | public void generateDatasetDefinition()(Code) | | Generates a definition file that defines the structure of dataset's, i.e. a XSD of DTD that
describes the structure of the database.
|
getDataSource | public TransactionalDataSource getDataSource()(Code) | | Returns the DataSource that provides connection to the unit test database. When invoked the first
time, the DBMaintainer is invoked to make sure the test database is up-to-date (if database updating is enabled)
The DataSource |
getDefaultSqlHandler | protected SQLHandler getDefaultSqlHandler()(Code) | | The default SQLHandler, which simply executes the sql statements on the unitils-configuredtest database |
getTransactionManager | public TransactionManager getTransactionManager()(Code) | | Gets the transaction manager or creates one if it does not exist yet.
The transaction manager, not null |
init | public void init(Properties configuration)(Code) | | Initializes this module using the given Configuration
Parameters: configuration - the config, not null |
injectDataSource | public void injectDataSource(Object testObject)(Code) | | Assigns the TestDataSource to every field annotated with
TestDataSource and calls all methods
annotated with
TestDataSource Parameters: testObject - The test instance, not null |
setDatabaseToCurrentVersion | public void setDatabaseToCurrentVersion()(Code) | | 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.
|
setDatabaseToCurrentVersion | public void setDatabaseToCurrentVersion(SQLHandler sqlHandler)(Code) | | 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.
Parameters: sqlHandler - The SQLHandler to which all commands are issued |
startTransaction | public void startTransaction(Object testObject)(Code) | | Starts a transaction. If the Unitils DataSource was not loaded yet, we simply remember that a
transaction was started but don't actually start it. If the DataSource is loaded within this
test, the transaction will be started immediately after loading the DataSource.
Parameters: testObject - The test object, not null |
updateDatabase | public void updateDatabase()(Code) | | 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.
|
updateDatabase | public void updateDatabase(SQLHandler sqlHandler)(Code) | | todo make configurable using properties
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.
Parameters: sqlHandler - SQLHandler that needs to be used for the database updates |
updateSequences | public void updateSequences()(Code) | | Updates all sequences that have a value below a certain configurable treshold to become equal
to this treshold
|
|
|