org.dbmaintain.script.executedscriptinfo.impl
Class DefaultExecutedScriptInfoSource

java.lang.Object
  extended by org.dbmaintain.script.executedscriptinfo.impl.DefaultExecutedScriptInfoSource
All Implemented Interfaces:
ExecutedScriptInfoSource

public class DefaultExecutedScriptInfoSource
extends Object
implements ExecutedScriptInfoSource

Implementation of VersionSource that stores the version in the database.

Author:
Filip Neven, Tim Ducheyne

Field Summary
protected  boolean autoCreateExecutedScriptsTable
           
protected  SortedSet<ExecutedScript> cachedExecutedScripts
           
protected  String checksumColumnName
           
protected  int checksumColumnSize
           
protected  Database defaultDatabase
           
protected  String executedAtColumnName
           
protected  int executedAtColumnSize
           
protected  String executedScriptsTableName
           
protected  String fileLastModifiedAtColumnName
           
protected  String fileNameColumnName
           
protected  int fileNameColumnSize
           
protected  ScriptFactory scriptFactory
           
protected  SQLHandler sqlHandler
           
protected  String succeededColumnName
           
protected  DateFormat timestampFormat
           
protected  boolean validExecutedScriptsTable
           
 
Constructor Summary
DefaultExecutedScriptInfoSource(boolean autoCreateExecutedScriptsTable, String executedScriptsTableName, String fileNameColumnName, int fileNameColumnSize, String fileLastModifiedAtColumnName, String checksumColumnName, int checksumColumnSize, String executedAtColumnName, int executedAtColumnSize, String succeededColumnName, DateFormat timestampFormat, Database defaultSupport, SQLHandler sqlHandler, ScriptFactory scriptFactory)
           
 
Method Summary
protected  boolean checkExecutedScriptsTable()
          Checks if the version table and columns are available and if a record exists in which the version info is stored.
 void clearAllExecutedScripts()
          Clears all script executions that have been registered.
protected  void createExecutedScriptsTable()
          Creates the version table and inserts a version record.
 void deleteAllExecutedPostprocessingScripts()
          Removes all previously registered executed postprocessing scripts
 void deleteExecutedScript(ExecutedScript executedScript)
          Remove the given executed script from the executed scripts
protected  SortedSet<ExecutedScript> doGetExecutedScripts()
          Precondition: The table db_executed_scripts must exist
protected  String getCreateExecutedScriptTableStatement()
           
 SortedSet<ExecutedScript> getExecutedScripts()
           
protected  String getQualifiedExecutedScriptsTableName()
           
protected  void insertExecutedScript(ExecutedScript executedScript)
          Saves the given registered script Precondition: The table db_executed_scripts must exist
protected  boolean isExecutedScriptsTableValid()
          Checks if the version table and columns are available and if a record exists in which the version info is stored.
 void markErrorScriptsAsSuccessful()
          Marks the failed scripts in the executed scripts table as successful.
 void registerExecutedScript(ExecutedScript executedScript)
          Registers the fact that the given script has been executed on the database
 void removeErrorScripts()
          Removes the failed scripts in the executed scripts table.
 void renameExecutedScript(ExecutedScript executedScript, Script renamedToScript)
          Registers the fact that the script that was originally executed has been renamed.
 void resetCachedState()
          Resets the cached state, for example when the scripts table was modified by another process.
 void updateExecutedScript(ExecutedScript executedScript)
          Updates the given registered script
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedExecutedScripts

protected SortedSet<ExecutedScript> cachedExecutedScripts

defaultDatabase

protected Database defaultDatabase

sqlHandler

protected SQLHandler sqlHandler

executedScriptsTableName

protected String executedScriptsTableName

fileNameColumnName

protected String fileNameColumnName

fileNameColumnSize

protected int fileNameColumnSize

fileLastModifiedAtColumnName

protected String fileLastModifiedAtColumnName

checksumColumnName

protected String checksumColumnName

checksumColumnSize

protected int checksumColumnSize

executedAtColumnName

protected String executedAtColumnName

executedAtColumnSize

protected int executedAtColumnSize

succeededColumnName

protected String succeededColumnName

autoCreateExecutedScriptsTable

protected boolean autoCreateExecutedScriptsTable

timestampFormat

protected DateFormat timestampFormat

validExecutedScriptsTable

protected boolean validExecutedScriptsTable

scriptFactory

protected ScriptFactory scriptFactory
Constructor Detail

DefaultExecutedScriptInfoSource

public DefaultExecutedScriptInfoSource(boolean autoCreateExecutedScriptsTable,
                                       String executedScriptsTableName,
                                       String fileNameColumnName,
                                       int fileNameColumnSize,
                                       String fileLastModifiedAtColumnName,
                                       String checksumColumnName,
                                       int checksumColumnSize,
                                       String executedAtColumnName,
                                       int executedAtColumnSize,
                                       String succeededColumnName,
                                       DateFormat timestampFormat,
                                       Database defaultSupport,
                                       SQLHandler sqlHandler,
                                       ScriptFactory scriptFactory)
Method Detail

getExecutedScripts

public SortedSet<ExecutedScript> getExecutedScripts()
Specified by:
getExecutedScripts in interface ExecutedScriptInfoSource
Returns:
All scripts that were registered as executed on the database

doGetExecutedScripts

protected SortedSet<ExecutedScript> doGetExecutedScripts()
Precondition: The table db_executed_scripts must exist

Returns:
All scripts that were registered as executed on the database

registerExecutedScript

public void registerExecutedScript(ExecutedScript executedScript)
Registers the fact that the given script has been executed on the database

Specified by:
registerExecutedScript in interface ExecutedScriptInfoSource
Parameters:
executedScript - The script that was executed on the database

insertExecutedScript

protected void insertExecutedScript(ExecutedScript executedScript)
Saves the given registered script Precondition: The table db_executed_scripts must exist

Parameters:
executedScript - The script that needs to be saved, not null

updateExecutedScript

public void updateExecutedScript(ExecutedScript executedScript)
Updates the given registered script

Specified by:
updateExecutedScript in interface ExecutedScriptInfoSource
Parameters:
executedScript - The script that needs to be updated, not null

deleteExecutedScript

public void deleteExecutedScript(ExecutedScript executedScript)
Remove the given executed script from the executed scripts

Specified by:
deleteExecutedScript in interface ExecutedScriptInfoSource
Parameters:
executedScript - The executed script, which is no longer part of the executed scripts

renameExecutedScript

public void renameExecutedScript(ExecutedScript executedScript,
                                 Script renamedToScript)
Registers the fact that the script that was originally executed has been renamed.

Specified by:
renameExecutedScript in interface ExecutedScriptInfoSource
Parameters:
executedScript - the original executed script that still refers to the original script
renamedToScript - the script to which the original script has been renamed

deleteAllExecutedPostprocessingScripts

public void deleteAllExecutedPostprocessingScripts()
Description copied from interface: ExecutedScriptInfoSource
Removes all previously registered executed postprocessing scripts

Specified by:
deleteAllExecutedPostprocessingScripts in interface ExecutedScriptInfoSource

clearAllExecutedScripts

public void clearAllExecutedScripts()
Clears all script executions that have been registered. After having invoked this method, getExecutedScripts() will return an empty set.

Specified by:
clearAllExecutedScripts in interface ExecutedScriptInfoSource

markErrorScriptsAsSuccessful

public void markErrorScriptsAsSuccessful()
Marks the failed scripts in the executed scripts table as successful.

Specified by:
markErrorScriptsAsSuccessful in interface ExecutedScriptInfoSource

removeErrorScripts

public void removeErrorScripts()
Removes the failed scripts in the executed scripts table.

Specified by:
removeErrorScripts in interface ExecutedScriptInfoSource

checkExecutedScriptsTable

protected boolean checkExecutedScriptsTable()
Checks if the version table and columns are available and if a record exists in which the version info is stored. If not, the table, columns and record are created if auto-create is true, else an exception is raised.

Returns:
false if the version table was not ok and therefore auto-created

isExecutedScriptsTableValid

protected boolean isExecutedScriptsTableValid()
Checks if the version table and columns are available and if a record exists in which the version info is stored. If not, the table, columns and record are created.

Returns:
False if the version table was not ok and therefore re-created

createExecutedScriptsTable

protected void createExecutedScriptsTable()
Creates the version table and inserts a version record.


getCreateExecutedScriptTableStatement

protected String getCreateExecutedScriptTableStatement()
Returns:
The statement to create the version table.

getQualifiedExecutedScriptsTableName

protected String getQualifiedExecutedScriptsTableName()

resetCachedState

public void resetCachedState()
Resets the cached state, for example when the scripts table was modified by another process. The scripts will be reloaded the next time.

Specified by:
resetCachedState in interface ExecutedScriptInfoSource


Copyright © 2011. All Rights Reserved.