📄 graphsession.java
字号:
throw new JbpmException("couldn't find all versions of process definition '"+name+"'", e);
}
}
public void deleteProcessDefinition(long processDefinitionId) {
deleteProcessDefinition(loadProcessDefinition(processDefinitionId));
}
public void deleteProcessDefinition(ProcessDefinition processDefinition) {
if (processDefinition==null) throw new NullPointerException("processDefinition is null in JbpmSession.deleteProcessDefinition()");
try {
// delete all the process instances of this definition
List processInstances = findProcessInstances(processDefinition.getId());
if (processInstances!=null) {
Iterator iter = processInstances.iterator();
while (iter.hasNext()) {
deleteProcessInstance((ProcessInstance) iter.next());
}
}
// then delete the process definition
session.delete(processDefinition);
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't delete process definition '" + processDefinition.getId() + "'", e);
}
}
// process instances ////////////////////////////////////////////////////////
/**
* @deprecated use {@link org.jbpm.JbpmContext#save(ProcessInstance)} instead.
* @throws UnsupportedOperationException
*/
public void saveProcessInstance(ProcessInstance processInstance) {
throw new UnsupportedOperationException("use JbpmContext.save(ProcessInstance) instead");
}
/**
* loads a process instance from the database by the identifier.
* This throws an exception in case the process instance doesn't exist.
* @see #getProcessInstance(long)
* @throws a JbpmException in case the process instance doesn't exist.
*/
public ProcessInstance loadProcessInstance(long processInstanceId) {
try {
ProcessInstance processInstance = (ProcessInstance) session.load( ProcessInstance.class, new Long(processInstanceId) );
return processInstance;
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't load process instance '" + processInstanceId + "'", e);
}
}
/**
* gets a process instance from the database by the identifier.
* This method returns null in case the given process instance doesn't exist.
*/
public ProcessInstance getProcessInstance(long processInstanceId) {
try {
ProcessInstance processInstance = (ProcessInstance) session.get( ProcessInstance.class, new Long(processInstanceId) );
return processInstance;
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't get process instance '" + processInstanceId + "'", e);
}
}
/**
* loads a token from the database by the identifier.
* @return the token.
* @throws JbpmException in case the referenced token doesn't exist.
*/
public Token loadToken(long tokenId) {
try {
Token token = (Token) session.load(Token.class, new Long(tokenId));
return token;
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't load token '" + tokenId + "'", e);
}
}
/**
* gets a token from the database by the identifier.
* @return the token or null in case the token doesn't exist.
*/
public Token getToken(long tokenId) {
try {
Token token = (Token) session.get(Token.class, new Long(tokenId));
return token;
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't get token '" + tokenId + "'", e);
}
}
/**
* locks a process instance in the database.
*/
public void lockProcessInstance(long processInstanceId) {
lockProcessInstance(loadProcessInstance(processInstanceId));
}
/**
* locks a process instance in the database.
*/
public void lockProcessInstance(ProcessInstance processInstance) {
try {
session.lock( processInstance, LockMode.UPGRADE );
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't lock process instance '" + processInstance.getId() + "'", e);
}
}
/**
* fetches all processInstances for the given process definition from the database.
* The returned list of process instances is sorted start date, youngest first.
*/
public List findProcessInstances(long processDefinitionId) {
List processInstances = null;
try {
Query query = session.getNamedQuery("GraphSession.findAllProcessInstancesForADefinition");
query.setLong("processDefinitionId", processDefinitionId);
processInstances = query.list();
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't load process instances for process definition '" + processDefinitionId + "'", e);
}
return processInstances;
}
public void deleteProcessInstance(long processInstanceId) {
deleteProcessInstance(loadProcessInstance(processInstanceId));
}
public void deleteProcessInstance(ProcessInstance processInstance) {
deleteProcessInstance(processInstance, true, true, true);
}
public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks, boolean includeTimers, boolean includeMessages) {
if (processInstance==null) throw new NullPointerException("processInstance is null in JbpmSession.deleteProcessInstance()");
try {
// find the tokens
Query query = session.getNamedQuery("GraphSession.findTokensForProcessInstance");
query.setEntity("processInstance", processInstance);
List tokens = query.list();
// deleteSubProcesses
Iterator iter = tokens.iterator();
while (iter.hasNext()) {
Token token = (Token) iter.next();
deleteSubProcesses(token);
// messages
if (includeMessages) {
query = session.getNamedQuery("GraphSession.deleteMessagesForToken");
query.setEntity("token", token);
query.executeUpdate();
}
}
// tasks
if (includeTasks) {
query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance");
query.setEntity("processInstance", processInstance);
List taskInstanceIds = query.list();
query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
query.setParameterList("taskInstanceIds", taskInstanceIds);
}
// timers
if (includeTimers) {
query = session.getNamedQuery("SchedulerSession.deleteTimersForProcessInstance");
query.setEntity("processInstance", processInstance);
query.executeUpdate();
}
// delete the logs for all the process instance's tokens
query = session.getNamedQuery("GraphSession.selectLogsForTokens");
query.setParameterList("tokens", tokens);
List logs = query.list();
iter = logs.iterator();
while (iter.hasNext()) {
session.delete(iter.next());
}
// then delete the process instance
session.delete(processInstance);
} catch (Exception e) {
e.printStackTrace(); log.error(e);
jbpmSession.handleException();
throw new JbpmException("couldn't delete process instance '" + processInstance.getId() + "'", e);
}
}
void deleteSubProcesses(Token token) {
ProcessInstance subProcessInstance = token.getSubProcessInstance();
if (subProcessInstance!=null){
subProcessInstance.setSuperProcessToken(null);
token.setSubProcessInstance(null);
deleteProcessInstance(subProcessInstance);
}
if (token.getChildren()!=null) {
Iterator iter = token.getChildren().values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
deleteSubProcesses(child);
}
}
}
private static final Log log = LogFactory.getLog(GraphSession.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -