KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > db > TaskMgmtSession


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 JavaDoc 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   /**
27    * get the tasllist for a given actor.
28    */

29   public List findTaskInstances(String JavaDoc 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 JavaDoc e) {
36       log.error(e);
37       jbpmSession.handleException();
38       throw new RuntimeException JavaDoc("couldn't get task instances list for actor '"+actorId+"'", e);
39     }
40     return result;
41   }
42   
43   /**
44    * get all the task instances for all the given actorIds.
45    * @throws NullPointerException if actorIds is null.
46    */

47   public List findTaskInstances(List actorIds) {
48     return findTaskInstances((String JavaDoc[])actorIds.toArray(new String JavaDoc[actorIds.size()]));
49   }
50
51   private static final String JavaDoc 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   /**
58    * get all the task instances for all the given actorIds.
59    */

60   public List findTaskInstances(String JavaDoc[] 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 JavaDoc e) {
67       log.error(e);
68       jbpmSession.handleException();
69       throw new RuntimeException JavaDoc("couldn't get task instances list for actors '"+actorIds+"'", e);
70     }
71     return result;
72   }
73
74   private static final String JavaDoc 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   /**
83    * get the taskinstances for which the given actor is in the pool.
84    */

85   public List findPooledTaskInstances(String JavaDoc 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 JavaDoc e) {
92       log.error(e);
93       jbpmSession.handleException();
94       throw new RuntimeException JavaDoc("couldn't get pooled task instances list for actor '"+actorId+"'", e);
95     }
96     return result;
97   }
98   
99   private static final String JavaDoc 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   /**
108    * get the taskinstances for which the given actor is in the pool.
109    */

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 JavaDoc e) {
117       log.error(e);
118       jbpmSession.handleException();
119       throw new RuntimeException JavaDoc("couldn't get pooled task instances list for actors '"+actorIds+"'", e);
120     }
121     return result;
122   }
123
124   private static final String JavaDoc 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   /**
131    * get active taskinstances for a given token.
132    */

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 JavaDoc e) {
140       log.error(e);
141       jbpmSession.handleException();
142       throw new RuntimeException JavaDoc("couldn't get task instances by token '"+tokenId+"'", e);
143     }
144     return result;
145   }
146
147   /**
148    * get the task instance for a given task instance-id.
149    */

150   public TaskInstance loadTaskInstance(long taskInstanceId) {
151     TaskInstance taskInstance = null;
152     try {
153       taskInstance = (TaskInstance) session.load(TaskMgmtInstance.getTaskInstanceClass(), new Long JavaDoc(taskInstanceId));
154     } catch (Exception JavaDoc e) {
155       log.error(e);
156       jbpmSession.handleException();
157       throw new RuntimeException JavaDoc("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