|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.dbmaintainer.DBMaintainer
public class DBMaintainer
A class for performing automatic maintenance of a database.
This class must be configured with implementations of a ExecutedScriptInfoSource
,
ScriptSource
, a ScriptRunner
, DBClearer
, DBCleaner
,
ConstraintsDisabler
, SequenceUpdater
and a DataSetStructureGenerator
updateDatabase()
method check what is the current version of the database, and
see if existing scripts have been modified. If yes, the database is cleared and all available
database scripts, are executed on the database. If no existing scripts have been modified, but
new scripts were added, only the new scripts are executed. Before executing an update, data from
the database is removed, to avoid problems when e.g. adding a not null column. If a database
update causes an error, a UnitilsException
is thrown. After a failing update, the
database is always completely recreated from scratch. After updating the database, following
steps are optionally executed on the database (depending on the configuration):
DBMaintainer
, invoke the constructor
DBMaintainer(Properties,SQLHandler)
with a TestDataSource
providing
access to the database and a Configuration
object containing all necessary
properties.
Field Summary | |
---|---|
protected ConstraintsDisabler |
constraintsDisabler
Disabler of constraints |
protected DataSetStructureGenerator |
dataSetStructureGenerator
Database DTD generator |
protected DBCleaner |
dbCleaner
Cleaner of the database (deletes all data from all tables before updating |
protected DBClearer |
dbClearer
Clearer of the database (removed all tables, sequences, ...) before updating |
protected boolean |
disableConstraintsEnabled
Indicates if foreign key and not null constraints should removed after updating the database structure |
protected boolean |
fromScratchEnabled
Indicates whether updating the database from scratch is enabled. |
protected boolean |
keepRetryingAfterError
Indicates whether a from scratch update should be performed when the previous update failed, but none of the scripts were modified since that last update. |
static String |
PROPKEY_CLEAR_DB_CODE_ENABLED
Property indicating if database code should be cleared before installing a new version of the code or when updating the database from scratch |
static String |
PROPKEY_DB_CLEANER_ENABLED
Property indicating if deleting all data from all tables before updating is enabled |
static String |
PROPKEY_DISABLE_CONSTRAINTS_ENABLED
Property indicating if the database constraints should org disabled after updating the database |
static String |
PROPKEY_FROM_SCRATCH_ENABLED
Property indicating if updating the database from scratch is enabled |
static String |
PROPKEY_GENERATE_DATA_SET_STRUCTURE_ENABLED
Property that indicates if a data set DTD or XSD is to be generated or not |
static String |
PROPKEY_KEEP_RETRYING_AFTER_ERROR_ENABLED
Property indicating if an retry of an update should only be performed when changes to script files were made |
static String |
PROPKEY_UPDATE_SEQUENCES_ENABLED
Property indicating if the database constraints should org disabled after updating the database |
protected ScriptRunner |
scriptRunner
Executer of the scripts |
protected ScriptSource |
scriptSource
Provider of scripts for updating the database to a higher version |
protected SequenceUpdater |
sequenceUpdater
Database sequence updater |
protected ExecutedScriptInfoSource |
versionSource
Provider of the current version of the database, and means to increment it |
Constructor Summary | |
---|---|
protected |
DBMaintainer()
Default constructor for testing. |
|
DBMaintainer(Properties configuration,
SQLHandler sqlHandler)
Create a new instance of DBMaintainer , The concrete implementations of all
helper classes are derived from the given Configuration object. |
Method Summary | |
---|---|
protected boolean |
errorInIndexedScriptDuringLastUpdate(Set<ExecutedScript> alreadyExecutedScripts)
|
protected void |
executePostProcessingScripts(List<Script> postProcessingScripts)
Executes the given post processing scripts on the database. |
protected void |
executeScripts(List<Script> scripts)
Executes the given scripts and updates the database version and state appropriatly. |
protected Version |
getHighestExecutedScriptVersion(Set<ExecutedScript> executedScripts)
|
void |
resetDatabaseState()
Updates the database version to the current version of the update scripts, without changing anything else in the database. |
protected boolean |
shouldUpdateDatabaseFromScratch(Version currentVersion,
Set<ExecutedScript> alreadyExecutedScripts)
Checks whether the database should be updated from scratch or just incrementally. |
void |
updateDatabase()
Checks if the new scripts are available to update the version of the database. |
protected void |
updateDatabase(List<Script> scripts)
Updates the state of the database using the given scripts. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PROPKEY_DB_CLEANER_ENABLED
public static final String PROPKEY_FROM_SCRATCH_ENABLED
public static final String PROPKEY_CLEAR_DB_CODE_ENABLED
public static final String PROPKEY_KEEP_RETRYING_AFTER_ERROR_ENABLED
public static final String PROPKEY_DISABLE_CONSTRAINTS_ENABLED
public static final String PROPKEY_UPDATE_SEQUENCES_ENABLED
public static final String PROPKEY_GENERATE_DATA_SET_STRUCTURE_ENABLED
protected ExecutedScriptInfoSource versionSource
protected ScriptSource scriptSource
protected ScriptRunner scriptRunner
protected DBClearer dbClearer
protected DBCleaner dbCleaner
protected ConstraintsDisabler constraintsDisabler
protected SequenceUpdater sequenceUpdater
protected DataSetStructureGenerator dataSetStructureGenerator
protected boolean fromScratchEnabled
protected boolean disableConstraintsEnabled
protected boolean keepRetryingAfterError
Constructor Detail |
---|
protected DBMaintainer()
public DBMaintainer(Properties configuration, SQLHandler sqlHandler)
DBMaintainer
, The concrete implementations of all
helper classes are derived from the given Configuration
object.
configuration
- the configuration, not nullsqlHandler
- the data source, not nullMethod Detail |
---|
public void updateDatabase()
UnitilsException
is thrown.
protected Version getHighestExecutedScriptVersion(Set<ExecutedScript> executedScripts)
public void resetDatabaseState()
protected void updateDatabase(List<Script> scripts)
scripts
- The scripts, not nullprotected void executeScripts(List<Script> scripts)
scripts
- The scripts to execute, not nullprotected void executePostProcessingScripts(List<Script> postProcessingScripts)
postProcessingScripts
- The scripts to execute, not nullprotected boolean shouldUpdateDatabaseFromScratch(Version currentVersion, Set<ExecutedScript> alreadyExecutedScripts)
PROPKEY_FROM_SCRATCH_ENABLED
is
set to true. If the PROPKEY_KEEP_RETRYING_AFTER_ERROR_ENABLED
is set to false, the
database will only be rebuilt again after an unsuccessful build when changes were made to the
script files.
currentVersion
- The current database version, not null
protected boolean errorInIndexedScriptDuringLastUpdate(Set<ExecutedScript> alreadyExecutedScripts)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |