|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.massimo.tools.scriptrunner.AbstractTask com.massimo.tools.scriptrunner.work.SQLTask
public class SQLTask
Task to handle SQL or procedural SQL from the definition text.
Introduces attributes Constants.ATTRIBUTE_BINDS
and Constants.ATTRIBUTE_STATMENT_SPLIT.
The task element body is the SQL to execute.
The SQL is split into statements according to the statement-split attribute or pre-defined patterns (for supported databases).
The statements are executed and progress logged.
After an error and exit, a re-start will pick up at the statement that errored.
Field Summary | |
---|---|
protected static String |
BIND_END_DELIMITERS
Punctuation that can make the end of a bind variable |
protected String[] |
bindNames
|
protected Connection |
connection
|
protected DatabaseType |
dbType
|
protected String |
run_id
|
protected static String |
SQL_CHECK_PREFIX_ORACLE
|
protected static String |
SQL_CHECK_PREFIX_POSTGRES
|
protected static String |
SQL_CHECK_SUFFIX_ORACLE
|
protected static String |
SQL_CHECK_SUFFIX_POSTGRES
|
protected static Pattern |
SQL_NON_COMMENT_PATTERN
|
protected static Pattern |
SQL_STMT_PATTERN_ORACLE
Oracle uses / |
protected static Pattern |
SQL_STMT_PATTERN_POSTGRES
Postgres uses \g |
Fields inherited from class com.massimo.tools.scriptrunner.AbstractTask |
---|
definition, name, parent, properties, type |
Fields inherited from interface com.massimo.tools.scriptrunner.Task |
---|
DATA_ERROR, ERROR, FINISHED, INTERRUPTED, PROMPT, RUNNING, START, SUCCESS |
Constructor Summary | |
---|---|
SQLTask(Task parent,
String type,
Element definition,
Map<String,String> properties)
|
Method Summary | |
---|---|
protected int |
doProcess(ExecutionContext context)
Implementing classes only need to do their own work and log progress when appropriate. |
protected int |
doValidate(ValidationContext context)
Check whether this task should be able to run. |
protected int |
executeSQL(ExecutionContext context,
String sqlText)
|
protected void |
finalize()
Attempts to close the database connection. |
protected String[] |
getBindNames()
Read the binds attribute and return variable names in a String array. |
protected org.apache.log4j.Logger |
getLogger()
|
protected Pattern |
getSQLSplitPattern()
Checks attribute statement-split, before looking at the DBMS connection. |
protected String |
getSQLText()
Sub-classes may override this if the SQL is not simply the XML text. |
protected String |
getSQLWarning(SQLWarning sqlWarning)
Walk down the chain of warnings, adding each to the return value. |
protected String[] |
parseTextIntoStatements(String parameterizedText)
Break the text up into individaul statments. |
protected int |
postCheck(ExecutionContext context)
Execute the configured pre-execution check function The default is run_progress.postcheck(:run_id, :module). |
protected int |
preCheck()
A precheck can be done to see if the task should be executed. |
protected void |
setBinds(PreparedStatement stmt,
List<String> binds)
Bind the variables to the statement. |
protected String |
substitiuteBinds(String sql,
List<String> binds)
Parses the statement looking for known bind variables. |
protected int |
validateBinds(ValidationContext context)
Checks that bind variables in bindNames have values. |
protected int |
validateSQL(String sqlText,
ValidationContext context)
|
Methods inherited from class com.massimo.tools.scriptrunner.AbstractTask |
---|
getBooleanProperty, getCurrentWorkingDirectory, getDefinition, getIntProperty, getName, getParent, getProperties, getStartProcessingRow, getText, getType, interrupt, isIgnoreableError, isIgnoreableError, isInterrupted, isLogProgress, postProcess, preProcess, process, resultCodeToString, substituteParameters, toString, validate, validateConnections, validateParameters |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final String BIND_END_DELIMITERS
protected String[] bindNames
protected Connection connection
protected DatabaseType dbType
protected String run_id
protected static final String SQL_CHECK_PREFIX_ORACLE
protected static final String SQL_CHECK_PREFIX_POSTGRES
protected static final String SQL_CHECK_SUFFIX_ORACLE
protected static final String SQL_CHECK_SUFFIX_POSTGRES
protected static final Pattern SQL_NON_COMMENT_PATTERN
protected static final Pattern SQL_STMT_PATTERN_ORACLE
protected static final Pattern SQL_STMT_PATTERN_POSTGRES
Constructor Detail |
---|
public SQLTask(Task parent, String type, Element definition, Map<String,String> properties) throws Exception
parent
- type
- definition
- properties
-
Exception
Method Detail |
---|
protected int doProcess(ExecutionContext context) throws Exception
doProcess
in class AbstractTask
Exception
AbstractTask.process(ExecutionContext)
protected int doValidate(ValidationContext context)
doValidate
in class AbstractTask
protected int executeSQL(ExecutionContext context, String sqlText) throws SQLException, SRException
context
- sqlText
-
SQLException
SRException
protected void finalize() throws Throwable
finalize
in class Object
Throwable
protected String[] getBindNames()
protected org.apache.log4j.Logger getLogger()
getLogger
in class AbstractTask
protected Pattern getSQLSplitPattern()
protected String getSQLText()
protected String getSQLWarning(SQLWarning sqlWarning)
sqlWarning
-
protected String[] parseTextIntoStatements(String parameterizedText)
parameterizedText
-
protected int postCheck(ExecutionContext context) throws SQLException, SRException
context
-
SQLException
SRException
protected int preCheck() throws SQLException
SQLException
- if the query fails.protected void setBinds(PreparedStatement stmt, List<String> binds) throws SQLException
stmt
- PreparedStatementbinds
- List
SQLException
protected String substitiuteBinds(String sql, List<String> binds)
sql
- StringBufferbinds
- List to populate with the names of bind variables, in the order they appear
protected int validateBinds(ValidationContext context)
context
-
protected int validateSQL(String sqlText, ValidationContext context)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |