Class ScriptTasklet

  • All Implemented Interfaces:
    org.springframework.batch.core.step.tasklet.StoppableTasklet, org.springframework.batch.core.step.tasklet.Tasklet, org.springframework.batch.core.StepExecutionListener, org.springframework.batch.core.StepListener, org.springframework.beans.factory.InitializingBean

    public class ScriptTasklet
    extends org.springframework.batch.core.listener.StepExecutionListenerSupport
    implements org.springframework.batch.core.step.tasklet.StoppableTasklet, org.springframework.beans.factory.InitializingBean
    Runs multiple SQL/PLSQL scripts using SQL*Plus. Requires SQL*Plus to be installed on the system running the tasklet.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String reportDir  
    • Constructor Summary

      Constructors 
      Constructor Description
      ScriptTasklet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()  
      org.springframework.batch.repeat.RepeatStatus execute​(org.springframework.batch.core.StepContribution contribution, org.springframework.batch.core.scope.context.ChunkContext chunkContext)
      Execute system executable (sqlplus ..) and map its exit code to ExitStatus using SystemProcessExitCodeMapper.
      void setEasyConnectionIdentifier​(java.lang.String easyConnectionIdentifier)  
      void setEnvironmentParams​(java.util.Map<java.lang.String,​java.lang.String> envp)  
      void setExecutable​(java.lang.String executable)  
      void setJobExplorer​(org.springframework.batch.core.explore.JobExplorer jobExplorer)  
      void setScriptDir​(java.lang.String dir)  
      void setScriptFile​(java.lang.String scriptFile)
      For convenience and for backward compatibility, if you have only one single script file, you can use this method.
      void setScriptFiles​(java.util.List<java.lang.String> scriptFiles)  
      void setScriptParameters​(java.util.List<java.lang.String> scriptParameters)
      A list of script parameters to be passed to the script.
      void setSendExitCommand​(boolean sendExitCommand)
      By default, when executing an sql file with SQLPLUS in a "one-liner" fashion, i.e.
      void setTerminationCheckInterval​(long checkInterval)
      The time interval how often the tasklet will check for termination status.
      void setTimeout​(long timeout)
      Timeout in milliseconds.
      void stop()
      Will try to interrupt the thread executing the system executable.
      • Methods inherited from class org.springframework.batch.core.listener.StepExecutionListenerSupport

        afterStep, beforeStep
      • Methods inherited from class java.lang.Object

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

      • reportDir

        @Value("${bauta.reportDir}")
        protected java.lang.String reportDir
    • Constructor Detail

      • ScriptTasklet

        public ScriptTasklet()
    • Method Detail

      • execute

        public org.springframework.batch.repeat.RepeatStatus execute​(org.springframework.batch.core.StepContribution contribution,
                                                                     org.springframework.batch.core.scope.context.ChunkContext chunkContext)
                                                              throws java.lang.Exception
        Execute system executable (sqlplus ..) and map its exit code to ExitStatus using SystemProcessExitCodeMapper.
        Specified by:
        execute in interface org.springframework.batch.core.step.tasklet.Tasklet
        Throws:
        java.lang.Exception
      • setExecutable

        public void setExecutable​(java.lang.String executable)
        Parameters:
        executable - executable to be executed in a separate system process
      • setEnvironmentParams

        public void setEnvironmentParams​(java.util.Map<java.lang.String,​java.lang.String> envp)
        Parameters:
        envp - environment parameter values, inherited from parent process when not set (or set to null).
      • setScriptDir

        public void setScriptDir​(java.lang.String dir)
        Parameters:
        dir - working directory of the spawned process, inherited from parent process when not set (or set to null).
      • setSendExitCommand

        public void setSendExitCommand​(boolean sendExitCommand)
        By default, when executing an sql file with SQLPLUS in a "one-liner" fashion, i.e. "sglplus .. @myscript.sql", SQLPLUS will not exit from the prompt unless the script contains a final "exit" executable.
        Parameters:
        sendExitCommand - Set this to true if your script does not contain exit executable. Then an exit executable will be passed to SQLPlus after the script has finished.
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • setJobExplorer

        public void setJobExplorer​(org.springframework.batch.core.explore.JobExplorer jobExplorer)
      • setTimeout

        public void setTimeout​(long timeout)
        Timeout in milliseconds.
        Parameters:
        timeout - upper limit for how long the execution of the external program is allowed to last.
      • setTerminationCheckInterval

        public void setTerminationCheckInterval​(long checkInterval)
        The time interval how often the tasklet will check for termination status.
        Parameters:
        checkInterval - time interval in milliseconds (1 second by default).
      • stop

        public void stop()
        Will try to interrupt the thread executing the system executable.
        Specified by:
        stop in interface org.springframework.batch.core.step.tasklet.StoppableTasklet
        See Also:
        StoppableTasklet.stop()
      • setScriptFile

        public void setScriptFile​(java.lang.String scriptFile)
        For convenience and for backward compatibility, if you have only one single script file, you can use this method. Makes it a bit more convenient in the Spring configuration.
        Parameters:
        scriptFile - The script file to run.
      • setScriptFiles

        public void setScriptFiles​(java.util.List<java.lang.String> scriptFiles)
      • setEasyConnectionIdentifier

        public void setEasyConnectionIdentifier​(java.lang.String easyConnectionIdentifier)
        Parameters:
        easyConnectionIdentifier - username/password@host:port/serviceName
      • setScriptParameters

        public void setScriptParameters​(java.util.List<java.lang.String> scriptParameters)
        A list of script parameters to be passed to the script. Equivalent to "sqlplus @myscript.sql param1 param2".
        Parameters:
        scriptParameters - A list of identifiers for either a job-parameter or a spring property. A job parameter is identified by jobparam.[job-param-key]. A spring property is identified by env.[spring-property-key]