org.dbmaintain.script
Class Script

java.lang.Object
  extended by org.dbmaintain.script.Script
All Implemented Interfaces:
Comparable<Script>

public class Script
extends Object
implements Comparable<Script>

A class representing a script file and it's content.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
Script(String fileName, ScriptIndexes scriptIndexes, String targetDatabaseName, Long fileLastModifiedAt, String checkSum, ScriptContentHandle scriptContentHandle, boolean postProcessingScript, boolean patchScript, boolean ignored, Set<Qualifier> qualifiers)
          Creates a script with the given fileName and content or checksum.
 
Method Summary
 int compareTo(Script script)
          Compares the given script to this script by comparing the versions.
 boolean equals(Object object)
           
 String getCheckSum()
           
 Long getFileLastModifiedAt()
           
 String getFileName()
           
 String getFileNameWithoutPath()
           
 Set<Qualifier> getQualifiers()
           
 ScriptContentHandle getScriptContentHandle()
           
 ScriptIndexes getScriptIndexes()
           
 String getTargetDatabaseName()
           
 int hashCode()
           
 boolean isIgnored()
           
 boolean isIncremental()
           
 boolean isPatchScript()
           
 boolean isPostProcessingScript()
           
 boolean isRepeatable()
           
 boolean isScriptContentEqualTo(Script other, boolean useLastModificationDates)
           
 String toString()
          Gets a string representation of this script.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Script

public Script(String fileName,
              ScriptIndexes scriptIndexes,
              String targetDatabaseName,
              Long fileLastModifiedAt,
              String checkSum,
              ScriptContentHandle scriptContentHandle,
              boolean postProcessingScript,
              boolean patchScript,
              boolean ignored,
              Set<Qualifier> qualifiers)
Creates a script with the given fileName and content or checksum. If rhe contents of the script is know, a script content handle should be provided and the checksum can be left null. Otherwise leave the script content handle null and provide a checksum. This makes it possible to perform checks with the script (e.g. verify that the contents are equal) without having the content. The script can then ofcourse not be executed.

Parameters:
fileName - The name of the script file, not null
scriptIndexes - The indexes of the script, not null
targetDatabaseName - The target database, null if there is no target database
fileLastModifiedAt - The time when the file was last modified (in ms), not null
checkSum - Checksum calculated for the contents of the file, leave null if a script content handle is provided
scriptContentHandle - Handle providing access to the contents of the script, null if the content is unknown (a checksum is then required)
postProcessingScript - True if this script is a post processing script
patchScript - True if this script is a patch script (has a patch qualifier)
ignored - True if this script should be ignored (because the revision is lower than the baseline revision)
qualifiers - The qualifiers of this script, not null
Method Detail

getFileName

public String getFileName()
Returns:
The script name, not null

getFileNameWithoutPath

public String getFileNameWithoutPath()
Returns:
The script name without the path, not null

getScriptIndexes

public ScriptIndexes getScriptIndexes()
Returns:
The version indexes, not null

getTargetDatabaseName

public String getTargetDatabaseName()
Returns:
Logical name that indicates the target database on which this script must be executed. Can be null to indicate that it must be executed on the default target database.

getFileLastModifiedAt

public Long getFileLastModifiedAt()
Returns:
The timestamp at which the file in which this script is stored on the filesystem was last modified. Be careful: This can also be the timestamp on which this file was retrieved from the sourcde control system. If the timestamp wasn't changed, we're almost 100% sure that this file has not been modified. If changed, this file is possibly modified (but the reason might also be that a fresh checkout has been made from the version control system, or that the script was applied from another workstation or from another copy of the project), not null

getCheckSum

public String getCheckSum()
Returns:
Checksum calculated for the content of the script, not null

getScriptContentHandle

public ScriptContentHandle getScriptContentHandle()
Returns:
Handle that provides access to the content of the script. May be null! If so, this object is not suitable for being executed. The checksum however cannot be null, so we can always verify if the contents of the script are equal to another one.

isScriptContentEqualTo

public boolean isScriptContentEqualTo(Script other,
                                      boolean useLastModificationDates)
Parameters:
other - Another script, not null
useLastModificationDates - If true, this method first checks if the lastModifiedAt property of this Script is equal to the given one. If equal, we assume that the contents are also equal and we don't compare the checksums. If not equal, we compare the checksums to find out whether there is a difference. By setting this value to true, performance is heavily improved when you check for updates regularly from the same workstation (which is the case when you use unitils's automatic database maintenance for testing). This is because, to calculate a checksum, the script contents have to be read. This can take a few seconds to complete, which we want to avoid since a check for database updates is started every time a test is launched that accesses the test database. For applying changes to an environment that can only be updated incrementally (e.g. a database use by testers or even the production database), this parameter should be false, since working with last modification dates is not guaranteed to be 100% bulletproof (although unlikely, it is possible that a different version of the same file is checked out on different systems on exactly the same time).
Returns:
True if the contents of this script are equal to the given one, false otherwise

isIncremental

public boolean isIncremental()
Returns:
True if this is an incremental script, i.e. it needs to be executed in the correct order, and it can be executed only once. If an incremental script is changed, the database needs to be recreated from scratch, or an error must be reported.

isRepeatable

public boolean isRepeatable()

isPostProcessingScript

public boolean isPostProcessingScript()
Returns:
True if this script is a postprocessing script

isIgnored

public boolean isIgnored()
Returns:
True if this script is ignored because it falls below the baseline revision

isPatchScript

public boolean isPatchScript()
Returns:
True if this script is a patch script

getQualifiers

public Set<Qualifier> getQualifiers()
Returns:
The qualifiers of this script, not null

compareTo

public int compareTo(Script script)
Compares the given script to this script by comparing the versions. Can be used to define the proper execution sequence of the scripts.

Specified by:
compareTo in interface Comparable<Script>
Parameters:
script - The other script, not null
Returns:
-1 when this script has a smaller version, 0 if equal, 1 when larger

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
A hashcode value computed out of the filename

equals

public boolean equals(Object object)
Overrides:
equals in class Object
Parameters:
object - The object to compare with
Returns:
True if both scripts have the same file name

toString

public String toString()
Gets a string representation of this script.

Overrides:
toString in class Object
Returns:
The name and version, not null


Copyright © 2011. All Rights Reserved.