public void terminate(final Long iid) {
try {
_db.exec(new BpelDatabase.Callable<Object>() {
public Object run(BpelDAOConnection conn) throws Exception {
ProcessInstanceDAO instance = conn.getInstance(iid);
if (instance == null)
throw new ManagementException("InstanceNotFound:" + iid);
// send event
ProcessInstanceStateChangeEvent evt = new ProcessInstanceStateChangeEvent();
evt.setOldState(instance.getState());
instance.setState(ProcessState.STATE_TERMINATED);
evt.setNewState(ProcessState.STATE_TERMINATED);
evt.setProcessInstanceId(iid);
ProcessDAO process = instance.getProcess();
QName processName = process.getType();
evt.setProcessName(processName);
QName processId = process.getProcessId();
evt.setProcessId(processId);
_process.saveEvent(evt, instance);