KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > instancepersistence > HibernatePersistentManager


1 /*
2  * Shark Hibernate persistent layer - Open Wide
3  */

4
5
6 package org.enhydra.shark.instancepersistence;
7
8 import java.math.BigDecimal JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import net.sf.hibernate.Query;
16 import net.sf.hibernate.Session;
17
18 import org.enhydra.shark.api.RootException;
19 import org.enhydra.shark.api.SharkTransaction;
20 import org.enhydra.shark.api.internal.instancepersistence.ActivityPersistenceInterface;
21 import org.enhydra.shark.api.internal.instancepersistence.ActivityVariablePersistenceInterface;
22 import org.enhydra.shark.api.internal.instancepersistence.AndJoinEntryInterface;
23 import org.enhydra.shark.api.internal.instancepersistence.AssignmentPersistenceInterface;
24 import org.enhydra.shark.api.internal.instancepersistence.DeadlinePersistenceInterface;
25 import org.enhydra.shark.api.internal.instancepersistence.PersistenceException;
26 import org.enhydra.shark.api.internal.instancepersistence.PersistentManagerInterface;
27 import org.enhydra.shark.api.internal.instancepersistence.ProcessMgrPersistenceInterface;
28 import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceInterface;
29 import org.enhydra.shark.api.internal.instancepersistence.ProcessVariablePersistenceInterface;
30 import org.enhydra.shark.api.internal.instancepersistence.ResourcePersistenceInterface;
31 import org.enhydra.shark.api.internal.working.CallbackUtilities;
32 import org.enhydra.shark.instancepersistence.data.HibernateActivityState;
33 import org.enhydra.shark.instancepersistence.data.HibernateProcessState;
34 import org.enhydra.shark.transaction.SharkHibernateTransaction;
35 import org.enhydra.shark.transaction.ThreadLocalSession;
36 import org.enhydra.shark.utilities.MiscUtilities;
37 import org.enhydra.shark.utilities.hibernate.HibernateUtilities;
38
39 /**
40  * Used to save, restore or delete relevant engine objects from database, using
41  * Hibernate persistent layer.
42  *
43  * @author Vladislav Pernin
44  * @version 1.0
45  */

46 public class HibernatePersistentManager implements PersistentManagerInterface {
47
48    private static final String JavaDoc LOG_CHANNEL="Persistence";
49    private static final int RESOURCE_TYPE_OBJECT=0;
50    private static final int PROCESS_DEFINITION_TYPE_OBJECT=1;
51    private static final int PROCESS_TYPE_OBJECT=2;
52    private static final int ACTIVITY_TYPE_OBJECT=3;
53    private static final int ASSIGNMENT_TYPE_OBJECT=4;
54
55    private static final String JavaDoc[] activityAndProcessStates={"open.running",
56          "open.not_running.not_started","open.not_running.suspended",
57          "closed.completed", "closed.terminated", "closed.aborted"};
58
59    private CallbackUtilities cus;
60    private boolean deleteFinishedProcesses = false;
61    private Map JavaDoc _prStates;
62    private Map JavaDoc _acStates;
63
64    //////////////////////////////////////////////////////////////////
65
// Initialization methods
66
//////////////////////////////////////////////////////////////////
67

68    public void configure(CallbackUtilities cus) throws RootException {
69       this.cus = cus;
70       String JavaDoc del = cus.getProperty("HibernatePersistentManager.deleteFinishedProcesses");
71       deleteFinishedProcesses = new Boolean JavaDoc(del).booleanValue();
72       _prStates = new HashMap JavaDoc();
73       _acStates = new HashMap JavaDoc();
74
75       try {
76          try {
77             HibernateUtilities.init(cus.getProperties());
78          } catch (Throwable JavaDoc ex) {
79             ex.printStackTrace();
80          }
81          initActivityAndProcessStatesTable();
82       } catch (Throwable JavaDoc tr) {
83          cus.error(LOG_CHANNEL, "Problem with registering database manager with Hibernate !", new RootException(tr));
84          throw new RootException("Problem with registering database manager with Hibernate !", tr);
85       }
86    }
87
88    /**
89       * Fills the state table with possible activity and process states. For now,
90       * the 'keyValue' and the 'name' attribute of state record has the same value,
91       * but in the future, if the names of states changes, it will be very easy
92       * to change this table entries without affecting other tables.
93       * NOTE: When new names are introduced, the getPersistentXXX that use it
94       * also has to be changed
95       */

96    private void initActivityAndProcessStatesTable() throws PersistenceException {
97       SharkHibernateTransaction ti = null;
98       try {
99          ti = new SharkHibernateTransaction(ThreadLocalSession.currentSession().beginTransaction());
100          Session session = ti.getSession();
101          for (int i = 0; i < activityAndProcessStates.length; i++) {
102             String JavaDoc state = activityAndProcessStates[i];
103             HibernateProcessState hibProcessState = getPersistedProcessStateObject(state, session);
104             if (hibProcessState == null) {
105                hibProcessState = new HibernateProcessState();
106                hibProcessState.setKeyValue(state);
107                hibProcessState.setName(state);
108                hibProcessState.setDbId(getNextDecId(HibernateUtilities.HibernateProcessStateClassName).intValue());
109                session.save(hibProcessState);
110             } else {
111                hibProcessState.setName(state);
112                session.update(hibProcessState);
113             }
114             _prStates.put(state, new Integer JavaDoc(hibProcessState.getDbId()));
115             HibernateActivityState hibActivityState = getPersistedActivityStateObject(state, session);
116             if (hibActivityState == null) {
117                hibActivityState = new HibernateActivityState();
118                hibActivityState.setKeyValue(state);
119                hibActivityState.setName(state);
120                hibActivityState.setDbId(getNextDecId(HibernateUtilities.HibernateActivityStateClassName).intValue());
121                session.save(hibActivityState);
122             } else {
123                hibActivityState.setName(state);
124                session.update(hibActivityState);
125             }
126             _acStates.put(state, new Integer JavaDoc(hibActivityState.getDbId()));
127          }
128          ti.commit();
129          session.clear();
130          session.close();
131       } catch (Throwable JavaDoc thr) {
132          thr.printStackTrace();
133          throw new PersistenceException(thr);
134       } finally {
135          try {
136             ti = null;
137          } catch (Exception JavaDoc ex) {
138          }
139       }
140    }
141
142    //////////////////////////////////////////////////////////////////
143
// Closing methods
144
//////////////////////////////////////////////////////////////////
145

146    public void shutdownDatabase() throws PersistenceException {
147       try {
148          ThreadLocalSession.closeSession();
149       } catch (Throwable JavaDoc tr) {
150          cus.error(LOG_CHANNEL, "Database is not properly shudown !", new RootException(tr));
151          throw new PersistenceException("Database is not properly shudown !", tr);
152       }
153    }
154
155    //////////////////////////////////////////////////////////////////
156
// Persist methods
157
//////////////////////////////////////////////////////////////////
158

159    public void persist(ProcessMgrPersistenceInterface pm, SharkTransaction ti) throws PersistenceException {
160       try {
161          HibernateProcessMgr hibProcessMgr = getPersistedObject(pm, ti);
162          if (hibProcessMgr == null) {
163             hibProcessMgr = (HibernateProcessMgr) createProcessMgr();
164             hibProcessMgr.setName(pm.getName());
165             hibProcessMgr.setPackageId(pm.getPackageId());
166             hibProcessMgr.setProcessDefinitionId(pm.getProcessDefinitionId());
167             hibProcessMgr.setVersion(pm.getVersion());
168             hibProcessMgr.setCreated(pm.getCreated());
169             hibProcessMgr.setState(pm.getState());
170             ((SharkHibernateTransaction)ti).store(hibProcessMgr);
171          } else {
172             hibProcessMgr.setState(pm.getState());
173             ((SharkHibernateTransaction)ti).store(hibProcessMgr);
174          }
175          cus.info(LOG_CHANNEL, "ProcessDefinition[packageId=" + pm.getPackageId() + ",id=" + pm.getProcessDefinitionId() + "] persisted");
176       } catch (Throwable JavaDoc tr) {
177          cus.error(LOG_CHANNEL, "Persisting of ProcessDefinition " + pm.getProcessDefinitionId() + " failed");
178          throw new PersistenceException("Persisting of ProcessDefinition " + pm.getProcessDefinitionId() + " failed", tr);
179       }
180    }
181
182    public void persist(ProcessPersistenceInterface pr, SharkTransaction ti) throws PersistenceException {
183       try {
184          HibernateProcess hibProcess = getPersistedObject(pr, ti);
185          HibernateProcessRequester hibProcessRequester = getProcessRequester(pr.getId(),ti);
186
187          HibernateActivity hibActivity = null;
188          HibernateResource hibResource = null;
189
190          if (pr.getActivityRequesterId() != null)
191             hibActivity = getPersistedActivityObject(pr.getActivityRequesterId(), ti);
192          if (pr.getResourceRequesterId() != null)
193             hibResource = getPersistedResourceObject(pr.getResourceRequesterId(), ti);
194          HibernateProcessMgr hibProcessMgr = getPersistedProcessMgrObject(pr.getProcessMgrName(), ti);
195
196          if (hibProcess == null) {
197             hibProcess = (HibernateProcess) createProcess();
198
199             hibProcess.setId(pr.getId());
200             hibProcess.setProcessMgrName(hibProcessMgr.getName());
201             if (pr.getActivityRequesterId() != null)
202                hibProcess.setActivityRequesterId(hibActivity.getId());
203             if (pr.getResourceRequesterId() != null)
204                hibProcess.setResourceRequesterId(hibResource.getUsername());
205             hibProcess.setName(pr.getName());
206             hibProcess.setDescription(pr.getDescription());
207             hibProcess.setPriority(pr.getPriority());
208
209             hibProcess.setState(pr.getState());
210             Integer JavaDoc stateId = (Integer JavaDoc)_prStates.get(pr.getState());
211             hibProcess.setStateId(stateId.intValue());
212
213             hibProcess.setStartedTime(pr.getStartedTime());
214             hibProcess.setLastStateTime(pr.getLastStateTime());
215
216             hibProcessRequester.setId(pr.getId());
217             if (hibActivity != null){
218                hibProcessRequester.setActRequester(hibActivity.getId());
219             }
220             if (hibResource != null){
221                hibProcessRequester.setResRequester(hibResource.getUsername());
222             }
223
224             ((SharkHibernateTransaction)ti).store(hibProcessRequester);
225             ((SharkHibernateTransaction)ti).store(hibProcess);
226          } else {
227             if (hibActivity != null)
228                hibProcess.setActivityRequesterId(hibActivity.getId());
229             if (hibResource != null)
230                hibProcess.setResourceRequesterId(hibResource.getUsername());
231             hibProcess.setName(pr.getName());
232             hibProcess.setDescription(pr.getDescription());
233             hibProcess.setPriority(pr.getPriority());
234
235             hibProcess.setState(pr.getState());
236             Integer JavaDoc stateId = (Integer JavaDoc)_prStates.get(pr.getState());
237             hibProcess.setStateId(stateId.intValue());
238
239             hibProcess.setStartedTime(pr.getStartedTime());
240             hibProcess.setLastStateTime(pr.getLastStateTime());
241
242             hibProcessRequester.setId(pr.getId());
243             if (hibActivity != null){
244                hibProcessRequester.setActRequester(hibActivity.getId());
245             }
246             if (hibResource != null){
247                hibProcessRequester.setResRequester(hibResource.getUsername());
248             }
249
250              ((SharkHibernateTransaction)ti).store(hibProcessRequester);
251              ((SharkHibernateTransaction)ti).store(hibProcess);
252          }
253
254          cus.info(LOG_CHANNEL, "Process[id=" + pr.getId() + "] persisted");
255       } catch (Throwable JavaDoc tr) {
256          tr.printStackTrace();
257          cus.error(LOG_CHANNEL, "Persisting of Process " + pr.getId() + " failed");
258          throw new PersistenceException("Persisting of Process " + pr.getId() + " failed", tr);
259       }
260    }
261
262    public void persist(ActivityPersistenceInterface act, SharkTransaction ti) throws PersistenceException {
263       try {
264          HibernateActivity hibActivity = getPersistedObject(act, ti);
265
266          if (hibActivity == null) {
267             hibActivity = (HibernateActivity) createActivity();
268             hibActivity.setId(act.getId());
269             hibActivity.setActivityDefinitionId(act.getActivityDefinitionId());
270             hibActivity.setActivitySetDefinitionId(act.getActivitySetDefinitionId());
271             hibActivity.setProcessId(getPersistedProcessObject(act.getProcessId(), ti).getId());
272             String JavaDoc bActId = act.getBlockActivityId();
273             if (bActId != null) {
274                hibActivity.setBlockActivityId(getPersistedActivityObject(bActId, ti).getId());
275             }
276             hibActivity.setName(act.getName());
277             hibActivity.setDescription(act.getDescription());
278             hibActivity.setPriority(act.getPriority());
279             if (act.getResourceUsername() != null){
280                HibernateResource res = getPersistedResourceObject(act.getResourceUsername(), ti);
281                hibActivity.setResourceUsername(res.getUsername());
282             }
283             hibActivity.setState(act.getState());
284             Integer JavaDoc stateId = (Integer JavaDoc)_acStates.get(act.getState());
285             hibActivity.setStateId(stateId.intValue());
286
287             hibActivity.setLastStateTime(act.getLastStateTime());
288             hibActivity.setAcceptedTime(act.getAcceptedTime());
289             hibActivity.setActivatedTime(act.getActivatedTime());
290
291             ((SharkHibernateTransaction)ti).store(hibActivity);
292          } else {
293             hibActivity.setName(act.getName());
294             hibActivity.setDescription(act.getDescription());
295             hibActivity.setPriority(act.getPriority());
296             if (act.getResourceUsername() != null){
297                HibernateResource res = getPersistedResourceObject(act.getResourceUsername(), ti);
298                hibActivity.setResourceUsername(res.getUsername());
299             }
300             hibActivity.setState(act.getState());
301             Integer JavaDoc stateId = (Integer JavaDoc)_acStates.get(act.getState());
302             hibActivity.setStateId(stateId.intValue());
303
304             hibActivity.setLastStateTime(act.getLastStateTime());
305             hibActivity.setAcceptedTime(act.getAcceptedTime());
306             hibActivity.setActivatedTime(act.getActivatedTime());
307
308             ((SharkHibernateTransaction)ti).store(hibActivity);
309          }
310
311          cus.info(LOG_CHANNEL, "Activity[id=" + act.getId() + ",definitionId=" + act.getActivityDefinitionId() + "] persisted");
312       } catch (Throwable JavaDoc tr) {
313          tr.printStackTrace();
314          cus.error(LOG_CHANNEL, "Persisting of Activity " + act.getId() + " failed");
315          throw new PersistenceException("Persisting of Activity " + act.getId() + " failed", tr);
316       }
317    }
318
319    public void persist(ResourcePersistenceInterface res, SharkTransaction ti) throws PersistenceException {
320       try {
321          HibernateResource hibResource = getPersistedObject(res, ti);
322
323          // when this attribute is persisted - it is never changed
324
if (hibResource == null) {
325             hibResource = (HibernateResource) createResource();
326             hibResource.setUsername(res.getUsername());
327             hibResource.setName(res.getName());
328             ((SharkHibernateTransaction)ti).store(hibResource);
329          } else {
330             hibResource.setName(res.getName());
331             ((SharkHibernateTransaction)ti).store(hibResource);
332          }
333          cus.info(LOG_CHANNEL, "Resource[username=" + res.getUsername() + "] persisted");
334       } catch (Throwable JavaDoc tr) {
335          cus.error(LOG_CHANNEL, "Persisting of Resource " + res.getUsername() + " failed");
336          throw new PersistenceException("Persisting of Resource " + res.getUsername() + " failed", tr);
337       }
338    }
339
340    public void persist(AssignmentPersistenceInterface ass, SharkTransaction ti) throws PersistenceException {
341       try {
342          HibernateAssignment hibAssign = getPersistedObject(ass, ti);
343
344          // when this attribute is persisted - it is never changed
345
if (hibAssign == null) {
346             hibAssign = (HibernateAssignment) createAssignment();
347             hibAssign.setActivityId(getPersistedActivityObject(ass.getActivityId(), ti).getId());
348             hibAssign.setResourceUsername(getPersistedResourceObject(ass.getResourceUsername(), ti).getUsername());
349             //redundant information but needed for by the kernel
350
hibAssign.setProcessId(ass.getProcessId());
351             ((SharkHibernateTransaction)ti).store(hibAssign);
352          } else {
353             hibAssign.setResourceUsername(getPersistedResourceObject(ass.getResourceUsername(), ti).getUsername());
354             ((SharkHibernateTransaction)ti).store(hibAssign);
355          }
356          cus.info(LOG_CHANNEL, "Assignment[activityId=" + ass.getActivityId() + ", username=" + ass.getResourceUsername() + "] persisted");
357       } catch (Throwable JavaDoc tr) {
358          cus.error(LOG_CHANNEL, "Persisting of Assignment failed");
359          throw new PersistenceException("Persisting of Assignment failed", tr);
360       }
361    }
362
363    public void persist(AssignmentPersistenceInterface ass, String JavaDoc oldResUname, SharkTransaction ti) throws PersistenceException {
364       try {
365          Session session = ((SharkHibernateTransaction) ti).getSession();
366          HibernateAssignment hibAssign = getPersistedAssignmentObject(ass.getActivityId(), oldResUname, ti);
367          if (hibAssign != null) {
368             hibAssign.setResourceUsername(getPersistedResourceObject(ass.getResourceUsername(), ti).getUsername());
369             ((SharkHibernateTransaction)ti).store(hibAssign);
370          } else {
371             cus.error(LOG_CHANNEL, "Assignment[activityId=" + ass.getActivityId() + ", with old resource name=" + oldResUname + "] cannot be updatet because it is not persisted");
372          }
373
374          cus.info(LOG_CHANNEL, "Assignment[activityId=" + ass.getActivityId() + ", username=" + ass.getResourceUsername() + "] persisted");
375       } catch (Throwable JavaDoc tr) {
376          cus.error(LOG_CHANNEL, "Persisting of Assignment failed");
377          throw new PersistenceException("Persisting of Assignment failed", tr);
378       }
379    }
380
381    public void persist(ProcessVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
382       try {
383          HibernateProcessVariable hibProcessVariable = getPersistedObject(var, ti);
384          // when this attribute is persisted - it is never changed
385
if (hibProcessVariable == null) {
386             hibProcessVariable = (HibernateProcessVariable) createProcessVariable();
387             hibProcessVariable.setProcessId(getPersistedProcessObject(var.getProcessId(), ti).getId());
388             hibProcessVariable.setDefinitionId(var.getDefinitionId());
389             hibProcessVariable.setValue(MiscUtilities.serialize(var.getValue()));
390             ((SharkHibernateTransaction)ti).store(hibProcessVariable);
391          } else {
392             hibProcessVariable.setValue(MiscUtilities.serialize(var.getValue()));
393             ((SharkHibernateTransaction)ti).store(hibProcessVariable);
394          }
395          cus.info(LOG_CHANNEL, "ProcessVariable[processId=" + var.getProcessId() + ", definitionId=" + var.getDefinitionId() + "] persisted");
396       } catch (Throwable JavaDoc tr) {
397          cus.error(LOG_CHANNEL, "Persisting of ProcessVariable failed");
398          throw new PersistenceException("Persisting of ProcessVariable failed", tr);
399       }
400    }
401
402    public void persist(ActivityVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
403       try {
404          HibernateActivityVariable hibActivityVariable = getPersistedObject(var, ti);
405
406          // when this attribute is persisted - it is never changed
407
if (hibActivityVariable == null) {
408             hibActivityVariable = (HibernateActivityVariable) createActivityVariable();
409             hibActivityVariable.setActivityId(getPersistedActivityObject(var.getActivityId(), ti).getId());
410             hibActivityVariable.setDefinitionId(var.getDefinitionId());
411             hibActivityVariable.setValue(MiscUtilities.serialize(var.getValue()));
412             hibActivityVariable.setResultVariable(var.isResultVariable());
413             ((SharkHibernateTransaction)ti).store(hibActivityVariable);
414          } else {
415             hibActivityVariable.setValue(MiscUtilities.serialize(var.getValue()));
416             hibActivityVariable.setResultVariable(var.isResultVariable());
417             ((SharkHibernateTransaction)ti).store(hibActivityVariable);
418          }
419
420          cus.info(LOG_CHANNEL, "ActivityVariable[activityId=" + var.getActivityId() + ", definitionId=" + var.getDefinitionId() + "] persisted");
421       } catch (Throwable JavaDoc tr) {
422          cus.error(LOG_CHANNEL, "Persisting of ActivityVariable failed");
423          throw new PersistenceException("Persisting of ActivityVariable failed", tr);
424       }
425    }
426
427    public void persist(AndJoinEntryInterface aje, SharkTransaction ti) throws PersistenceException {
428       try {
429          Session session = ((SharkHibernateTransaction) ti).getSession();
430          HibernateAndJoinEntry hibAJE = (HibernateAndJoinEntry) createAndJoinEntry();
431          hibAJE.setProcessId(getPersistedProcessObject(aje.getProcessId(), ti).getId());
432          hibAJE.setActivityDefinitionId(aje.getActivityDefinitionId());
433          hibAJE.setActivitySetDefinitionId(aje.getActivitySetDefinitionId());
434          hibAJE.setActivityId(getPersistedActivityObject(aje.getActivityId(), ti).getId());
435          ((SharkHibernateTransaction)ti).store(hibAJE);
436
437          cus.info(LOG_CHANNEL, "AndJoinEntry[id=" + aje.getProcessId() + ",aDefId=" + aje.getActivityDefinitionId() + ",actId=" + aje.getActivityId() + "] persisted");
438       } catch (Throwable JavaDoc tr) {
439          cus.error(LOG_CHANNEL, "Persisting of AndJoinEntry [id=" + aje.getProcessId() + ",aDefId=" + aje.getActivityDefinitionId() + ",actId=" + aje.getActivityId() + "] failed");
440          throw new PersistenceException("Persisting of AndJoinEntry [id=" + aje.getProcessId() + ",aDefId=" + aje.getActivityDefinitionId() + ",actId=" + aje.getActivityId() + "] failed", tr);
441       }
442    }
443
444    public void persist(DeadlinePersistenceInterface dpe, SharkTransaction ti) throws PersistenceException {
445       try {
446          System.out.println("PERSIST DEADLINE :" + dpe);
447          HibernateDeadline hibDeadline = (HibernateDeadline) createDeadline();
448          hibDeadline.setProcessId(getPersistedProcessObject(dpe.getProcessId(),ti).getId());
449          hibDeadline.setActivityId(getPersistedActivityObject(dpe.getActivityId(),ti).getId());
450          hibDeadline.setExceptionName(dpe.getExceptionName());
451          hibDeadline.setTimeLimit(dpe.getTimeLimit());
452          hibDeadline.setSynchronous(dpe.isSynchronous());
453          System.out.println("PERSIST DEADLINE 2:" + hibDeadline);
454          ((SharkHibernateTransaction)ti).store(hibDeadline);
455          cus.info(LOG_CHANNEL,"Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] persisted");
456       }
457       catch (Throwable JavaDoc tr) {
458          cus.error(LOG_CHANNEL,"Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed");
459          throw new PersistenceException(
460                "Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed",tr);
461       }
462    }
463
464
465    //////////////////////////////////////////////////////////////////
466
// Restore methods
467
//////////////////////////////////////////////////////////////////
468

469    public ProcessMgrPersistenceInterface restoreProcessMgr(String JavaDoc mgrName, SharkTransaction ti) throws PersistenceException {
470       try {
471          Session session = ((SharkHibernateTransaction) ti).getSession();
472          return restore(getPersistedProcessMgrObject(mgrName, ti), session);
473
474       } catch (Throwable JavaDoc tr) {
475          cus.error(LOG_CHANNEL, "Restoring of ProcessDefinition name " + mgrName + " failed");
476          throw new PersistenceException("Restoring of ProcessDefinition " + mgrName + " failed", tr);
477       }
478    }
479
480    private ProcessMgrPersistenceInterface restore(HibernateProcessMgr hibProcessMgr, Session session) throws PersistenceException {
481       if (hibProcessMgr == null)
482          return null;
483       try {
484          cus.info(LOG_CHANNEL, "ProcessDefinition [name=" + hibProcessMgr.getName() + "] restored");
485       } catch (Throwable JavaDoc tr) {
486          cus.error(LOG_CHANNEL, "Restoring of Resource failed");
487          throw new PersistenceException("Restoring of Resource failed", tr);
488       }
489       return hibProcessMgr;
490    }
491
492    public ProcessPersistenceInterface restoreProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
493       try {
494          Session session = ((SharkHibernateTransaction) ti).getSession();
495          return restore(getPersistedProcessObject(procId, ti), getProcessRequester(procId,ti),ti);
496       } catch (Throwable JavaDoc tr) {
497          tr.printStackTrace();
498          cus.error(LOG_CHANNEL, "Restoring of Process " + procId + " failed");
499          throw new PersistenceException("Restoring of Process " + procId + " failed", tr);
500       }
501    }
502
503    private ProcessPersistenceInterface restore(HibernateProcess hibProcess, HibernateProcessRequester processRequester, SharkTransaction ti) throws PersistenceException {
504       if (hibProcess == null)
505          return null;
506       try {
507          Session session = ((SharkHibernateTransaction) ti).getSession();
508          hibProcess.setState(getPersistedProcessStateObjectById(hibProcess.getStateId(), session).getName());
509
510          HibernateActivity hibActivity = null;
511          if (processRequester.getActRequester() != null)
512             hibActivity = getPersistedActivityObject(processRequester.getActRequester(), ti);
513          if (hibActivity != null) {
514             hibProcess.setActivityRequesterId(hibActivity.getId());
515             hibProcess.setActivityRequestersProcessId(hibActivity.getProcessId());
516          }
517          HibernateResource hibResource = null;
518          if (processRequester.getResRequester() != null)
519             hibResource = getPersistedResourceObject(processRequester.getResRequester(), ti);
520          if (hibResource != null){
521             hibProcess.setResourceRequesterId(hibResource.getUsername());
522          }
523          cus.info(LOG_CHANNEL, "Process[id=" + hibProcess.getId() + "] restored");
524       } catch (Throwable JavaDoc tr) {
525          cus.error(LOG_CHANNEL, "Restoring of Process failed");
526          throw new PersistenceException("Restoring of Process failed", tr);
527       }
528       return hibProcess;
529    }
530
531    public ActivityPersistenceInterface restoreActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
532       try {
533          return restore(getPersistedActivityObject(actId, ti), ti);
534       } catch (Throwable JavaDoc tr) {
535          cus.error(LOG_CHANNEL, "Restoring of Activity " + actId + " failed");
536          throw new PersistenceException("Restoring of Activity " + actId + " failed", tr);
537       }
538    }
539
540    private ActivityPersistenceInterface restore(HibernateActivity hibActivity, SharkTransaction ti) throws PersistenceException {
541       if (hibActivity == null)
542          return null;
543
544       try {
545          Session session = ((SharkHibernateTransaction) ti).getSession();
546          HibernateProcessRequester processRequester = getProcessRequesterByActId(hibActivity.getId(),ti);
547          if (processRequester != null) {
548             hibActivity.setSubflowProcessId(processRequester.getId());
549          }
550          hibActivity.setState(getPersistedActivityStateObjectById(hibActivity.getStateId(), session).getName());
551          cus.info(LOG_CHANNEL, "Activity[id=" + hibActivity.getId() + ",definitionId=" + hibActivity.getActivityDefinitionId() + "] restored");
552       } catch (Throwable JavaDoc tr) {
553          cus.error(LOG_CHANNEL, "Restoring of Activity failed");
554          throw new PersistenceException("Restoring of Activity failed", tr);
555       }
556       return hibActivity;
557    }
558
559    public ResourcePersistenceInterface restoreResource(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
560       try {
561          Session session = ((SharkHibernateTransaction) ti).getSession();
562          return restore(getPersistedResourceObject(resUsername, ti), session);
563       } catch (Throwable JavaDoc tr) {
564          cus.error(LOG_CHANNEL, "Restoring of Resource " + resUsername + " failed");
565          throw new PersistenceException("Restoring of Resource " + resUsername + " failed", tr);
566       }
567    }
568
569    private ResourcePersistenceInterface restore(HibernateResource hibResource, Session session) throws PersistenceException {
570       if (hibResource == null)
571          return null;
572
573       try {
574          cus.info(LOG_CHANNEL, "Resource[username=" + hibResource.getUsername() + "] restored");
575       } catch (Throwable JavaDoc tr) {
576          cus.error(LOG_CHANNEL, "Restoring of Resource failed");
577          throw new PersistenceException("Restoring of Resource failed", tr);
578       }
579       return hibResource;
580    }
581
582    public AssignmentPersistenceInterface restoreAssignment(String JavaDoc actId, String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
583       try {
584          return restore(getPersistedAssignmentObject(actId, resUsername, ti), ti);
585       } catch (Throwable JavaDoc tr) {
586          cus.error(LOG_CHANNEL, "Restoring of Assignment failed");
587          throw new PersistenceException("Restoring of Assignment failed", tr);
588       }
589    }
590
591    private AssignmentPersistenceInterface restore(HibernateAssignment hibAssign, SharkTransaction ti) throws PersistenceException {
592       if (hibAssign == null)
593          return null;
594       try {
595          hibAssign.setProcessId(getPersistedActivityObject(hibAssign.getActivityId(), ti).getProcessId());
596          cus.info(LOG_CHANNEL, "Assignment[activityId=" + hibAssign.getActivityId() + ", username=" + hibAssign.getResourceUsername() + "] restored");
597       } catch (Throwable JavaDoc tr) {
598          cus.error(LOG_CHANNEL, "Restoring of Assignment failed");
599          throw new PersistenceException("Restoring of Assignment failed", tr);
600       }
601       return hibAssign;
602    }
603
604    public boolean restore(ProcessVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
605       try {
606          Session session = ((SharkHibernateTransaction) ti).getSession();
607          return restore(var, getPersistedObject(var, ti), session);
608       } catch (Throwable JavaDoc tr) {
609          cus.error(LOG_CHANNEL, "Restoring of Assignment failed");
610          throw new PersistenceException("Restoring of Assignment failed", tr);
611       }
612    }
613
614    private boolean restore(ProcessVariablePersistenceInterface engineObj, HibernateProcessVariable hibProcessVariable, Session s) throws PersistenceException {
615       if (hibProcessVariable == null)
616          return false;
617       try {
618          engineObj.setProcessId(hibProcessVariable.getProcessId());
619          engineObj.setDefinitionId(hibProcessVariable.getDefinitionId());
620          engineObj.setValue(MiscUtilities.deserialize((byte[]) hibProcessVariable.getValue()));
621
622          cus.info(LOG_CHANNEL, "ProcessVariable[processId=" + engineObj.getProcessId() + ", definitionId=" + engineObj.getDefinitionId() + "] restored");
623       } catch (Throwable JavaDoc tr) {
624          cus.error(LOG_CHANNEL, "Restoring of ProcessVariable failed");
625          throw new PersistenceException("Restoring of ProcessVariable failed", tr);
626       }
627       return true;
628    }
629
630    public boolean restore(ActivityVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
631       try {
632          Session session = ((SharkHibernateTransaction) ti).getSession();
633          return restore(var, getPersistedObject(var, ti), session);
634       } catch (Throwable JavaDoc tr) {
635          cus.error(LOG_CHANNEL, "Restoring of Assignment failed");
636          throw new PersistenceException("Restoring of Assignment failed", tr);
637       }
638    }
639
640    private boolean restore(ActivityVariablePersistenceInterface engineObj, HibernateActivityVariable hibActivityVariable, Session s) throws PersistenceException {
641       if (hibActivityVariable == null)
642          return false;
643
644       try {
645          engineObj.setActivityId(hibActivityVariable.getActivityId());
646          engineObj.setDefinitionId(hibActivityVariable.getDefinitionId());
647          engineObj.setValue(MiscUtilities.deserialize((byte[]) hibActivityVariable.getValue()));
648          engineObj.setResultVariable(hibActivityVariable.isResultVariable());
649          cus.info(LOG_CHANNEL, "ActivityVariable[activityId=" + engineObj.getActivityId() + ", definitionId=" + engineObj.getDefinitionId() + "] restored");
650       } catch (Throwable JavaDoc tr) {
651          cus.error(LOG_CHANNEL, "Restoring of Variable failed");
652          throw new PersistenceException("Restoring of Variable failed", tr);
653       }
654       return true;
655    }
656
657    private boolean restore(AndJoinEntryInterface engineObj, HibernateAndJoinEntry hibAndJoinEntry, Session s) throws PersistenceException {
658       if (hibAndJoinEntry == null)
659          return false;
660
661       try {
662          engineObj.setProcessId(hibAndJoinEntry.getProcessId());
663          engineObj.setActivityDefinitionId(hibAndJoinEntry.getActivityDefinitionId());
664          engineObj.setActivitySetDefinitionId(hibAndJoinEntry.getActivitySetDefinitionId());
665          engineObj.setActivityId(hibAndJoinEntry.getActivityId());
666          cus.info(
667             LOG_CHANNEL,
668             "AndJoinEntry[processId=" + engineObj.getProcessId() + ",activityId=" + engineObj.getActivityId() + ", activityDefinitionId=" + engineObj.getActivityDefinitionId() + "] restored");
669       } catch (Throwable JavaDoc tr) {
670          cus.error(LOG_CHANNEL, "Restoring of AndJoinEntry failed");
671          throw new PersistenceException("Restoring of AndJoinEntry failed", tr);
672       }
673       return true;
674    }
675
676    //////////////////////////////////////////////////////////////////
677
// Delete methods
678
//////////////////////////////////////////////////////////////////
679

680    public void deleteProcessMgr(String JavaDoc mgrName, SharkTransaction ti) throws PersistenceException {
681       try {
682          HibernateProcessMgr hibProcessDef = getPersistedProcessMgrObject(mgrName, ti);
683          if (getAllProcessesForMgr(mgrName, ti).size() > 0)
684             return;
685          ((SharkHibernateTransaction)ti).erase(hibProcessDef);
686          cus.info(LOG_CHANNEL, "ProcessDefinition[name=" + mgrName + "] deleted");
687       } catch (Throwable JavaDoc tr) {
688          cus.error(LOG_CHANNEL, "Deleting of ProcessDefinition failed");
689          throw new PersistenceException("Deleting of ProcessDefinition failed", tr);
690       }
691    }
692
693    public void deleteProcess(String JavaDoc procId, boolean administrative,SharkTransaction ti) throws PersistenceException {
694       if (!deleteFinishedProcesses && !administrative)
695          return;
696       try {
697          Session session = ((SharkHibernateTransaction) ti).getSession();
698
699          //get depending activities
700
List JavaDoc activities = getActivities(procId, ti);
701          List JavaDoc activitiesId = new ArrayList JavaDoc();
702          if (activities.size() != 0) {
703             for (Iterator JavaDoc it = activities.iterator(); it.hasNext();) {
704                activitiesId.add(((HibernateActivity) it.next()).getId());
705             }
706          }
707          //get depending block activities
708
List JavaDoc blockActivities = new ArrayList JavaDoc();
709          if (activitiesId.size() != 0) {
710             for (Iterator JavaDoc it = activitiesId.iterator(); it.hasNext();) {
711                List JavaDoc blockActs = getActivitiesForBlockActivity((String JavaDoc) it.next(), ti);
712                for (Iterator JavaDoc itBAs = blockActs.iterator(); itBAs.hasNext();) {
713                   Object JavaDoc obj = itBAs.next();
714                   if (!blockActivities.contains(obj)) {
715                      blockActivities.add(obj);
716                   }
717                }
718             }
719          }
720
721          // get all Activity whose processId equals to <procId>--no need anymore and it is not a good thing to delete process requested by an activity if not required directly
722
/*if (activitiesId.size() != 0) {
723             for (Iterator itActId = activitiesId.iterator(); itActId.hasNext();) {
724                String actId = (String) itActId.next();
725                processes = getProcessesForActivity(actId, ti);
726             }
727          }*/

728
729          //delete ProcessRequester entries where id equals to <procId>
730
((SharkHibernateTransaction)ti).erase(getProcessRequester(procId,ti));
731
732          // delete all Assignment object whose activityId equals to <>
733
List JavaDoc assignments = new ArrayList JavaDoc();
734          if (activitiesId.size() != 0) {
735             for (Iterator JavaDoc it = activitiesId.iterator(); it.hasNext();) {
736                List JavaDoc assigns = getAssignmentsOnActivity((String JavaDoc) it.next(), ti);
737                for (Iterator JavaDoc itAssigns = assigns.iterator(); itAssigns.hasNext();) {
738                   Object JavaDoc obj = itAssigns.next();
739                   if (!assignments.contains(obj)) {
740                      assignments.add(obj);
741                   }
742                }
743             }
744             for (Iterator JavaDoc itBA = blockActivities.iterator(); itBA.hasNext();) {
745                List JavaDoc assigns = getAssignmentsOnActivity(((HibernateActivity) itBA.next()).getId(), ti);
746                for (Iterator JavaDoc itAssigns = assigns.iterator(); itAssigns.hasNext();) {
747                   Object JavaDoc obj = itAssigns.next();
748                   if (!assignments.contains(obj)) {
749                      assignments.add(obj);
750                   }
751                }
752             }
753          }
754          if (assignments.size() != 0) {
755             for (Iterator JavaDoc itA = assignments.iterator(); itA.hasNext();) {
756                ((SharkHibernateTransaction)ti).erase((HibernateAssignment) itA.next());
757             }
758          }
759
760          // delete all AndJoinEntry objects whose processId equals to <procId> or whose activityId equals to <>
761
List JavaDoc andJoinEntries = new ArrayList JavaDoc();
762          if (activitiesId.size() != 0) {
763             for (Iterator JavaDoc it = activitiesId.iterator(); it.hasNext();) {
764                List JavaDoc ajes = getPersistedAndJoinEntriesForActivity((String JavaDoc) it.next(), ti);
765                for (Iterator JavaDoc itAJEs = ajes.iterator(); itAJEs.hasNext();) {
766                   Object JavaDoc obj = itAJEs.next();
767                   if (!andJoinEntries.contains(obj)) {
768                      andJoinEntries.add(obj);
769                   }
770                }
771             }
772          }
773          List JavaDoc ajes = getPersistedAndJoinEntriesForProcess(procId, ti);
774          for (Iterator JavaDoc itAJEs = ajes.iterator(); itAJEs.hasNext();) {
775             Object JavaDoc obj = itAJEs.next();
776             if (!andJoinEntries.contains(obj)) {
777                andJoinEntries.add(obj);
778             }
779          }
780          if (blockActivities.size() != 0) {
781             for (Iterator JavaDoc it = blockActivities.iterator(); it.hasNext();) {
782                List JavaDoc ajeBAs = getPersistedAndJoinEntriesForActivity(((HibernateActivity) it.next()).getId(), ti);
783                for (Iterator JavaDoc itAJEBAs = ajeBAs.iterator(); itAJEBAs.hasNext();) {
784                   Object JavaDoc obj = itAJEBAs.next();
785                   if (!andJoinEntries.contains(obj)) {
786                      andJoinEntries.add(obj);
787                   }
788                }
789             }
790          }
791          if (andJoinEntries.size() != 0) {
792             for (Iterator JavaDoc it = andJoinEntries.iterator(); it.hasNext();) {
793                ((SharkHibernateTransaction)ti).erase((HibernateAndJoinEntry) it.next());
794             }
795          }
796
797          // delete all ActivityVariable objects whose activityId equals to <>
798
List JavaDoc activityVariables = new ArrayList JavaDoc();
799          if (activitiesId.size() != 0) {
800             for (Iterator JavaDoc it = activitiesId.iterator(); it.hasNext();) {
801                List JavaDoc vars = getActivityVariablesOnActivity((String JavaDoc) it.next(), ti);
802                for (Iterator JavaDoc itVars = vars.iterator(); itVars.hasNext();) {
803                   Object JavaDoc obj = itVars.next();
804                   if (!activityVariables.contains(obj)) {
805                      activityVariables.add(obj);
806                   }
807                }
808             }
809             for (Iterator JavaDoc itBA = blockActivities.iterator(); itBA.hasNext();) {
810                List JavaDoc vars = getActivityVariablesOnActivity(((HibernateActivity) itBA.next()).getId(), ti);
811                for (Iterator JavaDoc itVars = vars.iterator(); itVars.hasNext();) {
812                   Object JavaDoc obj = itVars.next();
813                   if (!activityVariables.contains(obj)) {
814                      activityVariables.add(obj);
815                   }
816                }
817             }
818          }
819          if (activityVariables.size() != 0) {
820             for (Iterator JavaDoc itPV = activityVariables.iterator(); itPV.hasNext();) {
821                ((SharkHibernateTransaction)ti).erase((HibernateActivityVariable) itPV.next());
822             }
823          }
824
825          // delete all ProcessVariable objects whose processId equals to <procId>
826
List JavaDoc processVariables = getProcessVariablesOnProcess(procId, ti);
827          if (processVariables.size() != 0) {
828             for (Iterator JavaDoc it = processVariables.iterator(); it.hasNext();) {
829                ((SharkHibernateTransaction)ti).erase((HibernateProcessVariable) it.next());
830             }
831          }
832
833          // delete all Activity whose block activity equals to <activities.element.id>
834
if (blockActivities.size() != 0) {
835             for (Iterator JavaDoc itBA = blockActivities.iterator(); itBA.hasNext();) {
836                ((SharkHibernateTransaction)ti).erase((HibernateActivity) itBA.next());
837             }
838          }
839
840          // delete all Activity whose processId equals to <procId>
841
if (activitiesId.size() != 0) {
842             for (Iterator JavaDoc itActId = activitiesId.iterator(); itActId.hasNext();) {
843                String JavaDoc actId = (String JavaDoc) itActId.next();
844                if (actId != null)
845                   ((SharkHibernateTransaction)ti).erase(getPersistedActivityObject(actId,ti));
846             }
847          }
848
849          ((SharkHibernateTransaction)ti).erase(getPersistedProcessObject(procId,ti));
850
851          ((SharkHibernateTransaction)ti).setDeleteFinishedProcesses(true);
852
853          cus.info(LOG_CHANNEL, "Process[id=" + procId + "] deleted");
854       } catch (Throwable JavaDoc tr) {
855          cus.error(LOG_CHANNEL, "Deleting of Process failed");
856          throw new PersistenceException("Deleting of Process failed", tr);
857       }
858    }
859
860    public void deleteActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
861       // NEVER DELETE ACTIVITIES
862
if (true)
863          return;
864    }
865
866    public void deleteResource(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
867       // NEVER DELETE RESOURCES
868
if (true)
869          return;
870    }
871
872    public void deleteAssignment(String JavaDoc actId, String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
873       //if (!delete) return;
874
try {
875          HibernateAssignment hibAssign = getPersistedAssignmentObject(actId, resUsername, ti);
876          if (hibAssign != null)
877             ((SharkHibernateTransaction)ti).erase(hibAssign);
878          cus.info(LOG_CHANNEL, "Assignment[activityId=" + actId + ", username=" + resUsername + "] deleted");
879       } catch (Throwable JavaDoc tr) {
880          cus.error(LOG_CHANNEL, "Deleting of Assignment failed");
881          throw new PersistenceException("Deleting of Assignment failed", tr);
882       }
883    }
884
885    public void deleteAndJoinEntries(String JavaDoc procId, String JavaDoc asDefId, String JavaDoc aDefId, SharkTransaction ti) throws PersistenceException {
886       try {
887          List JavaDoc ajes = getPersistedAndJoinEntries(procId,asDefId,aDefId,ti);
888          List JavaDoc toRemove = new ArrayList JavaDoc();
889          if (ajes.size() > 0) {
890             for (Iterator JavaDoc it = ajes.iterator(); it.hasNext();) {
891                toRemove.add((HibernateAndJoinEntry) it.next());
892             }
893             //Have to make erase operation separate to avoid ConcurrentModification exception!
894
for (Iterator JavaDoc it = toRemove.iterator(); it.hasNext();) {
895                ((SharkHibernateTransaction)ti).erase(it.next());
896             }
897             cus.info(LOG_CHANNEL, "AndJoinEntries for [procId=" + procId + ", aDefId=" + aDefId + "] deleted");
898          } else {
899             cus.info(LOG_CHANNEL, "There is no AndJoinEntries for [procId=" + procId + ", aDefId=" + aDefId + "] to delete");
900          }
901       } catch (Throwable JavaDoc tr) {
902          cus.error(LOG_CHANNEL, "Deleting of AndJoinEntries for [procId=" + procId + ", aDefId=" + aDefId + "] failed");
903          throw new PersistenceException("Deleting of AndJoinEntries for [procId=" + procId + ", aDefId=" + aDefId + "] failed", tr);
904       }
905    }
906
907    public void delete(ProcessVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
908       // NEVER DELETE PROCESS VARIABLES
909
if (true)
910          return;
911    }
912
913    public void delete(ActivityVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
914       // NEVER DELETE ACTIVITY VARIABLES
915
if (true)
916          return;
917    }
918
919    public void deleteDeadlines (String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
920       try {
921          List JavaDoc deadlines = getPersistedDeadlines(procId,-1,ti);
922          List JavaDoc toRemove = new ArrayList JavaDoc();
923          if (deadlines.size() != 0) {
924             for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
925                toRemove.add((HibernateDeadline) it.next());
926             }
927             //Have to make erase operation separate to avoid ConcurrentModification exception!
928
for (Iterator JavaDoc it = toRemove.iterator(); it.hasNext();) {
929                ((SharkHibernateTransaction)ti).erase(it.next());
930             }
931             cus.info(LOG_CHANNEL,"Deadlines for process "+procId+" deleted");
932          } else {
933             cus.info(LOG_CHANNEL,"There are no Deadlines defined for the proces "+procId);
934          }
935       } catch (Throwable JavaDoc tr) {
936          cus.error(LOG_CHANNEL,"Deleting deadlines for the process "+procId+" failed");
937          throw new PersistenceException
938          ("Deleting deadlines for the process "+procId+" failed", tr);
939       }
940    }
941
942    public void deleteDeadlines (String JavaDoc procId, String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
943       try {
944          List JavaDoc deadlines = getActivitiesPersistedDeadlines(actId,-1,ti);
945          if (deadlines.size() != 0) {
946             for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
947                ((SharkHibernateTransaction)ti).erase(it.next());
948             }
949             cus.info(LOG_CHANNEL,"Deadlines for activity "+actId+" deleted");
950          } else {
951             cus.info(LOG_CHANNEL,"There are no Deadlines defined for the activity "+actId);
952          }
953       } catch (Throwable JavaDoc tr) {
954          cus.error(LOG_CHANNEL,"Deleting deadlines for the activity "+actId+" failed");
955          throw new PersistenceException
956          ("Deleting deadlines for the activity "+actId+" failed", tr);
957       }
958    }
959
960    //////////////////////////////////////////////////////////////////
961
// Query methods
962
//////////////////////////////////////////////////////////////////
963

964
965    private HibernateProcessState getPersistedProcessStateObject(String JavaDoc value, Session session) throws PersistenceException {
966       try {
967          Query qProcessState = session.createQuery("from HibernateProcessState processState where processState.keyValue = :keyValueParam");
968          qProcessState.setString("keyValueParam", value);
969          return (HibernateProcessState) qProcessState.uniqueResult();
970       } catch (Throwable JavaDoc t) {
971          throw new PersistenceException(t);
972       }
973    }
974
975    private HibernateProcessState getPersistedProcessStateObjectById(int id, Session session) throws PersistenceException {
976       try {
977          Integer JavaDoc intId = new Integer JavaDoc(id);
978          return (HibernateProcessState) session.get(HibernateProcessState.class, intId);
979       } catch (Throwable JavaDoc t) {
980          throw new PersistenceException(t);
981       }
982    }
983
984    private HibernateActivityState getPersistedActivityStateObjectById(int id, Session session) throws PersistenceException {
985       try {
986          Integer JavaDoc intId = new Integer JavaDoc(id);
987          return (HibernateActivityState) session.get(HibernateActivityState.class, intId);
988       } catch (Throwable JavaDoc t) {
989          throw new PersistenceException(t);
990       }
991    }
992
993    private HibernateActivityState getPersistedActivityStateObject(String JavaDoc value, Session session) throws PersistenceException {
994       try {
995          Query qActivityState = session.createQuery("from HibernateActivityState activityState where activityState.keyValue = :keyValueParam");
996          qActivityState.setString("keyValueParam", value);
997          return (HibernateActivityState) qActivityState.uniqueResult();
998
999       } catch (Throwable JavaDoc t) {
1000         throw new PersistenceException(t);
1001      }
1002   }
1003
1004
1005   private HibernateProcessMgr getPersistedObject(ProcessMgrPersistenceInterface mgr, SharkTransaction ti) throws PersistenceException {
1006      try {
1007         return getPersistedProcessMgrObject(mgr.getName(), ti);
1008      } catch (Throwable JavaDoc t) {
1009         throw new PersistenceException(t);
1010      }
1011   }
1012
1013   private HibernateProcessMgr getPersistedProcessMgrObject(String JavaDoc name, SharkTransaction ti) throws PersistenceException {
1014      try {
1015         Session s = ((SharkHibernateTransaction) ti).getSession();
1016         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessMgrClassName);
1017         it.hasNext();) {
1018            HibernateProcessMgr hibProcessMgr = (HibernateProcessMgr)it.next();
1019            if (name.equals(hibProcessMgr.getName()))
1020               return hibProcessMgr;
1021         }
1022         Query qProcessMgr = s.createQuery("from HibernateProcessMgr processMgr where processMgr.name = :keyValueParam");
1023         qProcessMgr.setString("keyValueParam", name);
1024         HibernateProcessMgr hibProcessMgr = (HibernateProcessMgr) qProcessMgr.uniqueResult();
1025         ((SharkHibernateTransaction)ti).read(hibProcessMgr);
1026         return hibProcessMgr;
1027
1028      } catch (Throwable JavaDoc t) {
1029         throw new PersistenceException(t);
1030      }
1031   }
1032
1033   private HibernateProcess getPersistedObject(ProcessPersistenceInterface pr, SharkTransaction ti) throws PersistenceException {
1034      try {
1035         return getPersistedProcessObject(pr.getId(), ti);
1036      } catch (Throwable JavaDoc t) {
1037         throw new PersistenceException(t);
1038      }
1039   }
1040
1041   private HibernateProcess getPersistedProcessObject(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1042      try {
1043         Session s = ((SharkHibernateTransaction) ti).getSession();
1044         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessClassName);
1045         it.hasNext();) {
1046            HibernateProcess hibProcess = (HibernateProcess)it.next();
1047            if (procId.equals(hibProcess.getId()))
1048               return hibProcess;
1049         }
1050         Query qProcess = s.createQuery("from HibernateProcess hibProcess where hibProcess.idPro = :keyValueParam");
1051         qProcess.setString("keyValueParam", procId);
1052         HibernateProcess hibProcess = (HibernateProcess) qProcess.uniqueResult();
1053         ((SharkHibernateTransaction)ti).read(hibProcess);
1054         return hibProcess;
1055      } catch (Throwable JavaDoc t) {
1056         throw new PersistenceException(t);
1057      }
1058   }
1059
1060   private HibernateProcessRequester getProcessRequester(String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
1061      HibernateProcessRequester hibProcessRequester = null;
1062      try {
1063         Session session = ((SharkHibernateTransaction)ti).getSession();
1064         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessRequesterClassName);
1065         it.hasNext();) {
1066            hibProcessRequester = (HibernateProcessRequester)it.next();
1067            if (procId.equals(hibProcessRequester.getId()))
1068               return hibProcessRequester;
1069         }
1070         Query qProcessRequester = session.createQuery("from HibernateProcessRequester processR where processR.idPro = :keyValueParam");
1071         qProcessRequester.setString("keyValueParam", procId);
1072         hibProcessRequester = (HibernateProcessRequester) qProcessRequester.uniqueResult();
1073         if (hibProcessRequester == null){
1074            hibProcessRequester = createProcessRequester();
1075         } else {
1076            ((SharkHibernateTransaction)ti).read(hibProcessRequester);
1077         }
1078         return hibProcessRequester;
1079      }
1080      catch (Throwable JavaDoc t) {
1081         throw new PersistenceException(t);
1082      }
1083   }
1084
1085   private HibernateProcessRequester getProcessRequesterByActId(String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
1086      try {
1087         if ((actId == null) || (actId.trim().equals(""))) return null;
1088         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessRequesterClassName);
1089         it.hasNext();) {
1090            HibernateProcessRequester hibProcessRequester = (HibernateProcessRequester)it.next();
1091            if (actId.equals(hibProcessRequester.getActRequester()))
1092               return hibProcessRequester;
1093         }
1094         Session s = ((SharkHibernateTransaction)ti).getSession();
1095         Query qProcessRequesterQuery = s.createQuery("from HibernateProcessRequester processRequester where processRequester.actRequester = :keyValueParam");
1096         qProcessRequesterQuery.setString("keyValueParam", actId);
1097
1098         HibernateProcessRequester hibProcessRequester = (HibernateProcessRequester) qProcessRequesterQuery.uniqueResult();
1099         ((SharkHibernateTransaction)ti).read(hibProcessRequester);
1100         return hibProcessRequester;
1101      }
1102      catch (Throwable JavaDoc t) {
1103         throw new PersistenceException(t);
1104      }
1105   }
1106
1107   private List JavaDoc getProcessRequesterByResId(String JavaDoc resId,SharkTransaction ti) throws PersistenceException {
1108      try {
1109         if ((resId == null) || (resId.trim().equals(""))) return new ArrayList JavaDoc();
1110         Session s = ((SharkHibernateTransaction)ti).getSession();
1111         Query qProcessRequesterQuery = s.createQuery("from HibernateProcessRequester processRequester where processRequester.resRequester = :keyValueParam");
1112         qProcessRequesterQuery.setString("keyValueParam", resId);
1113         List JavaDoc processRequesters = qProcessRequesterQuery.list();
1114
1115         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessRequesterClassName);
1116         it.hasNext();) {
1117            HibernateProcessRequester hibProcessRequester = (HibernateProcessRequester)it.next();
1118            if (hibProcessRequester.getResRequester().equals(resId)){
1119               int index = processRequesters.indexOf(hibProcessRequester);
1120               if (-1 == index)
1121                  processRequesters.add(hibProcessRequester);
1122               else {
1123                  processRequesters.set(index, hibProcessRequester);
1124               }
1125            }
1126         }
1127         return processRequesters;
1128         }
1129      catch (Throwable JavaDoc t) {
1130         throw new PersistenceException(t);
1131      }
1132   }
1133
1134   private HibernateActivity getPersistedObject(ActivityPersistenceInterface act, SharkTransaction ti) throws PersistenceException {
1135      try {
1136         return getPersistedActivityObject(act.getId(), ti);
1137      } catch (Throwable JavaDoc t) {
1138         throw new PersistenceException(t);
1139      }
1140   }
1141
1142   private HibernateActivity getPersistedActivityObject(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
1143      try {
1144         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
1145         it.hasNext();) {
1146            HibernateActivity hibActivity = (HibernateActivity)it.next();
1147            if (actId.equals(hibActivity.getId()))
1148               return hibActivity;
1149         }
1150         Session s = ((SharkHibernateTransaction)ti).getSession();
1151         Query qActivity = s.createQuery("from HibernateActivity activity where activity.idAct = :keyValueParam");
1152         qActivity.setString("keyValueParam", actId);
1153         HibernateActivity hibActivity = (HibernateActivity) qActivity.uniqueResult();
1154         ((SharkHibernateTransaction)ti).read(hibActivity);
1155         return hibActivity;
1156      } catch (Throwable JavaDoc t) {
1157         throw new PersistenceException(t);
1158      }
1159   }
1160
1161   private HibernateResource getPersistedObject(ResourcePersistenceInterface res, SharkTransaction ti) throws PersistenceException {
1162      try {
1163         return getPersistedResourceObject(res.getUsername(), ti);
1164      } catch (Throwable JavaDoc t) {
1165         throw new PersistenceException(t);
1166      }
1167   }
1168
1169   private HibernateResource getPersistedResourceObject(String JavaDoc username, SharkTransaction ti) throws PersistenceException {
1170      try {
1171         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateResourceClassName);
1172         it.hasNext();) {
1173            HibernateResource hibResource = (HibernateResource)it.next();
1174            if (username.equals(hibResource.getUsername()))
1175               return hibResource;
1176         }
1177         Session s = ((SharkHibernateTransaction)ti).getSession();
1178         Query qResource = s.createQuery("from HibernateResource resource where resource.username = :keyValueParam");
1179         qResource.setString("keyValueParam", username);
1180         HibernateResource hibResource = (HibernateResource) qResource.uniqueResult();
1181         ((SharkHibernateTransaction)ti).read(hibResource);
1182         return hibResource;
1183      } catch (Throwable JavaDoc t) {
1184         throw new PersistenceException(t);
1185      }
1186   }
1187
1188   private HibernateAssignment getPersistedObject(AssignmentPersistenceInterface ass, SharkTransaction ti) throws PersistenceException {
1189      try {
1190         return getPersistedAssignmentObject(ass.getActivityId(), ass.getResourceUsername(), ti);
1191      } catch (Throwable JavaDoc t) {
1192         throw new PersistenceException(t);
1193      }
1194   }
1195
1196   private HibernateAssignment getPersistedAssignmentObject(String JavaDoc actId, String JavaDoc username, SharkTransaction ti) throws PersistenceException {
1197      try {
1198         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1199         it.hasNext();) {
1200            HibernateAssignment hibAssignment = (HibernateAssignment)it.next();
1201            if (actId.equals(hibAssignment.getActivityId()) && username.equals(hibAssignment.getResourceUsername()))
1202               return hibAssignment;
1203         }
1204         Session s = ((SharkHibernateTransaction)ti).getSession();
1205         Query qAssignmentQuery = s.createQuery("from HibernateAssignment assign where assign.activityId = :keyValueParam_1 and assign.resourceUsername = :keyValueParam_2");
1206         qAssignmentQuery.setString("keyValueParam_1", actId);
1207         qAssignmentQuery.setString("keyValueParam_2", username);
1208         HibernateAssignment hibAssignment = (HibernateAssignment) qAssignmentQuery.uniqueResult();
1209         ((SharkHibernateTransaction)ti).read(hibAssignment);
1210         return hibAssignment;
1211      } catch (Throwable JavaDoc t) {
1212         throw new PersistenceException(t);
1213      }
1214   }
1215
1216   private HibernateProcessVariable getPersistedObject(ProcessVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
1217      try {
1218         return getPersistedProcessVariableObject(var.getProcessId(), var.getDefinitionId(), ti);
1219      } catch (Throwable JavaDoc t) {
1220         throw new PersistenceException(t);
1221      }
1222   }
1223
1224   private HibernateProcessVariable getPersistedProcessVariableObject(String JavaDoc procId, String JavaDoc defId, SharkTransaction ti) throws PersistenceException {
1225      try {
1226         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessVariableClassName);
1227         it.hasNext();) {
1228            HibernateProcessVariable hibProcessVariable = (HibernateProcessVariable)it.next();
1229            if ((procId.equals(hibProcessVariable.getProcessId())) && (defId.equals(hibProcessVariable.getDefinitionId()))){
1230               return hibProcessVariable;
1231            }
1232         }
1233
1234         Session s = ((SharkHibernateTransaction)ti).getSession();
1235         Query qProcessVariableQuery =
1236            s.createQuery("from HibernateProcessVariable processVariable where processVariable.processId = :keyValueParam_1 and processVariable.definitionId = :keyValueParam_2");
1237         qProcessVariableQuery.setString("keyValueParam_1", procId);
1238         qProcessVariableQuery.setString("keyValueParam_2", defId);
1239         HibernateProcessVariable hibProcessVariable = (HibernateProcessVariable) qProcessVariableQuery.uniqueResult();
1240         if (hibProcessVariable != null){
1241            ((SharkHibernateTransaction)ti).read(hibProcessVariable);
1242         } else {
1243         }
1244         return hibProcessVariable;
1245      } catch (Throwable JavaDoc t) {
1246         throw new PersistenceException(t);
1247      }
1248   }
1249
1250   private HibernateActivityVariable getPersistedObject(ActivityVariablePersistenceInterface var, SharkTransaction ti) throws PersistenceException {
1251      try {
1252         return getPersistedActivityVariableObject(var.getActivityId(), var.getDefinitionId(), ti);
1253      } catch (Throwable JavaDoc t) {
1254         throw new PersistenceException(t);
1255      }
1256   }
1257
1258   private HibernateActivityVariable getPersistedActivityVariableObject(String JavaDoc actId, String JavaDoc defId, SharkTransaction ti) throws PersistenceException {
1259      try {
1260         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityVariableClassName);
1261         it.hasNext();) {
1262            HibernateActivityVariable hibActivityVariable = (HibernateActivityVariable)it.next();
1263            if (actId.equals(hibActivityVariable.getActivityId()) && defId.equals(hibActivityVariable.getDefinitionId()))
1264               return hibActivityVariable;
1265         }
1266         Session s = ((SharkHibernateTransaction)ti).getSession();
1267         Query qActivityVariableQuery =
1268            s.createQuery("from HibernateActivityVariable activityVariable where activityVariable.activityId = :keyValueParam_1 and activityVariable.definitionId = :keyValueParam_2");
1269         qActivityVariableQuery.setString("keyValueParam_1", actId);
1270         qActivityVariableQuery.setString("keyValueParam_2", defId);
1271         HibernateActivityVariable hibActivityVariable = (HibernateActivityVariable) qActivityVariableQuery.uniqueResult();
1272         ((SharkHibernateTransaction)ti).read(hibActivityVariable);
1273         return hibActivityVariable;
1274      } catch (Throwable JavaDoc t) {
1275         throw new PersistenceException(t);
1276      }
1277   }
1278
1279   public List JavaDoc getAllRunningProcesses(SharkTransaction ti) throws PersistenceException {
1280      List JavaDoc ret=new ArrayList JavaDoc();
1281      try {
1282         List JavaDoc procs=getPersistedProcesses(ti,true);
1283         if (procs.size() != 0) {
1284            for (Iterator JavaDoc it = procs.iterator();it.hasNext();) {
1285               HibernateProcess hibPro = (HibernateProcess)it.next();
1286               ProcessPersistenceInterface proc = restore(hibPro,getProcessRequester(hibPro.getId(),ti),ti);
1287               ret.add(proc);
1288            }
1289         }
1290         return ret;
1291      } catch (Throwable JavaDoc e) {
1292         throw new PersistenceException(e);
1293      }
1294   }
1295
1296   public List JavaDoc getAllFinishedProcesses(SharkTransaction ti) throws PersistenceException {
1297      throw new PersistenceException("Not implemented yet!");
1298   }
1299
1300   public List JavaDoc getAllFinishedProcesses(SharkTransaction ti,java.util.Date JavaDoc finishedBefore) throws PersistenceException {
1301      throw new PersistenceException("Not implemented yet!");
1302   }
1303
1304   public List JavaDoc getAllFinishedProcesses(SharkTransaction ti,String JavaDoc pkgId) throws PersistenceException {
1305      throw new PersistenceException("Not implemented yet!");
1306   }
1307
1308   public List JavaDoc getAllFinishedProcesses(SharkTransaction ti,String JavaDoc pkgId,String JavaDoc procDefId) throws PersistenceException {
1309      throw new PersistenceException("Not implemented yet!");
1310   }
1311
1312   private List JavaDoc getPersistedProcesses (SharkTransaction ti,boolean onlyOpenRunning) throws PersistenceException {
1313      List JavaDoc processes = new ArrayList JavaDoc();
1314      try {
1315         Session s = ((SharkHibernateTransaction)ti).getSession();
1316         Integer JavaDoc openRunningState = null;
1317         Query qProcessesQuery = null;
1318         if (onlyOpenRunning) {
1319            openRunningState = (Integer JavaDoc)_prStates.get("open.running");
1320            qProcessesQuery = s.createQuery("from HibernateProcess process where process.stateId = :keyValueParam");
1321            qProcessesQuery.setInteger("keyValueParam", openRunningState.intValue());
1322         } else {
1323            qProcessesQuery = s.createQuery("from HibernateProcess process");
1324         }
1325
1326         processes= qProcessesQuery.list();
1327
1328         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessClassName);
1329         it.hasNext();) {
1330            HibernateProcess hibProcess = (HibernateProcess)it.next();
1331            if (onlyOpenRunning && !new Integer JavaDoc(hibProcess.getStateId()).equals(openRunningState)) continue;
1332            int index = processes.indexOf(hibProcess);
1333            if (-1 == index)
1334               processes.add(hibProcess);
1335            else {
1336               processes.set(index, hibProcess);
1337            }
1338         }
1339      return processes;
1340      }
1341      catch (Throwable JavaDoc t) {
1342         throw new PersistenceException(t);
1343      }
1344   }
1345
1346   public List JavaDoc getAllProcessesForMgr(String JavaDoc mgrName, SharkTransaction ti) throws PersistenceException {
1347      List JavaDoc ret = new ArrayList JavaDoc();
1348      try {
1349         Session session = ((SharkHibernateTransaction) ti).getSession();
1350         HibernateProcessMgr pMgr = getPersistedProcessMgrObject(mgrName, ti);
1351         if (pMgr != null) {
1352            List JavaDoc processes = getProcessesForManager(mgrName, ti);
1353
1354            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessClassName);
1355            it.hasNext();) {
1356               HibernateProcess hibProcess = (HibernateProcess)it.next();
1357               if (hibProcess.getProcessMgrName().equals(pMgr.getName())){
1358                  int index = processes.indexOf(hibProcess);
1359                  if (-1 == index)
1360                     processes.add(hibProcess);
1361                  else {
1362                     processes.set(index, hibProcess);
1363                  }
1364               }
1365            }
1366
1367            if (processes.size() != 0) {
1368               for (Iterator JavaDoc it = processes.iterator(); it.hasNext();) {
1369                  HibernateProcess pro = (HibernateProcess) it.next();
1370                  ProcessPersistenceInterface proc = restore(pro,getProcessRequester(pro.getId(),ti), ti);
1371                  ret.add(proc);
1372               }
1373            }
1374         }
1375         ((SharkHibernateTransaction)ti).read(ret);
1376         return ret;
1377      } catch (Throwable JavaDoc t) {
1378         throw new PersistenceException(t);
1379      }
1380   }
1381
1382   private List JavaDoc getProcessesForManager(String JavaDoc procDefId, SharkTransaction ti) throws PersistenceException {
1383      try {
1384         Session s = ((SharkHibernateTransaction) ti).getSession();
1385
1386         Query qProcessesQuery = s.createQuery("from HibernateProcess process where process.managerName = :keyValueParam_1");
1387         qProcessesQuery.setString("keyValueParam_1", procDefId);
1388         List JavaDoc processes = qProcessesQuery.list();
1389
1390         return processes;
1391      } catch (Throwable JavaDoc t) {
1392         throw new PersistenceException(t);
1393      }
1394   }
1395
1396   private List JavaDoc getActivitiesForBlockActivity(String JavaDoc blockActId, SharkTransaction ti) throws PersistenceException {
1397      try {
1398         Session s = ((SharkHibernateTransaction) ti).getSession();
1399         Query qActivitiesQuery = s.createQuery("from HibernateActivity activity where activity.blockActivityId = :keyValueParam_1");
1400         qActivitiesQuery.setString("keyValueParam_1", blockActId);
1401         List JavaDoc activities = qActivitiesQuery.list();
1402
1403         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
1404         it.hasNext();) {
1405            HibernateActivity hibActivity = (HibernateActivity)it.next();
1406            int index = activities.indexOf(hibActivity);
1407            if (blockActId.equals(hibActivity.getBlockActivityId())){
1408               if (-1 == index){
1409                  activities.add(hibActivity);
1410               } else {
1411                  activities.set(index, hibActivity);
1412               }
1413            }
1414         }
1415         ((SharkHibernateTransaction)ti).read(activities);
1416         return activities;
1417      } catch (Throwable JavaDoc t) {
1418         t.printStackTrace();
1419         throw new PersistenceException(t);
1420      }
1421   }
1422
1423   private List JavaDoc getProcessesForActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
1424      try {
1425         Session s = ((SharkHibernateTransaction) ti).getSession();
1426         String JavaDoc processId = null;
1427
1428         HibernateProcessRequester proRequester = getProcessRequesterByActId(actId,ti);
1429         if (proRequester != null){
1430            processId = proRequester.getId();
1431         } else {
1432            return new ArrayList JavaDoc();
1433         }
1434         Query qProcessesQuery = s.createQuery("from HibernateProcess process where process.idPro = :keyValueParam_1");
1435         qProcessesQuery.setString("keyValueParam_1", processId);
1436         List JavaDoc processes = qProcessesQuery.list();
1437
1438         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessClassName);
1439         it.hasNext();) {
1440            HibernateProcess hibProcess = (HibernateProcess)it.next();
1441            int index = processes.indexOf(hibProcess);
1442            if (processId.equals(hibProcess.getId())){
1443               if (-1 == index)
1444                  processes.add(hibProcess);
1445               else {
1446                  processes.set(index, hibProcess);
1447               }
1448            }
1449         }
1450         return processes;
1451      } catch (Throwable JavaDoc t) {
1452         throw new PersistenceException(t);
1453      }
1454   }
1455
1456   private List JavaDoc getPersistedAndJoinEntriesForProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1457      try {
1458         Session s = ((SharkHibernateTransaction) ti).getSession();
1459
1460         Query qAndJoinEntryQuery = s.createQuery("from HibernateAndJoinEntry aje where aje.processId = :keyValueParam_1");
1461         qAndJoinEntryQuery.setString("keyValueParam_1", procId);
1462         List JavaDoc ajes = qAndJoinEntryQuery.list();
1463
1464         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAndJoinEntryClassName);
1465         it.hasNext();) {
1466            HibernateAndJoinEntry hibAndJoinEntry = (HibernateAndJoinEntry)it.next();
1467            int index = ajes.indexOf(hibAndJoinEntry);
1468            if (procId.equals(hibAndJoinEntry.getProcessId())){
1469               if (-1 == index)
1470                  ajes.add(hibAndJoinEntry);
1471               else {
1472                  ajes.set(index, hibAndJoinEntry);
1473               }
1474            }
1475         }
1476         ((SharkHibernateTransaction)ti).read(ajes);
1477         return ajes;
1478      } catch (Throwable JavaDoc t) {
1479         throw new PersistenceException(t);
1480      }
1481   }
1482
1483   private List JavaDoc getPersistedAndJoinEntriesForActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
1484      try {
1485         Session s = ((SharkHibernateTransaction) ti).getSession();
1486
1487         Query qAndJoinEntryQuery = s.createQuery("from HibernateAndJoinEntry aje where aje.activityId = :keyValueParam_1");
1488         qAndJoinEntryQuery.setString("keyValueParam_1", actId);
1489         List JavaDoc ajes = qAndJoinEntryQuery.list();
1490
1491         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAndJoinEntryClassName);
1492         it.hasNext();) {
1493            HibernateAndJoinEntry hibAndJoinEntry = (HibernateAndJoinEntry)it.next();
1494            int index = ajes.indexOf(hibAndJoinEntry);
1495            if (actId.equals(hibAndJoinEntry.getActivityId())){
1496               if (-1 == index)
1497                  ajes.add(hibAndJoinEntry);
1498               else {
1499                  ajes.set(index, hibAndJoinEntry);
1500               }
1501            }
1502         }
1503         ((SharkHibernateTransaction)ti).read(ajes);
1504         return ajes;
1505      } catch (Throwable JavaDoc t) {
1506         throw new PersistenceException(t);
1507      }
1508   }
1509
1510   private List JavaDoc getPersistedAndJoinEntries(String JavaDoc procId, String JavaDoc asDefId, String JavaDoc aDefId, SharkTransaction ti) throws PersistenceException {
1511      try {
1512         Session s = ((SharkHibernateTransaction) ti).getSession();
1513
1514         Query qAndJoinEntryQuery = s.createQuery("from HibernateAndJoinEntry aje where aje.processId = :keyValueParam_1 and "
1515               + "aje.activityDefinitionId = :keyValueParam_2"
1516               + " and aje.activitySetDefinitionId = :keyValueParam_3");
1517         qAndJoinEntryQuery.setString("keyValueParam_1", procId);
1518         qAndJoinEntryQuery.setString("keyValueParam_2", aDefId);
1519         qAndJoinEntryQuery.setString("keyValueParam_3", asDefId);
1520         List JavaDoc ajes = qAndJoinEntryQuery.list();
1521
1522         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAndJoinEntryClassName);
1523         it.hasNext();) {
1524            HibernateAndJoinEntry hibAndJoinEntry = (HibernateAndJoinEntry)it.next();
1525            int index = ajes.indexOf(hibAndJoinEntry);
1526            if (procId.equals(hibAndJoinEntry.getProcessId()) &&
1527                  aDefId.equals(hibAndJoinEntry.getActivityDefinitionId()) &&
1528                  asDefId.equals(hibAndJoinEntry.getActivitySetDefinitionId())){
1529               if (-1 == index)
1530                  ajes.add(hibAndJoinEntry);
1531               else {
1532                  ajes.set(index, hibAndJoinEntry);
1533               }
1534            }
1535         }
1536         ((SharkHibernateTransaction)ti).read(ajes);
1537         return ajes;
1538      } catch (Throwable JavaDoc t) {
1539         throw new PersistenceException(t);
1540      }
1541   }
1542
1543   public List JavaDoc getAllProcessMgrs(SharkTransaction ti) throws PersistenceException {
1544      try {
1545         return getAllPersistedProcessMgrs(ti);
1546      } catch (Throwable JavaDoc tr) {
1547         cus.error(LOG_CHANNEL, "Restoring of all process definition failed");
1548         throw new PersistenceException("Restoring of all process definition failed", tr);
1549      }
1550   }
1551
1552   private List JavaDoc getAllPersistedProcessMgrs(SharkTransaction ti) throws PersistenceException {
1553      try {
1554         Session s = ((SharkHibernateTransaction) ti).getSession();
1555         Query qProcessDefinitionsQuery = s.createQuery("from HibernateProcessMgr processMgr");
1556         List JavaDoc processMgrs = qProcessDefinitionsQuery.list();
1557
1558         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessMgrClassName);
1559         it.hasNext();) {
1560            HibernateProcessMgr hibProcessMgr = (HibernateProcessMgr)it.next();
1561            int index = processMgrs.indexOf(hibProcessMgr);
1562            if (-1 == index)
1563               processMgrs.add(hibProcessMgr);
1564            else {
1565               processMgrs.set(index, hibProcessMgr);
1566            }
1567         }
1568         ((SharkHibernateTransaction)ti).read(processMgrs);
1569         return processMgrs;
1570      } catch (Throwable JavaDoc t) {
1571         throw new PersistenceException(t);
1572      }
1573   }
1574
1575   public List JavaDoc getAllProcesses(SharkTransaction ti) throws PersistenceException {
1576      List JavaDoc processes = new ArrayList JavaDoc();
1577      List JavaDoc processesRestored = new ArrayList JavaDoc();
1578      try {
1579         Session session = ((SharkHibernateTransaction) ti).getSession();
1580         processes = getAllPersistedProcesses(ti);
1581         if (processes.size() != 0) {
1582            for (Iterator JavaDoc it = processes.iterator(); it.hasNext();) {
1583               HibernateProcess pro = (HibernateProcess) it.next();
1584               ProcessPersistenceInterface proc = restore(pro,getProcessRequester(pro.getId(),ti), ti);
1585               processesRestored.add(proc);
1586            }
1587         }
1588         ((SharkHibernateTransaction)ti).read(processesRestored);
1589         return processesRestored;
1590
1591      } catch (Throwable JavaDoc tr) {
1592         cus.error(LOG_CHANNEL, "Restoring of all processes definition failed");
1593         throw new PersistenceException("Restoring of all processes definition failed", tr);
1594      }
1595   }
1596
1597   private List JavaDoc getAllPersistedProcesses(SharkTransaction ti) throws PersistenceException {
1598      try {
1599         Session s = ((SharkHibernateTransaction) ti).getSession();
1600         List JavaDoc processes = s.createQuery("from HibernateProcess process").list();
1601
1602         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessClassName);
1603         it.hasNext();) {
1604            HibernateProcess hibProcess = (HibernateProcess)it.next();
1605            int index = processes.indexOf(hibProcess);
1606            if (-1 == index)
1607               processes.add(hibProcess);
1608            else {
1609               processes.set(index, hibProcess);
1610            }
1611         }
1612         return processes;
1613      } catch (Throwable JavaDoc t) {
1614         throw new PersistenceException(t);
1615      }
1616   }
1617
1618   public List JavaDoc getAllActivities(SharkTransaction ti) throws PersistenceException {
1619      List JavaDoc activities = new ArrayList JavaDoc();
1620      List JavaDoc activitiesRestored = new ArrayList JavaDoc();
1621      try {
1622         activities = getAllPersistedActivities(ti);
1623         if (activities.size() != 0) {
1624            for (Iterator JavaDoc it = activities.iterator(); it.hasNext();) {
1625               ActivityPersistenceInterface act = restore((HibernateActivity) it.next(), ti);
1626               activitiesRestored.add(act);
1627            }
1628         }
1629         ((SharkHibernateTransaction)ti).read(activitiesRestored);
1630         return activitiesRestored;
1631
1632      } catch (Throwable JavaDoc tr) {
1633         cus.error(LOG_CHANNEL, "Restoring of all activities failed");
1634         throw new PersistenceException("Restoring of all activities failed", tr);
1635      }
1636   }
1637
1638   private List JavaDoc getAllPersistedActivities(SharkTransaction ti) throws PersistenceException {
1639      try {
1640         Session s = ((SharkHibernateTransaction) ti).getSession();
1641         List JavaDoc activities = s.createQuery("from HibernateActivity activity").list();
1642
1643         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
1644         it.hasNext();) {
1645            HibernateActivity hibActivity = (HibernateActivity)it.next();
1646            int index = activities.indexOf(hibActivity);
1647            if (-1 == index)
1648               activities.add(hibActivity);
1649            else {
1650               activities.set(index, hibActivity);
1651            }
1652         }
1653         return activities;
1654
1655      } catch (Throwable JavaDoc t) {
1656         throw new PersistenceException(t);
1657      }
1658   }
1659
1660   public List JavaDoc getAllResources(SharkTransaction ti) throws PersistenceException {
1661      try {
1662         return getAllPersistedResources(ti);
1663      } catch (Throwable JavaDoc tr) {
1664         cus.error(LOG_CHANNEL, "Restoring of all resources failed");
1665         throw new PersistenceException("Restoring of all resources failed", tr);
1666      }
1667   }
1668
1669   private List JavaDoc getAllPersistedResources(SharkTransaction ti) throws PersistenceException {
1670      try {
1671         Session s = ((SharkHibernateTransaction) ti).getSession();
1672         List JavaDoc resources = s.createQuery("from HibernateResource resource").list();
1673
1674         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateResourceClassName);
1675         it.hasNext();) {
1676            HibernateResource hibResource = (HibernateResource)it.next();
1677            int index = resources.indexOf(hibResource);
1678            if (-1 == index)
1679               resources.add(hibResource);
1680            else {
1681               resources.set(index, hibResource);
1682            }
1683         }
1684         ((SharkHibernateTransaction)ti).read(resources);
1685         return resources;
1686      } catch (Throwable JavaDoc t) {
1687         throw new PersistenceException(t);
1688      }
1689   }
1690
1691   public List JavaDoc getAllAssignments(SharkTransaction ti) throws PersistenceException {
1692      List JavaDoc assignments = new ArrayList JavaDoc();
1693      List JavaDoc assignmentsRestored = new ArrayList JavaDoc();
1694      try {
1695         assignments = getAllPersistedAssignments(ti);
1696         if (assignments.size() != 0) {
1697            for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
1698               AssignmentPersistenceInterface assign = restore((HibernateAssignment) it.next(), ti);
1699               assignmentsRestored.add(assign);
1700            }
1701         }
1702         ((SharkHibernateTransaction)ti).read(assignmentsRestored);
1703         return assignmentsRestored;
1704
1705      } catch (Throwable JavaDoc tr) {
1706         cus.error(LOG_CHANNEL, "Restoring of all assignments failed");
1707         throw new PersistenceException("Restoring of all assignments failed", tr);
1708      }
1709   }
1710
1711   private List JavaDoc getAllPersistedAssignments(SharkTransaction ti) throws PersistenceException {
1712      try {
1713         Session s = ((SharkHibernateTransaction) ti).getSession();
1714         List JavaDoc assignments = s.createQuery("from HibernateAssignment assignment").list();
1715         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1716         it.hasNext();) {
1717            HibernateAssignment hibAssignment = (HibernateAssignment)it.next();
1718            int index = assignments.indexOf(hibAssignment);
1719            if (-1 == index)
1720               assignments.add(hibAssignment);
1721            else {
1722               assignments.set(index, hibAssignment);
1723            }
1724         }
1725         return assignments;
1726      } catch (Throwable JavaDoc t) {
1727         throw new PersistenceException(t);
1728      }
1729   }
1730
1731   public List JavaDoc getAllActivitiesForProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1732      List JavaDoc ret = new ArrayList JavaDoc();
1733      try {
1734         Session session = ((SharkHibernateTransaction) ti).getSession();
1735         HibernateProcess pro = getPersistedProcessObject(procId, ti);
1736         if (pro != null) {
1737            List JavaDoc activities = getActivities(procId, ti);
1738
1739            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
1740            it.hasNext();) {
1741               HibernateActivity hibActivity = (HibernateActivity)it.next();
1742               if (hibActivity.getProcessId().equals(procId)){
1743                  int index = activities.indexOf(hibActivity);
1744                  if (-1 == index)
1745                     activities.add(hibActivity);
1746                  else {
1747                     activities.set(index, hibActivity);
1748                  }
1749               }
1750            }
1751            if (activities.size() != 0) {
1752               for (Iterator JavaDoc it = activities.iterator(); it.hasNext();) {
1753                  ActivityPersistenceInterface act = restore((HibernateActivity) it.next(), ti);
1754                  ret.add(act);
1755               }
1756            }
1757            ((SharkHibernateTransaction)ti).read(ret);
1758         }
1759         return ret;
1760      } catch (Throwable JavaDoc t) {
1761         throw new PersistenceException(t);
1762      }
1763   }
1764
1765   public List JavaDoc getAllFinishedActivitiesForProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1766      throw new PersistenceException("Not implemented yet!");
1767   }
1768
1769   public List JavaDoc getAllActiveActivitiesForProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1770      throw new PersistenceException("Not implemented yet!");
1771   }
1772
1773   private List JavaDoc getActivities(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
1774      try {
1775         Session s = ((SharkHibernateTransaction) ti).getSession();
1776
1777         Query qActivitiesQuery = s.createQuery("from HibernateActivity activity where activity.processId = :keyValueParam_1");
1778         qActivitiesQuery.setString("keyValueParam_1", procId);
1779         List JavaDoc activities = qActivitiesQuery.list();
1780
1781         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
1782         it.hasNext();) {
1783            HibernateActivity hibActivity = (HibernateActivity)it.next();
1784            if (hibActivity.getProcessId().equals(procId)){
1785               int index = activities.indexOf(hibActivity);
1786               if (-1 == index)
1787                  activities.add(hibActivity);
1788               else {
1789                  activities.set(index, hibActivity);
1790               }
1791            }
1792         }
1793         return activities;
1794      } catch (Throwable JavaDoc t) {
1795         throw new PersistenceException(t);
1796      }
1797   }
1798
1799   /**
1800     * Returns all assignments for the resource, no matter if its activity
1801     * is in "closed" state (or some of its sub-states).
1802     */

1803   public List JavaDoc getAllAssignmentsForResource(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
1804      List JavaDoc ret = new ArrayList JavaDoc();
1805      try {
1806         Session session = ((SharkHibernateTransaction) ti).getSession();
1807         //restore all assignments
1808
HibernateResource res = getPersistedResourceObject(resUsername, ti);
1809         if (res != null) {
1810            List JavaDoc assignments = getAssignmentsOnUsername(resUsername, session);
1811
1812            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1813            it.hasNext();) {
1814               HibernateAssignment hibAssign = (HibernateAssignment)it.next();
1815               if (hibAssign.getResourceUsername().equals(res.getUsername())){
1816                  int index = assignments.indexOf(hibAssign);
1817                  if (-1 == index)
1818                     assignments.add(hibAssign);
1819                  else {
1820                     assignments.set(index, hibAssign);
1821                  }
1822               }
1823            }
1824            if (assignments.size() != 0) {
1825               for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
1826                  HibernateAssignment assign = (HibernateAssignment) it.next();
1827                  ret.add(restore(assign, ti));
1828               }
1829            }
1830         }
1831         ((SharkHibernateTransaction)ti).read(ret);
1832         return ret;
1833      } catch (Throwable JavaDoc t) {
1834         throw new PersistenceException(t);
1835      }
1836   }
1837
1838   /**
1839      * Returns all assignments which activity is not in "closed" state, or some
1840      * of its sub-states.
1841      */

1842   public List JavaDoc getAllAssignmentsForNotClosedActivitiesForResource(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
1843      List JavaDoc ret = new ArrayList JavaDoc();
1844      try {
1845         Session session = ((SharkHibernateTransaction) ti).getSession();
1846         HibernateResource res = getPersistedResourceObject(resUsername, ti);
1847         if (res != null) {
1848            List JavaDoc assignments = getAssignmentsOnUsername(resUsername, session);
1849
1850            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1851            it.hasNext();) {
1852               HibernateAssignment hibAssign = (HibernateAssignment)it.next();
1853               if (hibAssign.getResourceUsername().equals(res.getUsername())){
1854                  int index = assignments.indexOf(hibAssign);
1855                  if (-1 == index)
1856                     assignments.add(hibAssign);
1857                  else {
1858                     assignments.set(index, hibAssign);
1859                  }
1860               }
1861            }
1862            if (assignments.size() != 0) {
1863               for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
1864                  HibernateAssignment assign = (HibernateAssignment) it.next();
1865                  HibernateActivity act = (HibernateActivity) restore(getPersistedActivityObject(assign.getActivityId(), ti), ti);
1866                  String JavaDoc state = act.getState();
1867                  // restore assignment
1868
if (!state.startsWith("closed")) {
1869                     ret.add(restore(assign, ti));
1870                  }
1871               }
1872            }
1873         }
1874         ((SharkHibernateTransaction)ti).read(ret);
1875         return ret;
1876      } catch (Throwable JavaDoc t) {
1877         throw new PersistenceException(t);
1878      }
1879   }
1880
1881   /**
1882        * Returns only the assignments that can be currently executed by the resource
1883        * with a given username. This means the ones which activity is not finished
1884        * and not accepted (it doesn't have TheResource field set), and the ones
1885        * which activity is accepted by this resource (its TheResource field is set
1886        * to the resource with given username).
1887        */

1888   public List JavaDoc getAllValidAssignmentsForResource(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
1889      List JavaDoc ret = new ArrayList JavaDoc();
1890      try {
1891         Session session = ((SharkHibernateTransaction) ti).getSession();
1892         //restore all assignments
1893
HibernateResource res = getPersistedResourceObject(resUsername, ti);
1894         if (res != null) {
1895            List JavaDoc assignments = getAssignmentsOnUsername(resUsername, session);
1896
1897            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1898            it.hasNext();) {
1899               HibernateAssignment hibAssign = (HibernateAssignment)it.next();
1900               if (hibAssign.getResourceUsername().equals(res.getUsername())){
1901                  int index = assignments.indexOf(hibAssign);
1902                  if (-1 == index)
1903                     assignments.add(hibAssign);
1904                  else {
1905                     assignments.set(index, hibAssign);
1906                  }
1907               }
1908            }
1909
1910            if (assignments.size() != 0) {
1911               for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
1912                  HibernateAssignment assign = (HibernateAssignment) it.next();
1913                  if (assign.getActivityId() == null) {
1914                     System.out.println("Activity for assignment [" + assign.toString() + "] is null");
1915                  }
1916                  HibernateActivity act = (HibernateActivity) restore(getPersistedActivityObject(assign.getActivityId(), ti), ti);
1917                  HibernateResource resAct = null;
1918                  if (act.getResourceUsername() != null)
1919                     resAct = getPersistedResourceObject(act.getResourceUsername(), ti);
1920                  String JavaDoc state = act.getState();
1921                  // restore assignment
1922
if (!state.startsWith("closed") && (resAct == null || res.equals(resAct))) {
1923                     ret.add(restore(assign, ti));
1924                  }
1925               }
1926            }
1927         }
1928         ((SharkHibernateTransaction)ti).read(ret);
1929         return ret;
1930      } catch (Throwable JavaDoc t) {
1931         throw new PersistenceException(t);
1932      }
1933   }
1934
1935   private List JavaDoc getAssignmentsOnUsername(String JavaDoc username, Session s) throws PersistenceException {
1936      try {
1937         //Do not need to query the cache because the methods that called this one do it
1938
Query qAssignmentsQuery = s.createQuery("from HibernateAssignment assignment where assignment.resourceUsername = :keyValueParam_1");
1939         qAssignmentsQuery.setString("keyValueParam_1", username);
1940         return qAssignmentsQuery.list();
1941      } catch (Throwable JavaDoc t) {
1942         throw new PersistenceException(t);
1943      }
1944   }
1945
1946   /**
1947      * Returns all assignments that are ever created for that activity, no
1948      * matter if activity is already in "closed" state or some of its sub-states.
1949      */

1950   public List JavaDoc getAllAssignmentsForActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
1951      List JavaDoc ret = new ArrayList JavaDoc();
1952      try {
1953         Session session = ((SharkHibernateTransaction) ti).getSession();
1954         // restore assignments
1955
HibernateActivity act = (HibernateActivity) restore(getPersistedActivityObject(actId, ti), ti);
1956         if (act != null) {
1957            List JavaDoc assignments = getAssignmentsOnActivity(actId, ti);
1958
1959            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
1960            it.hasNext();) {
1961               HibernateAssignment hibAssign = (HibernateAssignment)it.next();
1962               if (hibAssign.getActivityId().equals(act.getId())){
1963                  int index = assignments.indexOf(hibAssign);
1964                  if (-1 == index)
1965                     assignments.add(hibAssign);
1966                  else {
1967                     assignments.set(index, hibAssign);
1968                  }
1969               }
1970            }
1971
1972            if (assignments.size() != 0) {
1973               for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
1974                  ret.add(restore((HibernateAssignment) it.next(), ti));
1975               }
1976            }
1977         }
1978         ((SharkHibernateTransaction)ti).read(ret);
1979         return ret;
1980      } catch (Throwable JavaDoc t) {
1981         throw new PersistenceException(t);
1982      }
1983   }
1984
1985   /**
1986      * If activity is in "closed" state, or some of its sub-states, returns an
1987      * empty list, otherwise returns all assignments that are ever created for
1988      * that activity.
1989      */

1990   public List JavaDoc getAllAssignmentsForNotClosedActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
1991      List JavaDoc ret = new ArrayList JavaDoc();
1992      try {
1993         Session session = ((SharkHibernateTransaction) ti).getSession();
1994         // restore assignments
1995
HibernateActivity act = (HibernateActivity) restore(getPersistedActivityObject(actId, ti), ti);
1996         if (act != null) {
1997            String JavaDoc actState = act.getState();
1998            if (!actState.startsWith("closed")) {
1999               List JavaDoc assignments = getAssignmentsOnActivity(actId, ti);
2000
2001               for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
2002               it.hasNext();) {
2003                  HibernateAssignment hibAssign = (HibernateAssignment)it.next();
2004                  if (hibAssign.getActivityId().equals(act.getId())){
2005                     int index = assignments.indexOf(hibAssign);
2006                     if (-1 == index)
2007                        assignments.add(hibAssign);
2008                     else {
2009                        assignments.set(index, hibAssign);
2010                     }
2011                  }
2012               }
2013
2014               if (assignments.size() != 0) {
2015                  for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
2016                     ret.add(restore((HibernateAssignment) it.next(), ti));
2017                  }
2018               }
2019            }
2020         }
2021         ((SharkHibernateTransaction)ti).read(ret);
2022         return ret;
2023      } catch (Throwable JavaDoc t) {
2024         throw new PersistenceException(t);
2025      }
2026   }
2027
2028   /**
2029    * If activity is in "closed" state, or some of its sub-states, returns an
2030    * empty list, otherwise it returns either all assignments that are ever
2031    * created for that activity if activity is not accepted, or just the
2032    * assignment for the resource that accepted activity.
2033    */

2034   public List JavaDoc getAllValidAssignmentsForActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
2035      List JavaDoc ret = new ArrayList JavaDoc();
2036      try {
2037         Session session = ((SharkHibernateTransaction) ti).getSession();
2038         HibernateActivity act = (HibernateActivity) restore(getPersistedActivityObject(actId, ti), ti);
2039         HibernateResource resAct = null;
2040         if (act.getResourceUsername() != null)
2041            resAct = getPersistedResourceObject(act.getResourceUsername(), ti);
2042         if (act != null) {
2043            String JavaDoc actState = act.getState();
2044            if (!actState.startsWith("closed")) {
2045               List JavaDoc assignments = getAssignmentsOnActivity(actId, ti);
2046
2047               for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
2048               it.hasNext();) {
2049                  HibernateAssignment hibAssign = (HibernateAssignment)it.next();
2050                  if (hibAssign.getActivityId().equals(actId)){
2051                     int index = assignments.indexOf(hibAssign);
2052                     if (-1 == index)
2053                        assignments.add(hibAssign);
2054                     else {
2055                        assignments.set(index, hibAssign);
2056                     }
2057                  }
2058               }
2059
2060               if (assignments.size() != 0) {
2061                  for (Iterator JavaDoc it = assignments.iterator(); it.hasNext();) {
2062                     HibernateAssignment assign = (HibernateAssignment) it.next();
2063                     HibernateResource resAssign = getPersistedResourceObject(assign.getResourceUsername(), ti);
2064                     if (resAct == null || resAct.equals(resAssign)) {
2065                        ret.add(restore(assign, ti));
2066                     }
2067                  }
2068               }
2069            }
2070         }
2071         ((SharkHibernateTransaction)ti).read(ret);
2072         return ret;
2073      } catch (Throwable JavaDoc t) {
2074         throw new PersistenceException(t);
2075      }
2076   }
2077
2078   private List JavaDoc getAssignmentsOnActivity(String JavaDoc activityId, SharkTransaction ti) throws PersistenceException {
2079      try {
2080         //need to query the cache because this method is also called from deleteProcess
2081
Session s = ((SharkHibernateTransaction) ti).getSession();
2082
2083         Query qAssignmentsQuery = s.createQuery("from HibernateAssignment assignment where assignment.activityId = :keyValueParam_1");
2084         qAssignmentsQuery.setString("keyValueParam_1", activityId);
2085         List JavaDoc assignments = qAssignmentsQuery.list();
2086
2087         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateAssignmentClassName);
2088         it.hasNext();) {
2089            HibernateAssignment hibAssign = (HibernateAssignment)it.next();
2090            if (activityId.equals(hibAssign.getActivityId())){
2091               int index = assignments.indexOf(hibAssign);
2092               if (-1 == index)
2093                  assignments.add(hibAssign);
2094               else {
2095                  assignments.set(index, hibAssign);
2096               }
2097            }
2098         }
2099         return assignments;
2100      } catch (Throwable JavaDoc t) {
2101         throw new PersistenceException(t);
2102      }
2103   }
2104
2105   public List JavaDoc getAllVariablesForProcess(String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
2106      List JavaDoc ret = new ArrayList JavaDoc();
2107      try {
2108         Session session = ((SharkHibernateTransaction) ti).getSession();
2109         HibernateProcess pro = getPersistedProcessObject(procId, ti);
2110         if (pro != null) {
2111            List JavaDoc processVariables = getProcessVariablesOnProcess(procId, ti);
2112
2113            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessVariableClassName);
2114            it.hasNext();) {
2115               HibernateProcessVariable hibProcessVariable = (HibernateProcessVariable)it.next();
2116               if (hibProcessVariable.getProcessId().equals(pro.getId())){
2117                  int index = processVariables.indexOf(hibProcessVariable);
2118                  if (-1 == index)
2119                     processVariables.add(hibProcessVariable);
2120                  else {
2121                     processVariables.set(index, hibProcessVariable);
2122                  }
2123               }
2124            }
2125            if (processVariables.size() != 0) {
2126               for (Iterator JavaDoc it = processVariables.iterator(); it.hasNext();) {
2127                  HibernateProcessVariable proVar = (HibernateProcessVariable) it.next();
2128                  ProcessVariablePersistenceInterface var = createProcessVariable();
2129                  ((HibernateProcessVariable)var).setDbId(proVar.getDbId());
2130                  // restore objects
2131
restore(var, proVar, session);
2132                  ret.add(var);
2133               }
2134            }
2135            ((SharkHibernateTransaction)ti).read(ret);
2136         }
2137         return ret;
2138      } catch (Throwable JavaDoc t) {
2139         throw new PersistenceException(t);
2140      }
2141   }
2142
2143   private List JavaDoc getProcessVariablesOnProcess(String JavaDoc processId, SharkTransaction ti) throws PersistenceException {
2144      try {
2145         //need to query the cache because this method is also called from deleteProcess
2146
Session s = ((SharkHibernateTransaction) ti).getSession();
2147
2148         Query qProcessVariablesQuery = s.createQuery("from HibernateProcessVariable proVariable where proVariable.processId = :keyValueParam_1");
2149         qProcessVariablesQuery.setString("keyValueParam_1", processId);
2150         List JavaDoc processVariables = qProcessVariablesQuery.list();
2151
2152         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessVariableClassName);
2153         it.hasNext();) {
2154            HibernateProcessVariable hibProcessVariable = (HibernateProcessVariable)it.next();
2155            if (processId.equals(hibProcessVariable.getProcessId())){
2156               int index = processVariables.indexOf(hibProcessVariable);
2157               if (-1 == index)
2158                  processVariables.add(hibProcessVariable);
2159               else {
2160                  processVariables.set(index, hibProcessVariable);
2161               }
2162            }
2163         }
2164         return processVariables;
2165      } catch (Throwable JavaDoc t) {
2166         throw new PersistenceException(t);
2167      }
2168   }
2169
2170   public List JavaDoc getAllVariablesForActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
2171      List JavaDoc ret = new ArrayList JavaDoc();
2172      try {
2173         Session session = ((SharkHibernateTransaction) ti).getSession();
2174         HibernateActivity act = getPersistedActivityObject(actId, ti);
2175         if (act != null) {
2176            List JavaDoc activityVariables = getActivityVariablesOnActivity(actId, ti);
2177
2178            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityVariableClassName);
2179            it.hasNext();) {
2180               HibernateActivityVariable hibActivityVariable = (HibernateActivityVariable)it.next();
2181               if (hibActivityVariable.getActivityId().equals(act.getId())){
2182                  int index = activityVariables.indexOf(hibActivityVariable);
2183                  if (-1 == index)
2184                     activityVariables.add(hibActivityVariable);
2185                  else {
2186                     activityVariables.set(index, hibActivityVariable);
2187                  }
2188               }
2189            }
2190            if (activityVariables.size() != 0) {
2191               for (Iterator JavaDoc it = activityVariables.iterator(); it.hasNext();) {
2192                  ActivityVariablePersistenceInterface var = createActivityVariable();
2193                  HibernateActivityVariable actVar = (HibernateActivityVariable) it.next();
2194                  ((HibernateActivityVariable)var).setDbId(actVar.getDbId());
2195                  // restore objects
2196
restore(var, actVar, session);
2197                  ret.add(var);
2198               }
2199            }
2200            ((SharkHibernateTransaction)ti).read(ret);
2201         }
2202         return ret;
2203      } catch (Throwable JavaDoc t) {
2204         throw new PersistenceException(t);
2205      }
2206   }
2207
2208   private List JavaDoc getActivityVariablesOnActivity(String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
2209      try {
2210         Session s = ((SharkHibernateTransaction) ti).getSession();
2211
2212         Query qActivityVariablesQuery = s.createQuery("from HibernateActivityVariable actVariable where actVariable.activityId = :keyValueParam_1");
2213         qActivityVariablesQuery.setString("keyValueParam_1", actId);
2214         List JavaDoc activityVariables = qActivityVariablesQuery.list();
2215
2216         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityVariableClassName);
2217         it.hasNext();) {
2218            HibernateActivityVariable hibActivityVariable = (HibernateActivityVariable)it.next();
2219            if (actId.equals(hibActivityVariable.getActivityId())){
2220               int index = activityVariables.indexOf(hibActivityVariable);
2221               if (-1 == index)
2222                  activityVariables.add(hibActivityVariable);
2223               else {
2224                  activityVariables.set(index, hibActivityVariable);
2225               }
2226            }
2227         }
2228         return activityVariables;
2229      } catch (Throwable JavaDoc t) {
2230         throw new PersistenceException(t);
2231      }
2232   }
2233
2234   public List JavaDoc getResourceRequestersProcessIds(String JavaDoc resUsername, SharkTransaction ti) throws PersistenceException {
2235      List JavaDoc ret = new ArrayList JavaDoc();
2236      try {
2237         HibernateResource res = getPersistedResourceObject(resUsername, ti);
2238         if (res != null) {
2239            List JavaDoc processRequesters = getProcessRequesterByResId(resUsername,ti);
2240
2241            for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateProcessRequesterClassName);
2242            it.hasNext();) {
2243               HibernateProcessRequester hibProcessRequester = (HibernateProcessRequester)it.next();
2244               if (hibProcessRequester.getResRequester().equals(res.getUsername())){
2245                  int index = processRequesters.indexOf(hibProcessRequester);
2246                  if (-1 == index)
2247                     processRequesters.add(hibProcessRequester);
2248                  else {
2249                     processRequesters.set(index, hibProcessRequester);
2250                  }
2251               }
2252            }
2253
2254            for (Iterator JavaDoc it = processRequesters.iterator(); it.hasNext();) {
2255               ret.add(((HibernateProcessRequester) it.next()).getId());
2256            }
2257         }
2258         ((SharkHibernateTransaction)ti).read(ret);
2259         return ret;
2260      } catch (Throwable JavaDoc t) {
2261         throw new PersistenceException(t);
2262      }
2263   }
2264
2265   public List JavaDoc getAndJoinEntries(String JavaDoc procId, String JavaDoc asDefId, String JavaDoc aDefId, SharkTransaction ti) throws PersistenceException {
2266      List JavaDoc ret = new ArrayList JavaDoc();
2267      try {
2268         Session session = ((SharkHibernateTransaction) ti).getSession();
2269         List JavaDoc andJoinEntries = getPersistedAndJoinEntries(procId, asDefId, aDefId, ti);
2270         if (andJoinEntries.size() != 0) {
2271            for (Iterator JavaDoc it = andJoinEntries.iterator(); it.hasNext();) {
2272               AndJoinEntryInterface aje = createAndJoinEntry();
2273               // restore objects
2274
HibernateAndJoinEntry hibAje = (HibernateAndJoinEntry) it.next();
2275               ((HibernateAndJoinEntry)aje).setDbId(hibAje.getDbId());
2276               restore(aje, hibAje, session);
2277               ((SharkHibernateTransaction)ti).read(hibAje);
2278               ret.add(aje);
2279            }
2280         }
2281         ((SharkHibernateTransaction)ti).read(ret);
2282         return ret;
2283      } catch (Throwable JavaDoc t) {
2284         throw new PersistenceException(t);
2285      }
2286   }
2287
2288   public List JavaDoc getAllDeadlinesForProcess (String JavaDoc procId, SharkTransaction ti) throws PersistenceException {
2289      List JavaDoc ret=new ArrayList JavaDoc();
2290      try {
2291         List JavaDoc deadlines = getPersistedDeadlines(procId,-1,ti);
2292         if (deadlines.size() != 0) {
2293            for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
2294               HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2295               DeadlinePersistenceInterface dl = createDeadline();
2296               // restore Deadline
2297
dl.setProcessId(procId);
2298               dl.setActivityId(hibDeadline.getActivityId());
2299               dl.setExceptionName(hibDeadline.getExceptionName());
2300               dl.setSynchronous(hibDeadline.isSynchronous());
2301               ((SharkHibernateTransaction)ti).read(hibDeadline);
2302               ret.add(dl);
2303            }
2304         }
2305         return ret;
2306      }
2307      catch (Throwable JavaDoc t) {
2308         throw new PersistenceException(t);
2309      }
2310   }
2311
2312   public List JavaDoc getAllDeadlinesForProcess (String JavaDoc procId, long timeLimitBoundary, SharkTransaction ti) throws PersistenceException {
2313      List JavaDoc ret=new ArrayList JavaDoc();
2314      try {
2315         List JavaDoc deadlines = getPersistedDeadlines(procId,timeLimitBoundary,ti);
2316         if (deadlines.size() != 0) {
2317            for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
2318               HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2319               DeadlinePersistenceInterface dl = createDeadline();
2320               // restore Deadline
2321
dl.setProcessId(procId);
2322               dl.setActivityId(hibDeadline.getActivityId());
2323               dl.setExceptionName(hibDeadline.getExceptionName());
2324               dl.setSynchronous(hibDeadline.isSynchronous());
2325               ((SharkHibernateTransaction)ti).read(hibDeadline);
2326               ret.add(dl);
2327            }
2328         }
2329         return ret;
2330      }
2331      catch (Throwable JavaDoc t) {
2332         throw new PersistenceException(t);
2333      }
2334   }
2335
2336   private List JavaDoc getPersistedDeadlines (String JavaDoc procId,long timeLimitBoundary,SharkTransaction ti) throws PersistenceException {
2337      List JavaDoc deadlines = new ArrayList JavaDoc();
2338      try {
2339         Session session = ((SharkHibernateTransaction) ti).getSession();
2340         if (timeLimitBoundary>=0) {
2341            Query qDeadlinesQuery = session.createQuery("from HibernateDeadline deadline where deadline.processId = :keyValueParam_1 and " + "deadline.timeLimit < :keyValueParam_2");
2342            qDeadlinesQuery.setString("keyValueParam_1", getPersistedProcessObject(procId,ti).getId());
2343            qDeadlinesQuery.setLong("keyValueParam_2", timeLimitBoundary);
2344            deadlines = qDeadlinesQuery.list();
2345         } else {
2346            Query qDeadlinesQuery = session.createQuery("from HibernateDeadline deadline where deadline.processId = :keyValueParam_1");
2347            qDeadlinesQuery.setString("keyValueParam_1", getPersistedProcessObject(procId,ti).getId());
2348            deadlines = qDeadlinesQuery.list();
2349         }
2350
2351         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateDeadlineClassName);
2352         it.hasNext();) {
2353            HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2354            int index = deadlines.indexOf(hibDeadline);
2355            if (procId.equals(hibDeadline.getProcessId())) {
2356               if (-1 == index)
2357                  deadlines.add(hibDeadline);
2358               else {
2359                  deadlines.set(index, hibDeadline);
2360               }
2361            }
2362         }
2363         ((SharkHibernateTransaction)ti).read(deadlines);
2364         return deadlines;
2365      }
2366      catch (Throwable JavaDoc t) {
2367         throw new PersistenceException(t);
2368      }
2369   }
2370
2371   private List JavaDoc getActivitiesPersistedDeadlines (String JavaDoc actId, long timeLimitBoundary,SharkTransaction ti) throws PersistenceException {
2372      List JavaDoc deadlines = new ArrayList JavaDoc();
2373      try {
2374         Session session = ((SharkHibernateTransaction) ti).getSession();
2375         if (timeLimitBoundary>=0) {
2376            Query qDeadlinesQuery = session.createQuery("from HibernateDeadline deadline where deadline.activityId = :keyValueParam_1 and " + "deadline.timeLimit < :keyValueParam_2");
2377            qDeadlinesQuery.setString("keyValueParam_1", getPersistedActivityObject(actId,ti).getId());
2378            qDeadlinesQuery.setLong("keyValueParam_2", timeLimitBoundary);
2379            deadlines = qDeadlinesQuery.list();
2380         } else {
2381            Query qDeadlinesQuery = session.createQuery("from HibernateDeadline deadline where deadline.activityId = :keyValueParam_1");
2382            qDeadlinesQuery.setString("keyValueParam_1", getPersistedActivityObject(actId,ti).getId());
2383            deadlines = qDeadlinesQuery.list();
2384         }
2385
2386         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateDeadlineClassName);
2387         it.hasNext();) {
2388            HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2389            int index = deadlines.indexOf(hibDeadline);
2390            if (actId.equals(hibDeadline.getActivityId())) {
2391               if (-1 == index)
2392                  deadlines.add(hibDeadline);
2393               else {
2394                  deadlines.set(index, hibDeadline);
2395               }
2396            }
2397         }
2398         ((SharkHibernateTransaction)ti).read(deadlines);
2399         return deadlines;
2400      }
2401      catch (Throwable JavaDoc t) {
2402         throw new PersistenceException(t);
2403      }
2404   }
2405
2406   public List JavaDoc getAllDeadlinesForActivity (String JavaDoc procId, String JavaDoc actId, SharkTransaction ti) throws PersistenceException {
2407      List JavaDoc ret=new ArrayList JavaDoc();
2408      try {
2409         List JavaDoc deadlines = getActivitiesPersistedDeadlines(actId,-1,ti);
2410         if (deadlines.size() != 0) {
2411            for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
2412               HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2413               DeadlinePersistenceInterface dl = createDeadline();
2414               // restore Deadline
2415
dl.setProcessId(procId);
2416               dl.setActivityId(hibDeadline.getActivityId());
2417               dl.setExceptionName(hibDeadline.getExceptionName());
2418               dl.setSynchronous(hibDeadline.isSynchronous());
2419               ((SharkHibernateTransaction)ti).read(hibDeadline);
2420               ret.add(dl);
2421            }
2422         }
2423         return ret;
2424      }
2425      catch (Throwable JavaDoc t) {
2426         throw new PersistenceException(t);
2427      }
2428   }
2429
2430   public List JavaDoc getAllDeadlinesForActivity (String JavaDoc procId, String JavaDoc actId, long timeLimitBoundary, SharkTransaction ti) throws PersistenceException {
2431      List JavaDoc ret=new ArrayList JavaDoc();
2432      try {
2433         List JavaDoc deadlines = getActivitiesPersistedDeadlines(actId,timeLimitBoundary,ti);
2434         if (deadlines.size() != 0) {
2435            for (Iterator JavaDoc it = deadlines.iterator();it.hasNext();) {
2436               HibernateDeadline hibDeadline = (HibernateDeadline)it.next();
2437               DeadlinePersistenceInterface dl = createDeadline();
2438               // restore Deadline
2439
dl.setProcessId(procId);
2440               dl.setActivityId(hibDeadline.getActivityId());
2441               dl.setExceptionName(hibDeadline.getExceptionName());
2442               dl.setSynchronous(hibDeadline.isSynchronous());
2443               ((SharkHibernateTransaction)ti).read(hibDeadline);
2444               ret.add(dl);
2445            }
2446         }
2447         return ret;
2448      }
2449      catch (Throwable JavaDoc t) {
2450         throw new PersistenceException(t);
2451      }
2452   }
2453
2454   public int howManyAndJoinEntries(String JavaDoc procId, String JavaDoc asDefId, String JavaDoc aDefId, SharkTransaction ti) throws PersistenceException {
2455      try {
2456         Session session = ((SharkHibernateTransaction) ti).getSession();
2457         List JavaDoc andJoinEntries = getPersistedAndJoinEntries(procId, asDefId, aDefId, ti);
2458         return andJoinEntries.size();
2459      } catch (Throwable JavaDoc tr) {
2460         throw new PersistenceException(tr);
2461      }
2462   }
2463
2464   public int getExecuteCount(String JavaDoc procId, String JavaDoc asDefId, String JavaDoc aDefId, SharkTransaction ti) throws PersistenceException {
2465      try {
2466         Session session = ((SharkHibernateTransaction) ti).getSession();
2467         HibernateProcess hibProcess = getPersistedProcessObject(procId, ti);
2468         if (hibProcess == null)
2469            return 0;
2470
2471         Query qActivitiesQuery = session.createQuery("from HibernateActivity activity where activity.processId = :keyValueParam_1 and " +
2472               "activity.activityDefinitionId = :keyValueParam_2" +
2473               " and activity.activitySetDefinitionId = :keyValueParam_3");
2474         qActivitiesQuery.setString("keyValueParam_1", hibProcess.getId());
2475         qActivitiesQuery.setString("keyValueParam_2", aDefId);
2476         qActivitiesQuery.setString("keyValueParam_3", asDefId);
2477         List JavaDoc activities = qActivitiesQuery.list();
2478
2479         for (Iterator JavaDoc it = ((SharkHibernateTransaction)ti).iterator4type(HibernateUtilities.HibernateActivityClassName);
2480         it.hasNext();) {
2481            HibernateActivity hibActivity = (HibernateActivity)it.next();
2482            if (procId.equals(hibActivity.getProcessId()) && aDefId.equals(hibActivity.getActivityDefinitionId()) && asDefId.equals(hibActivity.getActivitySetDefinitionId())){
2483               int index = activities.indexOf(hibActivity);
2484               if (-1 == index)
2485                  activities.add(hibActivity);
2486            }
2487         }
2488         return activities.size();
2489
2490      } catch (Exception JavaDoc e) {
2491         throw new PersistenceException(e);
2492      }
2493   }
2494
2495   //////////////////////////////////////////////////////////////////
2496
// Factory methods
2497
//////////////////////////////////////////////////////////////////
2498

2499   public ActivityPersistenceInterface createActivity() {
2500      return new HibernateActivity();
2501   }
2502
2503   public ProcessPersistenceInterface createProcess() {
2504      return new HibernateProcess();
2505   }
2506
2507   public HibernateProcessRequester createProcessRequester() {
2508      return new HibernateProcessRequester();
2509   }
2510
2511   public ProcessMgrPersistenceInterface createProcessMgr() {
2512      return new HibernateProcessMgr();
2513   }
2514
2515   public AssignmentPersistenceInterface createAssignment() {
2516      return new HibernateAssignment();
2517   }
2518
2519   public ResourcePersistenceInterface createResource() {
2520      return new HibernateResource();
2521   }
2522
2523   public ProcessVariablePersistenceInterface createProcessVariable() {
2524      return new HibernateProcessVariable();
2525   }
2526
2527   public ActivityVariablePersistenceInterface createActivityVariable() {
2528      return new HibernateActivityVariable();
2529   }
2530
2531   public AndJoinEntryInterface createAndJoinEntry() {
2532      return new HibernateAndJoinEntry();
2533   }
2534
2535   public DeadlinePersistenceInterface createDeadline() {
2536      return new HibernateDeadline();
2537   }
2538
2539   //////////////////////////////////////////////////////////////////
2540
// Utility methods
2541
//////////////////////////////////////////////////////////////////
2542

2543   public BigDecimal JavaDoc getNextDecId(String JavaDoc idName) throws PersistenceException {
2544      try {
2545         return HibernateUtilities.getNext(idName);
2546      } catch (Exception JavaDoc e) {
2547         throw new PersistenceException("Couldn't allocate id");
2548      }
2549   }
2550
2551   public String JavaDoc getNextId(String JavaDoc idName) throws PersistenceException {
2552      return getNextDecId(idName).toString();
2553   }
2554
2555}
2556
Popular Tags