com.massimo.tools.scriptrunner.context
Class PostgresExecutionContext

java.lang.Object
  extended by com.massimo.tools.scriptrunner.context.AbstractExecutionContext
      extended by com.massimo.tools.scriptrunner.context.PostgresExecutionContext
All Implemented Interfaces:
ExecutionContext

public class PostgresExecutionContext
extends AbstractExecutionContext

This is backed by Postgres database tables and schema. These must be installed before this can be used.
A audit datasource must be configured, identified by the dataSourceName srAudit.


Field Summary
protected  Connection auditConnection
           
protected static String SQL_IS_FINISHED
           
protected static String SQL_LOG_INSERT
           
protected static String SQL_NEXT_RUN_ID
           
protected static String SQL_TASK_FINISHED
           
protected static String SQL_TASK_PROGRESS
           
protected static String SQL_TASK_START
           
 
Fields inherited from class com.massimo.tools.scriptrunner.context.AbstractExecutionContext
lastException, runId
 
Constructor Summary
PostgresExecutionContext(Element task)
           
 
Method Summary
protected  void finalize()
          
Attempt to close the database conenction.
 void finished(String taskName, int lastRowCommitted)
          Audit trail: record successful finish of Task execution
protected  String generateRunIdentifier(Map<String,String> properties)
          
The run identifier is generated by a database sequence.
protected  org.apache.log4j.Logger getLogger()
          
protected  void handleSQLException(String stmtText, SQLException se, String errorText)
           
 boolean isFinished(String taskName)
          Audit trail: check whether Task has already been executed in this run
 void log(String taskName, int log_code, String message, int lastRowProcessed, String primaryKey)
          Log informational messages
 void progress(String taskName, int lastStepProcessed, String key)
          Audit trail: Task has finished executing its lastStepProcessed step
protected  void refreshConnection()
           
 int start(String taskName)
          Audit trail: start Task execution
 
Methods inherited from class com.massimo.tools.scriptrunner.context.AbstractExecutionContext
getLastException, getRunIdentifier, log, setLastException, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

auditConnection

protected Connection auditConnection

SQL_IS_FINISHED

protected static final String SQL_IS_FINISHED
See Also:
Constant Field Values

SQL_LOG_INSERT

protected static final String SQL_LOG_INSERT
See Also:
Constant Field Values

SQL_NEXT_RUN_ID

protected static final String SQL_NEXT_RUN_ID
See Also:
Constant Field Values

SQL_TASK_FINISHED

protected static final String SQL_TASK_FINISHED
See Also:
Constant Field Values

SQL_TASK_PROGRESS

protected static final String SQL_TASK_PROGRESS
See Also:
Constant Field Values

SQL_TASK_START

protected static final String SQL_TASK_START
See Also:
Constant Field Values
Constructor Detail

PostgresExecutionContext

public PostgresExecutionContext(Element task)
                         throws SRException
Parameters:
task -
Throws:
SRException
Method Detail

finalize

protected void finalize()
                 throws Throwable

Attempt to close the database conenction.

Overrides:
finalize in class Object
Throws:
Throwable

finished

public void finished(String taskName,
                     int lastRowCommitted)
              throws SRException
Audit trail: record successful finish of Task execution

Throws:
SRException

generateRunIdentifier

protected String generateRunIdentifier(Map<String,String> properties)
                                throws SRException

The run identifier is generated by a database sequence.

Specified by:
generateRunIdentifier in class AbstractExecutionContext
Returns:
a newly generate run identifier
Throws:
SRException

getLogger

protected org.apache.log4j.Logger getLogger()

Specified by:
getLogger in class AbstractExecutionContext
Returns:
The concrete class's Logger

handleSQLException

protected void handleSQLException(String stmtText,
                                  SQLException se,
                                  String errorText)
                           throws SRException
Parameters:
stmtText -
se -
errorText -
Throws:
SRException

isFinished

public boolean isFinished(String taskName)
                   throws SRException
Audit trail: check whether Task has already been executed in this run

Returns:
boolean
Throws:
SRException

log

public void log(String taskName,
                int log_code,
                String message,
                int lastRowProcessed,
                String primaryKey)
         throws SRException
Log informational messages

log_code - The Task constants or an error code
primaryKey - A identifier for the last step, e.g. a database row's primary key value. May be empty.
Throws:
SRException

progress

public void progress(String taskName,
                     int lastStepProcessed,
                     String key)
              throws SRException
Audit trail: Task has finished executing its lastStepProcessed step

lastStepProcessed - On re-start, this value will returned by ExecutionContext.start(String)
key - A identifier for the last step, e.g. a database row's primary key value. May be empty.
Throws:
SRException

refreshConnection

protected void refreshConnection()
                          throws SRException
Throws:
SRException

start

public int start(String taskName)
          throws SRException
Audit trail: start Task execution

Returns:
int The index of the last executed step or 0.
Throws:
SRException