com.agimatec.dbmigrate
Class AutoMigrationTool

java.lang.Object
  extended by com.agimatec.dbmigrate.BaseMigrationTool
      extended by com.agimatec.dbmigrate.AutoMigrationTool
All Implemented Interfaces:
MigrationTool

public class AutoMigrationTool
extends BaseMigrationTool

Automatical database migration program for Agimatec GmbH

 Features:
 01- detect from-version from database or config-file
 02- execute sql-scripts or commands from a config file for
     all files that belong to versions later than "from-version".
 03- automatic script detection and sorting.
 04- can stop execution at "to-version", if set in config-file.
 05- supports conditional execution in sql-scripts (-- #if #endif syntax)
 06- support conditional execution in config-files (list-tags)
 07- supports enviroment variables in sql-scripts ( ${variable} syntax )
 08- supports connect commands in SQL-scripts
 09- a) supports local-enviroment variables per config-file of each migration version,
     b) environment variables per migration config,
     c) all JVM System-Properties are accessible as environment variable default
 10- supports Simulation-mode "with jvm parameter -Dsim=true" to check
     behavior before affecting the system.
 11- supports subscripts (@scriptname.sql; syntax)
 12 - supports db_version upgrade with setVersion(dbversion)-method
      or -- @version(dbversion) script-directive
 13 - runs all scripts as files or as classpath resource
 14 - (optional) automatically create db_version table
 15 - (optional) automatically set version in db_version table after script execution
 16 - can be integrated into grails project (see plugin viaboxx-dbmigrate)
 17 - runs sql, xml or groovy script (auto-detect by file suffix)
 
Author: Roman Stumm Date: 2007, 2008, 2009, 2010
 final String sim = System.getProperty(SYSTEM_PROPERTY_SIM);
 sim = "true"|"yes" :: simulation, echo execution sequence into log, but do not invoke any script
 otherwise (=default) :: execute scripts/java in sequence
 


Field Summary
 
Fields inherited from class com.agimatec.dbmigrate.BaseMigrationTool
dbVersionMeta, log, migrateConfigFileName, targetDatabase
 
Constructor Summary
AutoMigrationTool()
           
 
Method Summary
 void addActionsAfterAll(String dir, List<MigrateAction> actions)
           
 List<MigrateAction> createUpgradeActions(String scriptDir, boolean enableAutoVersion)
          create some up- actions of a custom script dir dependent on current version
 void doXmlScript(String filePath)
           
 List<MigrateAction> getActionOverride()
           
 String getAfterAllScriptsDir()
           
 String getBeforeAllScriptsDir()
           
 Map getEnvironment()
          a map for environment properties (JVM System-Properties overwrite these properties) (to be used to conditional execution of statements in SQL scripts)
 DBVersionString getFromVersion()
           
 Map getLocalEnv()
           
protected  Map getMigrateEnvironment()
           
 String getScriptPrefix()
           
 DBVersionString getToVersion()
           
 boolean isSim()
           
static void main(String[] args)
          run the tool and exit the JVM afterwards.
 void performActions(List<MigrateAction> actionOverride)
           
protected  void prepareLocalEnvironment(Config cfg)
           
 DBVersionString readVersion()
          read the version from the database
 void setActionOverride(List<MigrateAction> actionOverride)
           
 void setLocalEnv(Map localEnv)
           
 void setSim(boolean sim)
           
 void startAutomaticMigration()
           
 
Methods inherited from class com.agimatec.dbmigrate.BaseMigrationTool
acceptDirectoryForSQLParser, applyEnvironment, checkObjectsValid, checkSchemaComplete, commit, connectTargetDatabase, copyFiles, createDatabase, dbDump, dbSetup, disconnectDatabase, doGroovyScript, doMethodOperation, doSQLScript, doSQLScriptIgnoreErrors, execSQLScript, findMethod, getDbVersionMeta, getGroovyScriptsDirs, getJdbcConfigFile, getLog, getMigrateConfig, getOperations, getScriptsDir, getTargetDatabase, halt, invokeBean, invokeBeanCallbacks, invokeClassMethod, invokeStatic, iterateSQLScript, log, perform, print, replaceProperties, rollback, setMigrateConfigFileName, setScriptsDir, setTargetDatabase, setUp, setupVersionMeta, splitMethodArgs, splitParams, sqlExec, sqlSelect, tearDown, terminateTransactions, version
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoMigrationTool

public AutoMigrationTool()
Method Detail

main

public static void main(String[] args)
run the tool and exit the JVM afterwards.

Throws:
Exception - exit(0) = successful exit(1) = in case of an exception

isSim

public boolean isSim()

getEnvironment

public Map getEnvironment()
Description copied from class: BaseMigrationTool
a map for environment properties (JVM System-Properties overwrite these properties) (to be used to conditional execution of statements in SQL scripts)

Specified by:
getEnvironment in interface MigrationTool
Overrides:
getEnvironment in class BaseMigrationTool
Returns:
a map (do not modify!)

getMigrateEnvironment

protected Map getMigrateEnvironment()

startAutomaticMigration

public void startAutomaticMigration()
                             throws Exception
Throws:
Exception

performActions

public void performActions(List<MigrateAction> actionOverride)
                    throws Exception
Throws:
Exception

prepareLocalEnvironment

protected void prepareLocalEnvironment(Config cfg)

doXmlScript

public void doXmlScript(String filePath)
                 throws Exception
Throws:
Exception

getToVersion

public DBVersionString getToVersion()

getFromVersion

public DBVersionString getFromVersion()
                               throws SQLException
Throws:
SQLException

readVersion

public DBVersionString readVersion()
                            throws SQLException
read the version from the database

Throws:
SQLException

addActionsAfterAll

public void addActionsAfterAll(String dir,
                               List<MigrateAction> actions)
                        throws IOException
Throws:
IOException

createUpgradeActions

public List<MigrateAction> createUpgradeActions(String scriptDir,
                                                boolean enableAutoVersion)
                                         throws SQLException,
                                                IOException
create some up- actions of a custom script dir dependent on current version

Parameters:
scriptDir -
enableAutoVersion -
Returns:
Throws:
SQLException
IOException

getScriptPrefix

public String getScriptPrefix()

getBeforeAllScriptsDir

public String getBeforeAllScriptsDir()

getAfterAllScriptsDir

public String getAfterAllScriptsDir()

getLocalEnv

public Map getLocalEnv()

getActionOverride

public List<MigrateAction> getActionOverride()

setActionOverride

public void setActionOverride(List<MigrateAction> actionOverride)

setSim

public void setSim(boolean sim)

setLocalEnv

public void setLocalEnv(Map localEnv)


Copyright © 2008-2011. All Rights Reserved.