📄 jbpmcontext.java
字号:
Token token = getGraphSession().getToken(tokenId);
if (token!=null) {
addAutoSaveToken(token);
}
return token;
}
/**
* loads a process instance from the db.
* Consider using {@link #loadProcessInstanceForUpdate(long)} if you plan to
* perform an update operation on the process instance.
* @throws JbpmException in case no such process instance exists.
* @see #getProcessInstance(long)
* @see #loadProcessInstanceForUpdate(long)
* @see #getProcessInstanceForUpdate(long)
*/
public ProcessInstance loadProcessInstance(long processInstanceId) {
return getGraphSession().loadProcessInstance(processInstanceId);
}
/**
* gets a process instance from the db.
* Consider using {@link #loadProcessInstanceForUpdate(long)} if you plan to
* perform an update operation on the process instance.
* @return the token or null in case no such token exists.
* @see #loadProcessInstance(long)
* @see #loadProcessInstanceForUpdate(long)
* @see #getProcessInstanceForUpdate(long)
*/
public ProcessInstance getProcessInstance(long processInstanceId) {
return getGraphSession().getProcessInstance(processInstanceId);
}
/**
* loads a process instances from the db and registers it for auto-save.
* The loaded process instance will be {@link #save(ProcessInstance)}d automatically
* at the {@link #close()}. This is a convenience method in case you plan to do update
* operations on this process instance.
* @throws JbpmException in case no such process instance exists.
* @see #loadProcessInstance(long)
* @see #getProcessInstance(long)
* @see #getProcessInstanceForUpdate(long)
*/
public ProcessInstance loadProcessInstanceForUpdate(long processInstanceId) {
ProcessInstance processInstance = getGraphSession().loadProcessInstance(processInstanceId);
addAutoSaveProcessInstance(processInstance);
return processInstance;
}
/**
* gets a process instances from the db and registers it for auto-save.
* The loaded process instance will be {@link #save(ProcessInstance)}d automatically
* at the {@link #close()}. This is a convenience method in case you plan to do update
* operations on this process instance.
* @return the token or null in case no such token exists.
* @see #loadProcessInstance(long)
* @see #getProcessInstance(long)
* @see #loadProcessInstanceForUpdate(long)
*/
public ProcessInstance getProcessInstanceForUpdate(long processInstanceId) {
ProcessInstance processInstance = getGraphSession().getProcessInstance(processInstanceId);
if (processInstance!=null) {
addAutoSaveProcessInstance(processInstance);
}
return processInstance;
}
/**
* creates a new process instance for the latest version of the process definition
* with the given name.
*/
public ProcessInstance newProcessInstance(String processDefinitionName) {
ProcessDefinition processDefinition = getGraphSession().findLatestProcessDefinition(processDefinitionName);
return new ProcessInstance(processDefinition);
}
/**
* creates a new process instance for the latest version of the process definition
* with the given name and registers it for auto-save.
*/
public ProcessInstance newProcessInstanceForUpdate(String processDefinitionName) {
ProcessDefinition processDefinition = getGraphSession().findLatestProcessDefinition(processDefinitionName);
ProcessInstance processInstance = new ProcessInstance(processDefinition);
addAutoSaveProcessInstance(processInstance);
return processInstance;
}
/**
* saves the process instance.
*/
public void save(ProcessInstance processInstance) {
if (services!=null) {
services.save(processInstance, this);
}
}
/**
* saves the complete process instance for this token.
*/
public void save(Token token) {
save(token.getProcessInstance());
}
/**
* saves the complete process instance for this task instance.
*/
public void save(TaskInstance taskInstance) {
save(taskInstance.getTaskMgmtInstance().getProcessInstance());
}
/**
* mark this transaction for rollback only in the persistence service.
* The {@link #close()} operation will then perform a rollback.
*/
public void setRollbackOnly() {
if (services!=null) {
services.getPersistenceService().setRollbackOnly();
}
}
// services //////////////////////////////////////////////////////////
/**
* gives access to the services and service factories.
*/
public Services getServices() {
return services;
}
public ServiceFactory getServiceFactory(String name) {
return services.getServiceFactory(name);
}
/**
* gives access to the object factory containing the configuration
* for creating the service factories.
*/
public ObjectFactory getObjectFactory() {
return objectFactory;
}
// persistence methods //////////////////////////////////////////////////////
/**
* gets the hibernate session factory from the default configured persistence
* service.
* @throws ClassCastException if another persistence service is configured then the default.
*/
public SessionFactory getSessionFactory() {
DbPersistenceService persistenceService = (DbPersistenceService) getPersistenceService();
if (persistenceService==null) return null;
return persistenceService.getSessionFactory();
}
/**
* sets the hibernate session factory into the default configured persistence
* service, overwriting the configured session factory (if there is one configured).
* @throws ClassCastException if another persistence service is configured then the default.
*/
public void setSessionFactory(SessionFactory sessionFactory) {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return;
persistenceService.setSessionFactory(sessionFactory);
}
/**
* gets the hibernate session from the default configured persistence
* service.
* @throws ClassCastException if another persistence service is configured then the default.
*/
public Session getSession() {
DbPersistenceService persistenceService = (DbPersistenceService) getPersistenceService();
if (persistenceService==null) return null;
return persistenceService.getSession();
}
/**
* sets the hibernate session into the default configured persistence
* service, preventing the creation of a session from the configured
* session factory (if there is one configured).
* @throws ClassCastException if another persistence service is configured then the default.
*/
public void setSession(Session session) {
DbPersistenceService persistenceService = (DbPersistenceService) getPersistenceService();
if (persistenceService==null) return;
persistenceService.setSession(session);
}
/**
* gets the jdbc connection from the default configured persistence service.
* @throws ClassCastException if another persistence service is configured then the default.
*/
public Connection getConnection() {
DbPersistenceService persistenceService = (DbPersistenceService) getPersistenceService();
if (persistenceService==null) return null;
return persistenceService.getConnection();
}
/**
* allows users to provide a jdbc connection to be used when the hibernate
* session is created.
* @throws ClassCastException if another persistence service is configured then the default.
*/
public void setConnection(Connection connection) {
DbPersistenceService persistenceService = (DbPersistenceService) getPersistenceService();
if (persistenceService==null) return;
persistenceService.setConnection(connection);
}
// jbpm database access sessions
/**
* more variables related database access.
*/
public ContextSession getContextSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return persistenceService.getContextSession();
}
/**
* more logging related database access.
*/
public LoggingSession getLoggingSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return (persistenceService!=null ? persistenceService.getLoggingSession() : null);
}
/**
* more messaging related database access.
*/
public MessagingSession getMessagingSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return (persistenceService!=null ? persistenceService.getMessagingSession() : null);
}
/**
* more scheduling related database access.
*/
public SchedulerSession getSchedulerSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return (persistenceService!=null ? persistenceService.getSchedulerSession() : null);
}
/**
* more graph (process) related database access.
*/
public GraphSession getGraphSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return (persistenceService!=null ? persistenceService.getGraphSession() : null);
}
/**
* more task related database access.
*/
public TaskMgmtSession getTaskMgmtSession() {
PersistenceService persistenceService = getPersistenceService();
if (persistenceService==null) return null;
return (persistenceService!=null ? persistenceService.getTaskMgmtSession() : null);
}
// authentication methods ///////////////////////////////////////////////////
/**
* retrieves the current authenticated actor from the authentication service.
*/
public String getActorId() {
return services.getAuthenticationService().getActorId();
}
/**
* sets the currently authenticated actorId.
* @throws ClassCastException if another authentication service is configured then the default.
*/
public void setActorId(String actorId) {
DefaultAuthenticationService authenticationService = (DefaultAuthenticationService) services.getAuthenticationService();
DefaultAuthenticationService defaultAuthenticationService = (DefaultAuthenticationService) authenticationService;
defaultAuthenticationService.setActorId(actorId);
}
// private methods //////////////////////////////////////////////////////////
void addAutoSaveProcessInstance(ProcessInstance processInstance) {
if (autoSaveProcessInstances==null) autoSaveProcessInstances = new ArrayList();
autoSaveProcessInstances.add(processInstance);
}
void addAutoSaveToken(Token token) {
addAutoSaveProcessInstance(token.getProcessInstance());
}
void addAutoSaveTaskInstance(TaskInstance taskInstance) {
addAutoSaveProcessInstance(taskInstance.getTaskMgmtInstance().getProcessInstance());
}
void autoSave() {
if (autoSaveProcessInstances!=null) {
Iterator iter = autoSaveProcessInstances.iterator();
while (iter.hasNext()) {
ProcessInstance processInstance = (ProcessInstance) iter.next();
save(processInstance);
iter.remove();
}
}
}
PersistenceService getPersistenceService() {
if (services==null) return null;
return services.getPersistenceService();
}
public JbpmConfiguration getJbpmConfiguration() {
return jbpmConfiguration;
}
private static Log log = LogFactory.getLog(JbpmContext.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -