1 package org.jbpm.db; 2 3 import java.util.*; 4 5 import org.apache.commons.logging.*; 6 import org.hibernate.*; 7 import org.jbpm.taskmgmt.exe.TaskInstance; 8 import org.jbpm.taskmgmt.exe.TaskMgmtInstance; 9 10 public class TaskMgmtSession { 11 12 JbpmSession jbpmSession = null; 13 Session session = null; 14 15 public TaskMgmtSession(JbpmSession jbpmSession) { 16 this.jbpmSession = jbpmSession; 17 this.session = jbpmSession.getSession(); 18 } 19 20 private static final String findTaskInstancesByActorId = 21 "select ti " + 22 "from org.jbpm.taskmgmt.exe.TaskInstance as ti " + 23 "where ti.actorId = :actorId " + 24 " and ti.end is null " + 25 " and ti.isCancelled = false"; 26 29 public List findTaskInstances(String actorId) { 30 List result = null; 31 try { 32 Query query = session.createQuery(findTaskInstancesByActorId); 33 query.setString("actorId", actorId); 34 result = query.list(); 35 } catch (Exception e) { 36 log.error(e); 37 jbpmSession.handleException(); 38 throw new RuntimeException ("couldn't get task instances list for actor '"+actorId+"'", e); 39 } 40 return result; 41 } 42 43 47 public List findTaskInstances(List actorIds) { 48 return findTaskInstances((String [])actorIds.toArray(new String [actorIds.size()])); 49 } 50 51 private static final String findTaskInstancesByActorIds = 52 "select ti " + 53 "from org.jbpm.taskmgmt.exe.TaskInstance as ti " + 54 "where ti.actorId in ( :actorIds )" + 55 " and ti.end is null " + 56 " and ti.isCancelled = false"; 57 60 public List findTaskInstances(String [] actorIds) { 61 List result = null; 62 try { 63 Query query = session.createQuery(findTaskInstancesByActorIds); 64 query.setParameterList("actorIds", actorIds); 65 result = query.list(); 66 } catch (Exception e) { 67 log.error(e); 68 jbpmSession.handleException(); 69 throw new RuntimeException ("couldn't get task instances list for actors '"+actorIds+"'", e); 70 } 71 return result; 72 } 73 74 private static final String findPooledTaskInstancesByActorId = 75 "select distinct ti " + 76 "from org.jbpm.taskmgmt.exe.PooledActor pooledActor " + 77 " join pooledActor.taskInstances ti " + 78 "where pooledActor.actorId = :swimlaneActorId " + 79 " and ti.actorId is null " + 80 " and ti.end is null " + 81 " and ti.isCancelled = false"; 82 85 public List findPooledTaskInstances(String actorId) { 86 List result = null; 87 try { 88 Query query = session.createQuery(findPooledTaskInstancesByActorId); 89 query.setString("swimlaneActorId", actorId); 90 result = query.list(); 91 } catch (Exception e) { 92 log.error(e); 93 jbpmSession.handleException(); 94 throw new RuntimeException ("couldn't get pooled task instances list for actor '"+actorId+"'", e); 95 } 96 return result; 97 } 98 99 private static final String findPooledTaskInstancesByActorIds = 100 "select distinct ti " + 101 "from org.jbpm.taskmgmt.exe.PooledActor pooledActor " + 102 " join pooledActor.taskInstances ti " + 103 "where pooledActor.actorId in ( :actorIds ) " + 104 " and ti.actorId is null " + 105 " and ti.end is null " + 106 " and ti.isCancelled = false"; 107 110 public List findPooledTaskInstances(List actorIds) { 111 List result = null; 112 try { 113 Query query = session.createQuery(findPooledTaskInstancesByActorIds); 114 query.setParameterList("actorIds", actorIds); 115 result = query.list(); 116 } catch (Exception e) { 117 log.error(e); 118 jbpmSession.handleException(); 119 throw new RuntimeException ("couldn't get pooled task instances list for actors '"+actorIds+"'", e); 120 } 121 return result; 122 } 123 124 private static final String findTaskInstancesByTokenId = 125 "select ti " + 126 "from org.jbpm.taskmgmt.exe.TaskInstance ti " + 127 "where ti.token.id = :tokenId " + 128 " and ti.end is null " + 129 " and ti.isCancelled = false"; 130 133 public List findTaskInstancesByToken(long tokenId) { 134 List result = null; 135 try { 136 Query query = session.createQuery(findTaskInstancesByTokenId); 137 query.setLong("tokenId", tokenId); 138 result = query.list(); 139 } catch (Exception e) { 140 log.error(e); 141 jbpmSession.handleException(); 142 throw new RuntimeException ("couldn't get task instances by token '"+tokenId+"'", e); 143 } 144 return result; 145 } 146 147 150 public TaskInstance loadTaskInstance(long taskInstanceId) { 151 TaskInstance taskInstance = null; 152 try { 153 taskInstance = (TaskInstance) session.load(TaskMgmtInstance.getTaskInstanceClass(), new Long (taskInstanceId)); 154 } catch (Exception e) { 155 log.error(e); 156 jbpmSession.handleException(); 157 throw new RuntimeException ("couldn't get task instance '"+taskInstanceId+"'", e); 158 } 159 return taskInstance; 160 } 161 162 163 private static final Log log = LogFactory.getLog(TaskMgmtSession.class); 164 } 165 | Popular Tags |