org.dbmaintain.script.analyzer
Class ScriptUpdatesAnalyzer

java.lang.Object
  extended by org.dbmaintain.script.analyzer.ScriptUpdatesAnalyzer

public class ScriptUpdatesAnalyzer
extends Object

An instance of this class can compare the info that we have about previously executed scripts with the new scripts. It decides which of these scripts were added, updated, deleted or renamed. It also decides for each script update whether it is a regular or irregular one.

Since:
29-dec-2008
Author:
Filip Neven, Tim Ducheyne

Constructor Summary
ScriptUpdatesAnalyzer(ScriptRepository scriptRepository, ExecutedScriptInfoSource executedScriptInfoSource, boolean useScriptFileLastModificationDates, boolean allowOutOfSequenceExecutionOfPatchScripts)
          Creates a new instance that will compare the info from the given ExecutedScriptInfoSource with the current scripts from the given ScriptRepository.
 
Method Summary
 ScriptUpdates calculateScriptUpdates()
          Compares the info that we have about previously executed scripts with the new scripts.
protected  Script findNewScriptWithSameContent(ExecutedScript executedScript)
           
protected  Script findScriptWithSameName(ExecutedScript executedScript)
           
protected  Map<String,Set<Script>> getCheckSumScriptMap()
           
protected  Script getExecutedScriptWithHighestScriptIndex()
           
protected  Map<String,ExecutedScript> getScriptNameExecutedScriptMap()
           
protected  Map<String,Script> getScriptNameScriptMap()
           
protected  void registerIrregularIncrementalScriptRenames()
          Take all script renames that were registered using the method registerScriptRename(ExecutedScript, Script) and register them all as irregular script renames.
protected  void registerIrregularScriptUpdate(ScriptUpdateType scriptUpdateType, Script script)
           
protected  void registerIrregularScriptUpdate(ScriptUpdateType scriptUpdateType, Script script1, Script script2)
           
protected  void registerPostprocessingScriptRename(ScriptUpdateType scriptUpdateType, Script originalScript, Script renamedToScript)
           
protected  void registerPostprocessingScriptUpdate(ScriptUpdateType scriptUpdateType, Script script)
           
protected  void registerRegularIncrementalScriptRenames()
          Take all script renames that were registered using the method registerScriptRename(ExecutedScript, Script) and register them all as regular script renames.
protected  void registerRegularlyAddedPatchScript(ScriptUpdateType scriptUpdateType, Script script)
           
protected  void registerRegularScriptRename(ScriptUpdateType scriptUpdateType, Script originalScript, Script renamedScript)
           
protected  void registerRegularScriptUpdate(ScriptUpdateType scriptUpdateType, Script script)
           
protected  void registerRepeatableScriptDeletion(Script script)
           
protected  void registerScriptAddition(Script script)
          Register the given script as a newly added one
protected  void registerScriptDeletion(Script deletedScript)
          Register that the given script has been deleted since the last update
protected  void registerScriptRename(ExecutedScript executedScript, Script renamedTo)
          Register that the given script has been renamed to the given new script since the last update
protected  void registerScriptUpdate(Script script)
          Register that the given script's content has changed since the last update
protected  boolean sequenceOfIndexedScriptsChangedDueToRenames()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptUpdatesAnalyzer

public ScriptUpdatesAnalyzer(ScriptRepository scriptRepository,
                             ExecutedScriptInfoSource executedScriptInfoSource,
                             boolean useScriptFileLastModificationDates,
                             boolean allowOutOfSequenceExecutionOfPatchScripts)
Creates a new instance that will compare the info from the given ExecutedScriptInfoSource with the current scripts from the given ScriptRepository. It also needs to know whether a new patch script with a lower index is a regular or irregular script update

Parameters:
scriptRepository - exposes the current set of scripts
executedScriptInfoSource - provides info on the script that were executed on the database
useScriptFileLastModificationDates - whether the last modification date of the scripts can be used to determine if a script has changed.
allowOutOfSequenceExecutionOfPatchScripts - whether scripts marked as patch scripts may be executed out-of-sequence
Method Detail

calculateScriptUpdates

public ScriptUpdates calculateScriptUpdates()
Compares the info that we have about previously executed scripts with the new scripts. It decides which of these scripts were added, updated, deleted or renamed. It also decides for each script update whether it is a regular or irregular one.

Returns:
ScriptUpdates object that represents all updates that were performed to the scripts since the last database update

registerScriptAddition

protected void registerScriptAddition(Script script)
Register the given script as a newly added one

Parameters:
script - The newly added script

registerScriptUpdate

protected void registerScriptUpdate(Script script)
Register that the given script's content has changed since the last update

Parameters:
script - The script who's content has changed

registerScriptDeletion

protected void registerScriptDeletion(Script deletedScript)
Register that the given script has been deleted since the last update

Parameters:
deletedScript - The script that has been deleted

registerScriptRename

protected void registerScriptRename(ExecutedScript executedScript,
                                    Script renamedTo)
Register that the given script has been renamed to the given new script since the last update

Parameters:
executedScript - The script like it was during the last update
renamedTo - The renamed script

sequenceOfIndexedScriptsChangedDueToRenames

protected boolean sequenceOfIndexedScriptsChangedDueToRenames()
Returns:
whether the sequence of the indexed scripts has changed due to indexed scripts that were renamed since the last update

registerRegularIncrementalScriptRenames

protected void registerRegularIncrementalScriptRenames()
Take all script renames that were registered using the method registerScriptRename(ExecutedScript, Script) and register them all as regular script renames.


registerIrregularIncrementalScriptRenames

protected void registerIrregularIncrementalScriptRenames()
Take all script renames that were registered using the method registerScriptRename(ExecutedScript, Script) and register them all as irregular script renames.


findNewScriptWithSameContent

protected Script findNewScriptWithSameContent(ExecutedScript executedScript)
Parameters:
executedScript - The script as executed during a previous update
Returns:
A script that is not yet mapped to an executed script, but that has the same content as the given one

findScriptWithSameName

protected Script findScriptWithSameName(ExecutedScript executedScript)
Parameters:
executedScript - A script as executed during a previous update
Returns:
The script with the same name as the given one

getScriptNameExecutedScriptMap

protected Map<String,ExecutedScript> getScriptNameExecutedScriptMap()
Returns:
The already executed scripts, as a map from scriptName => ExecutedScript

getScriptNameScriptMap

protected Map<String,Script> getScriptNameScriptMap()
Returns:
All scripts, as a map from scriptName => Script

getCheckSumScriptMap

protected Map<String,Set<Script>> getCheckSumScriptMap()
Returns:
All scripts, as a map from checksum => Script

getExecutedScriptWithHighestScriptIndex

protected Script getExecutedScriptWithHighestScriptIndex()
Returns:
The executed scripts with the highest script index

registerRegularScriptUpdate

protected void registerRegularScriptUpdate(ScriptUpdateType scriptUpdateType,
                                           Script script)

registerIrregularScriptUpdate

protected void registerIrregularScriptUpdate(ScriptUpdateType scriptUpdateType,
                                             Script script)

registerIrregularScriptUpdate

protected void registerIrregularScriptUpdate(ScriptUpdateType scriptUpdateType,
                                             Script script1,
                                             Script script2)

registerRepeatableScriptDeletion

protected void registerRepeatableScriptDeletion(Script script)

registerRegularlyAddedPatchScript

protected void registerRegularlyAddedPatchScript(ScriptUpdateType scriptUpdateType,
                                                 Script script)

registerPostprocessingScriptUpdate

protected void registerPostprocessingScriptUpdate(ScriptUpdateType scriptUpdateType,
                                                  Script script)

registerPostprocessingScriptRename

protected void registerPostprocessingScriptRename(ScriptUpdateType scriptUpdateType,
                                                  Script originalScript,
                                                  Script renamedToScript)

registerRegularScriptRename

protected void registerRegularScriptRename(ScriptUpdateType scriptUpdateType,
                                           Script originalScript,
                                           Script renamedScript)


Copyright © 2011. All Rights Reserved.