📄 persistenceservicehibernateimpl.java.svn-base
字号:
// public List<IToken> findTokens(IProcessInstance processInstance) {
// Session session = (Session) RuntimeContext.getInstance().getCurrentDBSession();
// Criteria criteria = session.createCriteria(Token.class);
//
// criteria.add(Expression.eq("processInstance.id", processInstance.getId()));
//
// return (List<IToken>) criteria.list();
// }
public List<IProcessInstance> findProcessInstanceByProcessId(final String processId) {
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
Criteria criteria = arg0.createCriteria(ProcessInstance.class);
criteria.add(Expression.eq("processId", processId));
List<IProcessInstance> _result = criteria.list();
return _result;
}
});
return result;
}
public IProcessInstance findProcessInstanceById(String id) {
return (IProcessInstance) this.getHibernateTemplate().get(ProcessInstance.class, id);
}
public IJoinPoint findJoinPointById(String id) {
return (IJoinPoint) this.getHibernateTemplate().get(JoinPoint.class, id);
}
public void saveOrUpdateWorkflowDefinition(WorkflowDefinition workflowDef) {
if (workflowDef.getId() == null || workflowDef.getId().equals("")) {
Integer latestVersion = findTheLatestVersionOfWorkflowDefinition(workflowDef.getProcessId());
if (latestVersion != null) {
workflowDef.setVersion(new Integer(latestVersion.intValue() + 1));
} else {
workflowDef.setVersion(new Integer(1));
}
}
this.getHibernateTemplate().saveOrUpdate(workflowDef);
}
public Integer findTheLatestVersionOfWorkflowDefinition(final String processId) {
//取得当前最大的version值
Integer result = (Integer) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
Query q = arg0.createQuery("select max(m.version) from WorkflowDefinition m");
Object obj = q.uniqueResult();
if (obj != null) {
Integer latestVersion = (Integer) obj;
return latestVersion;
} else {
return null;
}
}
});
return result;
}
public WorkflowDefinition findWorkflowDefinitionById(String id) {
return (WorkflowDefinition) this.getHibernateTemplate().get(WorkflowDefinition.class, id);
}
public WorkflowDefinition findWorkflowDefinitionByProcessIdAndVersion(final String processId, final int version) {
WorkflowDefinition workflowDef = (WorkflowDefinition) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
Criteria c = arg0.createCriteria(WorkflowDefinition.class);
c.add(Expression.eq("processId", processId));
c.add(Expression.eq("version", version));
return (WorkflowDefinition) c.uniqueResult();
}
});
return workflowDef;
}
public WorkflowDefinition findLatestVersionOfWorkflowDefinitionByProcessId(String processId) {
Integer latestVersion = this.findTheLatestVersionOfWorkflowDefinition(processId);
return this.findWorkflowDefinitionByProcessIdAndVersion(processId, latestVersion);
}
public List<WorkflowDefinition> findWorkflowDefinitionByProcessId(final String processId) {
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
Criteria c = arg0.createCriteria(WorkflowDefinition.class);
c.add(Expression.eq("processId", processId));
return c.list();
}
});
return result;
}
public List<WorkflowDefinition> findAllLatestVersionOfWorkflowDefinition() {
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = "select distinct model.processId from WorkflowDefinition model ";
Query query = arg0.createQuery(hql);
List processIdList = query.list();
List _result = new Vector<WorkflowDefinition>();
for (int i = 0; i < processIdList.size(); i++) {
WorkflowDefinition wfDef = findLatestVersionOfWorkflowDefinitionByProcessId((String) processIdList.get(i));
_result.add(wfDef);
}
return _result;
}
});
return result;
}
public List<IWorkItem> findTodoWorkItems(final String actorId) {
if (actorId == null || actorId.equals("")) {
return null;
}
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = "From org.fireflow.engine.impl.WorkItem model where model.actorId=? and (model.state=0 or model.state=1)";
Query query = arg0.createQuery(hql);
query.setString(0, actorId);
return query.list();
}
});
return result;
}
public List<IWorkItem> findTodoWorkItems(final String actorId, final String processInstanceId) {
if (processInstanceId == null || processInstanceId.trim().equals("") || actorId == null || actorId.trim().equals("")) {
return null;
}
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = "From org.fireflow.engine.impl.WorkItem model where model.actorId=? and model.taskInstance.processInstance.id=? and (model.state=0 or model.state=1)";
Query query = arg0.createQuery(hql);
query.setString(0, actorId);
query.setString(1, processInstanceId);
return query.list();
}
});
return result;
}
public List<IWorkItem> findTodoWorkItems(final String actorId, final String processId, final String taskId) {
if (actorId == null || actorId.equals("")) {
return null;
}
List result = (List) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = "From org.fireflow.engine.impl.WorkItem model where model.actorId=:actorId and (model.state=0 or model.state=1)";
if (processId != null && !processId.trim().equals("")) {
hql = hql + " and model.taskInstance.processInstance.processId=:processId";
}
if (taskId != null && !taskId.trim().equals("")) {
hql = hql + " and model.taskInstance.taskId=:taskId";
}
Query query = arg0.createQuery(hql);
query.setString("actorId", actorId);
if (processId != null && !processId.trim().equals("")) {
query.setString("processId", processId);
}
if (taskId != null && !taskId.trim().equals("")) {
query.setString("taskId", taskId);
}
return query.list();
}
});
return result;
}
public void deleteWorkItemsInInitializedState(final String taskInstanceId) {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = "delete from org.fireflow.engine.impl.WorkItem as model where model.taskInstance.id=? and model.state=0";
Query query = arg0.createQuery(hql);
query.setString(0, taskInstanceId);
return query.executeUpdate();
}
});
}
/*
public List<IWorkItem> findHaveDoneWorkItems(final String processInstanceId,final String activityId){
if (processInstanceId==null || processInstanceId.trim().equals("")||
activityId==null || activityId.trim().equals("")){
return null;
}
Object result = this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
String hql = " from org.fireflow.engine.impl.WorkItem as model where model.taskInstance.processInstance.id=? and model.activityId=? and model.state=2";
Query query = arg0.createQuery(hql);
query.setString(0, processInstanceId);
query.setString(1, activityId);
return query.list();
}
});
return (List)result;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -