public void afterComplete(Activity activity, ProcessInstance instance)
throws Exception {
if(!(activity instanceof SwitchActivity)) return;
SwitchActivity switchActivity = (SwitchActivity)activity;
int selectionPath = switchActivity.getCurrentStep(instance);
Long procDefId = new Long(switchActivity.getProcessDefinition().getBelongingDefinitionId());
Long pathNo = new Long(selectionPath);
boolean isNew = false;
long occurrence=0;
long total=0;
Long[] occurrenceAndTotal = getOccurrenceAndTotal(switchActivity, selectionPath);
if(occurrenceAndTotal==null){
isNew = true;
}else{
occurrence=occurrenceAndTotal[0].longValue();
total=occurrenceAndTotal[1].longValue();
}
occurrence++;
String sql = (isNew?
"insert into BPM_AUDIT_PRBLTY(ProcDefId, TracingTag, PathNo, Occurrence) values (?ProcDefId, ?TracingTag, ?PathNo, ?Occurrence)":
"update BPM_AUDIT_PRBLTY set Occurrence=?Occurrence where (ProcDefId = ?ProcDefId and TracingTag = ?TracingTag and PathNo = ?PathNo)"
);
BPM_AUDIT_PRBLTY newProbability = (BPM_AUDIT_PRBLTY)GenericDAO.createDAOImpl(
DefaultConnectionFactory.create(),
sql,
BPM_AUDIT_PRBLTY.class
);
newProbability.setProcDefId(procDefId);
newProbability.setTracingTag(switchActivity.getTracingTag());
newProbability.setPathNo(pathNo);
newProbability.setOccurrence(new Long(occurrence));
newProbability.insert();
}