Class ScriptRunner


  • public class ScriptRunner
    extends java.lang.Object
    Tool to run database scripts.
    Author:
    Apach project iBATIS, Benoit Duffez, Lijun Liao (xipki)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern delimP
      regex to detect delimiter.
    • Constructor Summary

      Constructors 
      Constructor Description
      ScriptRunner​(java.sql.Connection connection, boolean stopOnError)
      Default constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void runScript​(java.io.Reader reader)
      Runs an SQL script (read in using the Reader parameter)
      void runScript​(java.lang.String filepath)
      Runs an SQL script (read in using the Reader parameter)
      static void runScript​(java.lang.String dbConfFile, java.lang.String scriptFile)  
      static void runScript​(java.sql.Connection conn, java.lang.String scriptFile)  
      static void runScript​(DataSourceWrapper dataSource, java.lang.String scriptFile)  
      void setDelimiter​(java.lang.String delimiter, boolean fullLineDelimiter)  
      void setErrorLogWriter​(java.io.PrintWriter errorLogWriter)
      Setter for errorLogWriter property
      void setLogWriter​(java.io.PrintWriter logWriter)
      Setter for logWriter property
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • delimP

        public static final java.util.regex.Pattern delimP
        regex to detect delimiter. ignores spaces, allows delimiter in comment, allows an equals-sign
    • Constructor Detail

      • ScriptRunner

        public ScriptRunner​(java.sql.Connection connection,
                            boolean stopOnError)
        Default constructor
        Parameters:
        connection - the SQL connection
        stopOnError - whether the process stops when error occurs.
    • Method Detail

      • runScript

        public static void runScript​(java.lang.String dbConfFile,
                                     java.lang.String scriptFile)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • runScript

        public static void runScript​(DataSourceWrapper dataSource,
                                     java.lang.String scriptFile)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • runScript

        public static void runScript​(java.sql.Connection conn,
                                     java.lang.String scriptFile)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setDelimiter

        public void setDelimiter​(java.lang.String delimiter,
                                 boolean fullLineDelimiter)
      • setLogWriter

        public void setLogWriter​(java.io.PrintWriter logWriter)
        Setter for logWriter property
        Parameters:
        logWriter - - the new value of the logWriter property
      • setErrorLogWriter

        public void setErrorLogWriter​(java.io.PrintWriter errorLogWriter)
        Setter for errorLogWriter property
        Parameters:
        errorLogWriter - - the new value of the errorLogWriter property
      • runScript

        public void runScript​(java.lang.String filepath)
                       throws java.io.IOException,
                              java.sql.SQLException
        Runs an SQL script (read in using the Reader parameter)
        Parameters:
        filepath - - the filepath of the script to run. May be relative to the userDirectory.
        Throws:
        java.sql.SQLException - if any SQL errors occur
        java.io.IOException - if there is an error reading from the Reader
      • runScript

        public void runScript​(java.io.Reader reader)
                       throws java.io.IOException,
                              java.sql.SQLException
        Runs an SQL script (read in using the Reader parameter)
        Parameters:
        reader - - the source of the script
        Throws:
        java.sql.SQLException - if any SQL errors occur
        java.io.IOException - if there is an error reading from the Reader