com.agimatec.dbmigrate
Class BaseMigrationTool

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

public abstract class BaseMigrationTool
extends Object
implements MigrationTool

Title: Agimatec GmbH

Description: Base class for Migration and Testcases. Provides infrastructure and common utilities.

development: 2007-2010

Author:
Roman Stumm

Field Summary
protected  DBVersionMeta dbVersionMeta
           
protected static org.apache.commons.logging.Log log
           
protected  String migrateConfigFileName
           
protected  JdbcDatabase targetDatabase
           
 
Constructor Summary
BaseMigrationTool()
           
 
Method Summary
protected  boolean acceptDirectoryForSQLParser(File aDirectory)
          overwrite in subclasses
protected  void applyEnvironment(JdbcConfig jdbcConfig)
          ensure that the env-variables are used immediately to connect the database!
 void checkObjectsValid(String databaseType)
          callback - invoke DatabaseSchemaChecker for invalid triggers, views, ...
 void checkSchemaComplete(String dev)
          callback - invoke DatabaseSchemaChecker for completeness of schema (columns, tables, foreign keys, indices, ...)
protected  void commit()
           
 void connectTargetDatabase()
           
 void copyFiles(String configKey)
          copy the files from source to target
protected  JdbcDatabase createDatabase(JdbcConfig databaseConfig)
           
 void dbDump(String file)
          callback - invoke dbunit example: "data.XML"
 void dbSetup(String files)
          callback - invoke dbunit
 void disconnectDatabase()
           
 void doGroovyScript(String scriptInvocation)
          callback - invoke a groovy script
 void doMethodOperation(String methodName, String methodParam)
           
 void doSQLScript(String scriptName)
          callback - parse the script and execute each SQL statement
 void doSQLScriptIgnoreErrors(String scriptName)
          callback - parse the script and execute each SQL statement
 void execSQLScript(String scriptName)
          execute the content of a file as a single SQL statement.
protected  Method findMethod(Class clazz, String methodName, int paramCount)
           
 DBVersionMeta getDbVersionMeta()
           
 Map getEnvironment()
          a map for environment properties (JVM System-Properties overwrite these properties) (to be used to conditional execution of statements in SQL scripts)
 String[] getGroovyScriptsDirs()
           
protected  String getJdbcConfigFile()
           
 org.apache.commons.logging.Log getLog()
           
 Config getMigrateConfig()
           
protected  List getOperations(String name)
           
 String getScriptsDir()
           
 JdbcDatabase getTargetDatabase()
           
 void halt(String message)
          callback -
 void invokeBean(String classMethod)
          invoke a n-arg-method on a new instance of a class.
protected  void invokeBeanCallbacks(Object receiver)
           
protected  void invokeClassMethod(boolean isStatic, String classMethod)
           
 void invokeStatic(String classMethod)
          invoke a static n-arg-method on a class.
protected  void iterateSQLScript(ScriptVisitor visitor, String scriptName, boolean failOnError)
          iterate sql script.
 void log(Object obj)
           
protected  void perform(List operations)
           
 void print(Object obj)
           
protected  void replaceProperties(Map env)
           
 void rollback()
           
 void setMigrateConfigFileName(String migrateConfigFileName)
           
 void setScriptsDir(String scriptsDir)
           
 void setTargetDatabase(JdbcDatabase targetDatabase)
           
 void setUp()
           
protected  void setupVersionMeta()
           
protected  Object[] splitMethodArgs(String classMethod)
           
protected  List<String> splitParams(String methodName)
           
protected  int sqlExec(String sql)
           
protected  SQLCursor sqlSelect(String sql)
          utility method to exec a JDBC SELECT statement directly
 void tearDown()
           
 void terminateTransactions()
           
 void version(String dbVersion)
          callback - update the version
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

targetDatabase

protected JdbcDatabase targetDatabase

migrateConfigFileName

protected String migrateConfigFileName

dbVersionMeta

protected final DBVersionMeta dbVersionMeta
Constructor Detail

BaseMigrationTool

public BaseMigrationTool()
Method Detail

setUp

public void setUp()

setupVersionMeta

protected void setupVersionMeta()

tearDown

public void tearDown()
              throws Exception
Throws:
Exception

halt

public void halt(String message)
callback -


version

public void version(String dbVersion)
             throws SQLException
callback - update the version

Throws:
SQLException

execSQLScript

public void execSQLScript(String scriptName)
                   throws SQLException,
                          IOException
execute the content of a file as a single SQL statement. You can use this, when you need not parse the file or when the file cannot be parsed. Example: use this to execute a PL/SQL package, that is stored in a single file (1 file for the spec, 1 file for the body).

Parameters:
scriptName - - may contain properties, but not supported are: -- #if conditions, reconnect, subscripts etc.
Throws:
SQLException
IOException

doSQLScript

public void doSQLScript(String scriptName)
                 throws IOException,
                        SQLException
callback - parse the script and execute each SQL statement

Throws:
IOException
SQLException

doSQLScriptIgnoreErrors

public void doSQLScriptIgnoreErrors(String scriptName)
                             throws Exception
callback - parse the script and execute each SQL statement

Throws:
Exception

checkObjectsValid

public void checkObjectsValid(String databaseType)
                       throws Exception
callback - invoke DatabaseSchemaChecker for invalid triggers, views, ...

Throws:
Exception

checkSchemaComplete

public void checkSchemaComplete(String dev)
                         throws Exception
callback - invoke DatabaseSchemaChecker for completeness of schema (columns, tables, foreign keys, indices, ...)

Throws:
Exception

dbSetup

public void dbSetup(String files)
             throws Exception
callback - invoke dbunit

Parameters:
files - - comma-separated delete and insert DB-Unit script, example: "delete_data.xml,data.XML" example: "data.XML"
Throws:
Exception

copyFiles

public void copyFiles(String configKey)
               throws IOException
copy the files from source to target

Parameters:
configKey - - key in the env, value is list of source_1, target_1, ... URLs
Throws:
IOException

dbDump

public void dbDump(String file)
            throws Exception
callback - invoke dbunit example: "data.XML"

Throws:
Exception

invokeStatic

public void invokeStatic(String classMethod)
                  throws Exception
invoke a static n-arg-method on a class. All parameters of the target method must be of type String!!

Throws:
Exception

invokeBean

public void invokeBean(String classMethod)
                throws Exception
invoke a n-arg-method on a new instance of a class. All parameters of the target method must be of type String!!

Throws:
Exception

invokeClassMethod

protected void invokeClassMethod(boolean isStatic,
                                 String classMethod)
                          throws Exception
Throws:
Exception

doGroovyScript

public void doGroovyScript(String scriptInvocation)
                    throws Exception
callback - invoke a groovy script

Throws:
IOException
Exception

invokeBeanCallbacks

protected void invokeBeanCallbacks(Object receiver)

findMethod

protected Method findMethod(Class clazz,
                            String methodName,
                            int paramCount)

splitMethodArgs

protected Object[] splitMethodArgs(String classMethod)

splitParams

protected List<String> splitParams(String methodName)

iterateSQLScript

protected void iterateSQLScript(ScriptVisitor visitor,
                                String scriptName,
                                boolean failOnError)
                         throws IOException,
                                SQLException
iterate sql script.

Throws:
IOException
SQLException

getDbVersionMeta

public DBVersionMeta getDbVersionMeta()

getEnvironment

public Map getEnvironment()
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
Returns:
a map (do not modify!)

replaceProperties

protected void replaceProperties(Map env)

getTargetDatabase

public JdbcDatabase getTargetDatabase()
Specified by:
getTargetDatabase in interface MigrationTool

getMigrateConfig

public Config getMigrateConfig()

setMigrateConfigFileName

public void setMigrateConfigFileName(String migrateConfigFileName)

getOperations

protected List getOperations(String name)

getScriptsDir

public String getScriptsDir()

getGroovyScriptsDirs

public String[] getGroovyScriptsDirs()

setScriptsDir

public void setScriptsDir(String scriptsDir)

perform

protected void perform(List operations)
                throws Exception
Throws:
Exception

doMethodOperation

public void doMethodOperation(String methodName,
                              String methodParam)
                       throws Exception
Throws:
Exception

connectTargetDatabase

public void connectTargetDatabase()

createDatabase

protected JdbcDatabase createDatabase(JdbcConfig databaseConfig)

applyEnvironment

protected void applyEnvironment(JdbcConfig jdbcConfig)
ensure that the env-variables are used immediately to connect the database!


commit

protected void commit()

getJdbcConfigFile

protected String getJdbcConfigFile()

print

public void print(Object obj)

log

public void log(Object obj)

getLog

public org.apache.commons.logging.Log getLog()

rollback

public void rollback()
              throws Exception
Throws:
Exception

terminateTransactions

public void terminateTransactions()
                           throws Exception
Throws:
Exception

disconnectDatabase

public void disconnectDatabase()
                        throws Exception
Throws:
Exception

acceptDirectoryForSQLParser

protected boolean acceptDirectoryForSQLParser(File aDirectory)
overwrite in subclasses


sqlSelect

protected SQLCursor sqlSelect(String sql)
                       throws SQLException
utility method to exec a JDBC SELECT statement directly

Throws:
SQLException

sqlExec

protected int sqlExec(String sql)
               throws SQLException
Throws:
SQLException

setTargetDatabase

public void setTargetDatabase(JdbcDatabase targetDatabase)


Copyright © 2008-2011. All Rights Reserved.