/**
* processing
*/
public boolean spooler_process() {
SOSConnection localConnection = null;
Order order = null;
String command = "";
orderPayload = null;
Variable_set realOrderParams = null;
boolean rc = true;
boolean resultsetAsWarning = false;
boolean resultsetAsParameters = false;
boolean resultsetNameValue = false;
boolean execReturnsResultSet = false;
autoCommit = false;
try {
this.setLogger(new SOSSchedulerLogger(spooler_log));
super.prepareParams();
if(orderPayload!=null && orderPayload.var("scheduler_order_is_user_job")!=null && orderPayload.var("scheduler_order_is_user_job").equals("1")){
userJob = true;
}
if(orderPayload!=null && orderPayload.var("resultset_as_warning")!=null && (orderPayload.var("resultset_as_warning").equals("1") || orderPayload.var("resultset_as_warning").equalsIgnoreCase("true"))){
resultsetAsWarning = true;
}
if(orderPayload!=null && orderPayload.var("exec_returns_resultset")!=null && (orderPayload.var("exec_returns_resultset").equals("1") || orderPayload.var("exec_returns_resultset").equalsIgnoreCase("true"))){
execReturnsResultSet = true;
}
if(orderPayload!=null && orderPayload.var("resultset_as_parameters")!=null && (orderPayload.var("resultset_as_parameters").equals("1") || orderPayload.var("resultset_as_parameters").equalsIgnoreCase("true") || orderPayload.var("resultset_as_parameters").equalsIgnoreCase("name_value"))){
resultsetAsParameters = true;
if (orderPayload.var("resultset_as_parameters").equalsIgnoreCase("name_value")){
resultsetNameValue = true;
}
}
if(orderPayload!=null && orderPayload.var("auto_commit")!=null && (orderPayload.var("auto_commit").equals("1") || orderPayload.var("auto_commit").equalsIgnoreCase("true"))){
autoCommit = true;
}
try{
if(userJob){
checkOldTempUsers();
localConnection=this.getUserConnection(orderPayload.var("scheduler_order_user_name"), orderPayload.var("scheduler_order_schema"));
}else{
localConnection = JobSchedulerManagedObject.getOrderConnection(this.getConnection(), this);
localConnection.connect();
}
} catch (Exception e) {
throw new Exception("error occurred establishing database connection: " + e.getMessage());
}
localConnection.setExecReturnsResultSet(execReturnsResultSet);
try {
if (orderJob) command = JobSchedulerManagedObject.getOrderCommand(this.getConnection(), this);
if (command == null || command.length() == 0) {
command = JobSchedulerManagedObject.getJobCommand(this.getConnection(), this);
}
if (command == null || command.length() == 0) throw new Exception("command is empty");
} catch(Exception e){
throw (new Exception("no database command found: " + e));
}
// replace job-specific placeholders
command = command.replaceAll("\\$\\{scheduler_order_job_name\\}" , this.getJobName());
command = command.replaceAll("\\$\\{scheduler_order_job_id\\}" , Integer.toString(this.getJobId()));
command = command.replaceAll("\\$\\{scheduler_id\\}" , spooler.id());
// replace parameters
if (orderPayload != null)
command = JobSchedulerManagedObject.replaceVariablesInCommand(command, orderPayload, getLogger());
// replace order-specific placeholders
if(orderJob) {
order = spooler_task.order();
realOrderParams = order.params();
command = command.replaceAll("\\$\\{scheduler_order_id\\}" , order.id());
command = command.replaceAll("\\$\\{scheduler_order_managed_id\\}" , "0");
this.getLogger().info("executing database statement(s) for managed order [" + order.id() + "]: " + command);
} else {
this.getLogger().info("executing database statement(s): " + command);
}
executeStatements(localConnection, command);
this.getLogger().info("database statement(s) executed.");
if ((resultsetAsWarning || resultsetAsParameters) && localConnection.getResultSet() != null){
String warning = "";
HashMap result = null;
while( !(result = localConnection.get()).isEmpty()) {
String orderParamKey = "";
int columnCount =0;
warning = "execution terminated with warning:";
Iterator resultIterator = result.keySet().iterator();
boolean resultParametersSet = false;
while(resultIterator.hasNext()) {
columnCount++;
String key = (String) resultIterator.next();
if (key == null || key.length() == 0) continue;
String value = result.get(key).toString();
warning += " " + key + "=" + value;
if (resultsetAsParameters && order!=null && !resultParametersSet){
if (resultsetNameValue){ // name/value pairs from two columns
if (columnCount==1){
orderParamKey = value;
}
if (columnCount==2){
if (realOrderParams.value(orderParamKey)==null || realOrderParams.value(orderParamKey).length()==0){
realOrderParams.set_var(orderParamKey, value);
}
}
}else if (realOrderParams.value(key)==null || realOrderParams.value(key).length()==0){
// column name = name, value=value
realOrderParams.set_var(key, value);
resultParametersSet = true;
}
}
}
}
if (warning!=null && warning.length()>0 && resultsetAsWarning){
rc = false;
this.getLogger().warn(warning);
}
}
if (getLogger().hasWarnings() || getLogger().hasErrors()) spooler_task.end();
return rc && orderJob;
}
catch (Exception e) {
spooler_log.warn("error occurred processing managed order [" + ((order != null) ? "Job Chain: " + order.job_chain().name() + ", ID:"+ order.id() : "(none)") + "] : " + e);
if (userJob) writeError(e, order);
spooler_task.end();
return false;
}
finally {
//try { if (localConnection != null) localConnection.rollback(); } catch (Exception ex) {} // ignore this errror
try { if (localConnection != null && !userJob) localConnection.disconnect(); } catch (Exception ex) {} // ignore this errror
if(userJob) {
closeUserConnection(localConnection);
updateRunTime(order, getLogger(), getConnection());
}
try{getConnection().commit();} catch (Exception e){}