KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.instancepersistence;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.util.*;
5
6 import org.enhydra.dods.DODS;
7 import org.enhydra.shark.api.RootException;
8 import org.enhydra.shark.api.SharkTransaction;
9 import org.enhydra.shark.api.internal.instancepersistence.*;
10 import org.enhydra.shark.api.internal.working.CallbackUtilities;
11 import org.enhydra.shark.instancepersistence.data.*;
12 import org.enhydra.shark.transaction.SharkDODSTransaction;
13 import org.enhydra.shark.utilities.MiscUtilities;
14 import org.enhydra.shark.utilities.dods.DODSUtilities;
15
16 import com.lutris.appserver.server.sql.DBTransaction;
17 import com.lutris.dods.builder.generator.query.QueryBuilder;
18
19
20 /**
21  * Used to save, restore or delete relevant engine objects from database, using
22  * DODS persistent layer.
23  *
24  * @author Sasa Bojanic
25  * @version 1.0
26  */

27 public class DODSPersistentManager implements PersistentManagerInterface {
28
29    protected static final String JavaDoc LOG_CHANNEL="Persistence";
30    protected static final int RESOURCE_TYPE_OBJECT=0;
31    protected static final int PROCESS_DEFINITION_TYPE_OBJECT=1;
32    protected static final int PROCESS_TYPE_OBJECT=2;
33    protected static final int ACTIVITY_TYPE_OBJECT=3;
34    protected static final int ASSIGNMENT_TYPE_OBJECT=4;
35
36    protected static final String JavaDoc[] activityAndProcessStates={"open.running",
37          "open.not_running.not_started","open.not_running.suspended",
38          "closed.completed", "closed.terminated", "closed.aborted"};
39
40
41    protected static final short DB_TYPE_BOOLEAN=0;
42    protected static final short DB_TYPE_LONG=1;
43    protected static final short DB_TYPE_DOUBLE=2;
44    protected static final short DB_TYPE_VCHAR=3;
45    protected static final short DB_TYPE_DATE=4;
46    protected static final short DB_TYPE_BLOB=5;
47
48    protected static final int MAX_VCHAR_SIZE_LIMIT=4000;
49
50    protected static int max_vchar_size=4000;
51
52    protected CallbackUtilities cus;
53    protected boolean deleteFinishedProcesses=false;
54    protected Map _prStates;
55    protected Map _acStates;
56
57    protected List _prClosedStatesBigDecimals;
58    protected List _actClosedStatesBigDecimals;
59    protected List _actOpenStatesBigDecimals;
60
61    protected boolean usingStandardVariableDataModel=true;
62    
63    public void configure (CallbackUtilities cus) throws RootException {
64       this.cus=cus;
65       String JavaDoc del=cus.getProperty("DODSPersistentManager.deleteFinishedProcesses","false");
66       deleteFinishedProcesses=new Boolean JavaDoc(del).booleanValue();
67       String JavaDoc shtd=cus.getProperty("DatabaseManager.DB.sharkdb.Connection.ShutDownString","");
68       String JavaDoc mvc=cus.getProperty("DODSPersistentManager.maxVARCHARSize","4000");
69       try {
70          max_vchar_size=Integer.parseInt(mvc);
71          if (max_vchar_size>MAX_VCHAR_SIZE_LIMIT || max_vchar_size<1) {
72             max_vchar_size=MAX_VCHAR_SIZE_LIMIT;
73             cus.warn("Invalid value "+mvc+" for property DODSPersistentManager.maxVARCHARSize. Using default value "+max_vchar_size);
74          }
75       } catch (Exception JavaDoc e) {
76          cus.warn("Invalid value "+mvc+" for property DODSPersistentManager.maxVARCHARSize. Using default value "+max_vchar_size);
77       }
78       
79       if (shtd.equals("SHUTDOWN")) {
80          cus.info(LOG_CHANNEL,"DODSPersistentManager -> Adding shutdown hook for HSQL DB");
81          Runtime.getRuntime().addShutdownHook(
82             new Thread JavaDoc() {
83                public void run() {
84                   try {
85                      org.enhydra.dods.DODS.shutdown();
86                   } catch (Throwable JavaDoc thr) {
87                      thr.printStackTrace();
88                   }
89                }
90             }
91          );
92       }
93       usingStandardVariableDataModel=new Boolean JavaDoc(cus.getProperty("DODSPersistentManager.useStandardVariableDataModel","true")).booleanValue();
94       
95       _prStates = new HashMap();
96       _acStates = new HashMap();
97       _prClosedStatesBigDecimals = new ArrayList();
98       _actClosedStatesBigDecimals = new ArrayList();
99       _actOpenStatesBigDecimals = new ArrayList();
100
101       try {
102          try {
103             DODSUtilities.init(cus.getProperties());
104          }
105          catch (Throwable JavaDoc ex) {
106             ex.printStackTrace();
107          }
108          initActivityAndProcessStatesTable();
109          cus.info("DODSPersistentManager -> manager configured - working with DB "+cus.getProperty("DatabaseManager.DB.sharkdb.Connection.Url"));
110          cus.info("DODSPersistentManager -> - using DB Driver "+cus.getProperty("DatabaseManager.DB.sharkdb.JdbcDriver"));
111          cus.info("DODSPersistentManager -> - persisting String variables into BLOB for sizes greater than "+max_vchar_size);
112       }
113       catch (Throwable JavaDoc tr) {
114          tr.printStackTrace();
115          cus.error(LOG_CHANNEL,"Problem with registering database manager with DODS !", new RootException(tr));
116          throw new RootException("Problem with registering database manager with DODS !",tr);
117       }
118    }
119
120    /**
121     * Fills the state table with possible activity and process states. For now,
122     * the 'keyValue' and the 'name' attribute of state record has the same value,
123     * but in the future, if the names of states changes, it will be very easy
124     * to change this table entries without affecting other tables.
125     * NOTE: When new names are introduced, the getPersistentXXX that use it
126     * also has to be changed
127     */

128    protected void initActivityAndProcessStatesTable () throws PersistenceException {
129       DBTransaction t=null;
130       try {
131          t = DODS.getDatabaseManager().createTransaction();
132          for (int i=0; i<activityAndProcessStates.length; i++) {
133             String JavaDoc state=activityAndProcessStates[i];
134             ProcessStateDO psDO=getPersistedProcessStateObject(state,true,t);
135             if (!psDO.isPersistent()) {
136                psDO.setKeyValue(state);
137             }
138             psDO.setName(state);
139             psDO.save(t);
140             BigDecimal JavaDoc bd=psDO.get_OId().toBigDecimal();
141             _prStates.put(state, bd);
142             if (state.startsWith("closed.")) {
143                _prClosedStatesBigDecimals.add(bd);
144             }
145             ActivityStateDO asDO=getPersistedActivityStateObject(state,true,t);
146             if (!asDO.isPersistent()) {
147                asDO.setKeyValue(state);
148             }
149             asDO.setName(state);
150             asDO.save(t);
151
152             BigDecimal JavaDoc bda=asDO.get_OId().toBigDecimal();
153             _acStates.put(state, bda);
154             if (state.startsWith("closed.")) {
155                _actClosedStatesBigDecimals.add(bda);
156             } else {
157                _actOpenStatesBigDecimals.add(bda);
158             }
159          }
160          t.commit();
161       }
162       catch (Throwable JavaDoc thr) {
163          throw new PersistenceException(thr);
164       }
165       finally {
166          try {
167             t.release();
168          } catch (Exception JavaDoc ex) {}
169       }
170    }
171
172    public void shutdownDatabase () throws PersistenceException {
173       try {
174          DODS.shutdown();
175       }
176       catch (Throwable JavaDoc tr) {
177          cus.error(LOG_CHANNEL,"Database is not properly shudown !", new RootException(tr));
178          throw new PersistenceException("Database is not properly shudown !",tr);
179       }
180    }
181
182    public void persist (ProcessMgrPersistenceInterface pm,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
183       try {
184          ProcessDefinitionDO DO=null;
185          if (isInitialPersistence) {
186             DO=ProcessDefinitionDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
187          } else {
188             DO=getPersistedObject(pm,ti);
189          }
190          // when these attributes are persisted - they never change
191
if (isInitialPersistence) {
192             DO.setName(pm.getName());
193             DO.setPackageId(pm.getPackageId());
194             DO.setProcessDefinitionId(pm.getProcessDefinitionId());
195             DO.setProcessDefinitionVersion(pm.getVersion());
196             DO.setProcessDefinitionCreated(pm.getCreated());
197          }
198          DO.setState(pm.getState());
199          ((SharkDODSTransaction)ti).store(DO);
200          //DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
201
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
202
cus.info(LOG_CHANNEL,"ProcessDefinition[packageId="+pm.getPackageId()+",id="+pm.getProcessDefinitionId()+"] persisted");
203       }
204       catch (Throwable JavaDoc tr) {
205          cus.error(LOG_CHANNEL,"Persisting of ProcessDefinition "+pm.getProcessDefinitionId()+" failed");
206          throw new PersistenceException("Persisting of ProcessDefinition "
207                                            + pm.getProcessDefinitionId()
208                                            +" failed", tr);
209       }
210    }
211
212    public void persist (ProcessPersistenceInterface pr,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
213       try {
214          ProcessDO DO=null;
215          if (isInitialPersistence) {
216             DO=ProcessDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
217          } else {
218             DO=getPersistedObject(pr,ti);
219          }
220          // when these attributes are persisted - they never change
221
if (isInitialPersistence) {
222             DO.setId(pr.getId());
223             DO.setProcessDefinition(getPersistedProcessMgrObject(pr.getProcessMgrName(),ti));
224             //ProcessRequesterDO rDO = getProcessRequester(pr.getId(),ti);
225
ProcessRequesterDO rDO = ProcessRequesterDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
226             rDO.setId(pr.getId());
227             if (pr.getActivityRequesterId()!=null) {
228                rDO.setActivityRequester(getPersistedActivityObject(pr.getActivityRequesterId(),ti));
229             }
230             rDO.setResourceRequester(getPersistedResourceObject(pr.getResourceRequesterId(),ti));
231             DO.setPDefName(pr.getProcessMgrName());
232             DO.setActivityRequesterId(pr.getActivityRequesterId());
233             DO.setActivityRequesterProcessId(pr.getActivityRequestersProcessId());
234             DO.setResourceRequesterId(pr.getResourceRequesterId());
235             ((SharkDODSTransaction)ti).store(rDO);
236          }
237          DO.setExternalRequesterClassName(pr.getExternalRequesterClassName());
238
239          //System.out.println("Going to persist process by filling DO "+DO);
240
DO.setName(pr.getName());
241          DO.setDescription(pr.getDescription());
242          DO.setPriority(pr.getPriority());
243          DO.oid_setState((BigDecimal JavaDoc)_prStates.get(pr.getState()));
244          DO.setCreated(pr.getCreatedTime());
245          DO.setStarted(pr.getStartedTime());
246          DO.setLastStateTime(pr.getLastStateTime());
247          DO.setLimitTime(pr.getLimitTime());
248          ((SharkDODSTransaction)ti).store(DO);
249          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
250
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
251
cus.info(LOG_CHANNEL,"Process[id="+pr.getId()+"] persisted");
252       }
253       catch (Throwable JavaDoc tr) {
254          cus.error(LOG_CHANNEL,"Persisting of Process "+pr.getId()+" failed");
255          throw new PersistenceException("Persisting of Process "
256                                            + pr.getId()
257                                            +" failed", tr);
258       }
259    }
260
261    public void persist (ActivityPersistenceInterface act,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
262       try {
263          //if (act.getActivityDefinitionId().equals("seeFirstRes")) System.out.println("HHH1");
264
ActivityDO DO=null;
265          if (isInitialPersistence) {
266             DO=ActivityDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
267          } else {
268             DO=getPersistedObject(act,ti);
269          }
270          //if (act.getActivityDefinitionId().equals("seeFirstRes")) System.out.println("HHH2");
271
// when these attributes are persisted - they never change
272
if (isInitialPersistence) {
273             DO.setId(act.getId());
274             DO.setActivitySetDefinitionId(act.getActivitySetDefinitionId());
275             DO.setActivityDefinitionId(act.getActivityDefinitionId());
276             DO.setPDefName(act.getProcessMgrName());
277             DO.setProcess(getPersistedProcessObject(act.getProcessId(),ti));
278             DO.setProcessId(act.getProcessId());
279             String JavaDoc bActId=act.getBlockActivityId();
280             if (bActId!=null) {
281                //DO.setBlockActivity(getPersistedActivityObject(bActId,ti));
282
DO.setBlockActivityId(bActId);
283             }
284          }
285          DO.setPerformer(act.getSubflowProcessId());
286          DO.setIsPerformerAsynchronous(act.isSubflowAsynchronous());
287          DO.setName(act.getName());
288          DO.setDescription(act.getDescription());
289          DO.setPriority(act.getPriority());
290          if (!isInitialPersistence && DO.getResourceId()!=act.getResourceUsername()) {
291             DO.setTheResource(getPersistedResourceObject(act.getResourceUsername(),ti));
292             DO.setResourceId(act.getResourceUsername());
293          }
294          DO.oid_setState((BigDecimal JavaDoc)_acStates.get(act.getState()));
295          DO.setLastStateTime(act.getLastStateTime());
296          DO.setLimitTime(act.getLimitTime());
297          DO.setAccepted(act.getAcceptedTime());
298          DO.setActivated(act.getActivatedTime());
299
300          ((SharkDODSTransaction)ti).store(DO);
301          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
302
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
303
cus.info(LOG_CHANNEL,"Activity[id="+act.getId()+",definitionId="+act.getActivityDefinitionId()+"] persisted");
304       }
305       catch (Throwable JavaDoc tr) {
306          cus.error(LOG_CHANNEL,"Persisting of Activity "+act.getId()+" failed");
307          throw new PersistenceException("Persisting of Activity "
308                                            + act.getId()
309                                            +" failed",tr);
310       }
311    }
312
313    public void persist (ResourcePersistenceInterface res,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
314       try {
315          ResourceDO DO=null;
316          if (isInitialPersistence) {
317             DO=ResourceDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
318          } else {
319             DO=getPersistedObject(res,ti);
320          }
321          // when this attribute is persisted - it is never changed
322
if (isInitialPersistence) {
323             DO.setUsername(res.getUsername());
324             DO.setName(res.getName());
325          }
326          ((SharkDODSTransaction)ti).store(DO);
327          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
328
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
329
cus.info(LOG_CHANNEL,"Resource[username="+res.getUsername()+"] persisted");
330       }
331       catch (Throwable JavaDoc tr) {
332          cus.error(LOG_CHANNEL,"Persisting of Resource "+res.getUsername()+" failed");
333          throw new PersistenceException("Persisting of Resource "
334                                            + res.getUsername()+" failed", tr);
335       }
336    }
337
338    public void persist (AssignmentPersistenceInterface ass,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
339       try {
340          AssignmentDO DO=null;
341          if (isInitialPersistence) {
342             DO=AssignmentDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
343          } else {
344             DO=getPersistedObject(ass,ti);
345          }
346 // System.out.println("IIP="+isInitialPersistence+", DO="+DO);
347
// when this attribute is persisted - it is never changed
348
if (isInitialPersistence) {
349             DO.setActivity(getPersistedActivityObject(ass.getActivityId(),ti));
350             DO.setCNT(getNextDecId("_assignment_"));
351             DO.setActivityId(ass.getActivityId());
352             DO.setActivityProcessId(ass.getProcessId());
353             DO.setActivityProcessDefName(ass.getProcessMgrName());
354          }
355          DO.setIsValid(ass.isValid());
356          DO.setIsAccepted(ass.isAccepted());
357          if (ass.getResourceUsername()!=DO.getResourceId()) {
358             DO.setResourceId(ass.getResourceUsername());
359             DO.setTheResource(getPersistedResourceObject(ass.getResourceUsername(),ti));
360          }
361          ((SharkDODSTransaction)ti).store(DO);
362          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
363
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
364
cus.info(LOG_CHANNEL,"Assignment[activityId="+ass.getActivityId()+", username="+ass.getResourceUsername()+"] persisted");
365       }
366       catch (Throwable JavaDoc tr) {
367          cus.error(LOG_CHANNEL,"Persisting of Assignment failed");
368          throw new PersistenceException("Persisting of Assignment failed", tr);
369       }
370    }
371
372    public void persist (AssignmentPersistenceInterface ass,String JavaDoc oldResUname,SharkTransaction ti) throws PersistenceException {
373       try {
374          AssignmentDO DO=getPersistedAssignmentObject(ass.getActivityId(),oldResUname,ti);
375          DO.setTheResource(getPersistedResourceObject(ass.getResourceUsername(),ti));
376          DO.setResourceId(ass.getResourceUsername());
377          DO.setIsValid(ass.isValid());
378          DO.setIsAccepted(ass.isAccepted());
379          ((SharkDODSTransaction)ti).store(DO);
380          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
381
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
382
cus.info(LOG_CHANNEL,"Assignment[activityId="+ass.getActivityId()+", username="+ass.getResourceUsername()+"] persisted");
383       }
384       catch (Throwable JavaDoc tr) {
385          cus.error(LOG_CHANNEL,"Persisting of Assignment failed");
386          throw new PersistenceException("Persisting of Assignment failed", tr);
387       }
388    }
389
390    public void persist (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
391       if (usingStandardVariableDataModel) {
392          persistVariablesBLOB(var, isInitialPersistence, ti);
393       } else {
394          persistVariablesWOB(var, isInitialPersistence, ti);
395       }
396    }
397    
398    protected void persistVariablesBLOB (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
399       try {
400          ProcessDataDO DO=null;
401          if (isInitialPersistence) {
402             DO=ProcessDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
403          } else {
404             DO=getPersistedObject(var,ti);
405          }
406          // when this attribute is persisted - it is never changed
407
if (isInitialPersistence) {
408             DO.setProcess(getPersistedProcessObject(var.getProcessId(),ti));
409             DO.setVariableDefinitionId(var.getDefinitionId());
410          }
411
412          Object JavaDoc vv=var.getValue();
413          boolean isBLOB=false;
414          boolean wasBLOB=false;
415          if (vv instanceof Boolean JavaDoc) {
416             DO.setVariableValueBOOL(((Boolean JavaDoc)vv).booleanValue());
417             DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN);
418          } else if (vv instanceof Long JavaDoc) {
419             DO.setVariableValueLONG(((Long JavaDoc)vv).longValue());
420             DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG);
421          } else if (vv instanceof String JavaDoc) {
422             String JavaDoc sv=(String JavaDoc)vv;
423             if (sv.length()<=max_vchar_size) {
424                DO.setVariableValueVCHAR(sv);
425                wasBLOB=true;
426                DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR);
427             } else {
428                DO.setVariableValueVCHAR(null);
429                isBLOB=true;
430             }
431          } else if (vv instanceof Double JavaDoc) {
432             DO.setVariableValueDBL(((Double JavaDoc)vv).doubleValue());
433             DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE);
434          } else if (vv instanceof java.util.Date JavaDoc) {
435             DO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)vv).getTime()));
436             DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE);
437          } else if (vv==null) {
438             short vt=DO.getVariableType();
439             if (vt==DODSPersistentManager.DB_TYPE_DATE) {
440                DO.setVariableValueDATE(null);
441             } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) {
442                DO.setVariableValueVCHAR(null);
443             } else {
444                DO.setVariableValue(null);
445                DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
446             }
447          } else {
448             isBLOB=true;
449          }
450
451          if (isBLOB) {
452             DO.setVariableValue(MiscUtilities.serialize(vv));
453             DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
454          }
455          if (wasBLOB) {
456             DO.setVariableValue(null);
457          }
458          
459          ((SharkDODSTransaction)ti).store(DO);
460          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
461
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
462
cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] persisted");
463       }
464       catch (Throwable JavaDoc tr) {
465          cus.error(LOG_CHANNEL,"Persisting of ProcessVariable failed");
466          throw new PersistenceException("Persisting of ProcessVariable failed", tr);
467       }
468    }
469       
470    protected void persistVariablesWOB (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
471       try {
472          ProcessDataWOBDO DO=null;
473          if (isInitialPersistence) {
474             DO=ProcessDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
475          } else {
476             DO=getPersistedObject2(var,ti);
477          }
478          // when this attribute is persisted - it is never changed
479
if (isInitialPersistence) {
480             DO.setProcess(getPersistedProcessObject(var.getProcessId(),ti));
481             DO.setVariableDefinitionId(var.getDefinitionId());
482          }
483
484          Object JavaDoc vv=var.getValue();
485          boolean isBLOB=false;
486          boolean wasBLOB=false;
487          if (vv instanceof Boolean JavaDoc) {
488             DO.setVariableValueBOOL(((Boolean JavaDoc)vv).booleanValue());
489             DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN);
490          } else if (vv instanceof Long JavaDoc) {
491             DO.setVariableValueLONG(((Long JavaDoc)vv).longValue());
492             DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG);
493          } else if (vv instanceof String JavaDoc) {
494             String JavaDoc sv=(String JavaDoc)vv;
495             if (sv.length()<=max_vchar_size) {
496                DO.setVariableValueVCHAR(sv);
497                wasBLOB=true;
498                DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR);
499             } else {
500                DO.setVariableValueVCHAR(null);
501                isBLOB=true;
502             }
503          } else if (vv instanceof Double JavaDoc) {
504             DO.setVariableValueDBL(((Double JavaDoc)vv).doubleValue());
505             DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE);
506          } else if (vv instanceof java.util.Date JavaDoc) {
507             DO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)vv).getTime()));
508             DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE);
509          } else if (vv==null) {
510             short vt=DO.getVariableType();
511             if (vt==DODSPersistentManager.DB_TYPE_DATE) {
512                DO.setVariableValueDATE(null);
513             } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) {
514                DO.setVariableValueVCHAR(null);
515             } else {
516                ProcessDataBLOBDO bDO=null;
517                if (isInitialPersistence) {
518                   bDO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
519                } else {
520                   bDO=getPersistedObject(DO, ti);
521                }
522                bDO.setProcessDataWOB(DO);
523                bDO.setVariableValue(null);
524                DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
525                ((SharkDODSTransaction)ti).store(bDO);
526             }
527          } else {
528             isBLOB=true;
529          }
530
531          if (isBLOB) {
532             ProcessDataBLOBDO bDO=null;
533             if (isInitialPersistence) {
534                bDO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
535             } else {
536                bDO=getPersistedObject(DO, ti);
537             }
538             bDO.setProcessDataWOB(DO);
539             bDO.setVariableValue(MiscUtilities.serialize(vv));
540             DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
541             ((SharkDODSTransaction)ti).store(bDO);
542          }
543 // if (wasBLOB) {
544
// DO.setVariableValue(null);
545
// }
546

547          ((SharkDODSTransaction)ti).store(DO);
548          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
549
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
550
cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] persisted");
551       }
552       catch (Throwable JavaDoc tr) {
553          cus.error(LOG_CHANNEL,"Persisting of ProcessVariable failed");
554          throw new PersistenceException("Persisting of ProcessVariable failed", tr);
555       }
556    }
557
558    public void persist (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
559       if (usingStandardVariableDataModel) {
560          persistVariablesBLOB(var, isInitialPersistence, ti);
561       } else {
562          persistVariablesWOB(var, isInitialPersistence, ti);
563       }
564    }
565
566    public void persistVariablesBLOB (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
567       try {
568          ActivityDataDO DO=null;
569          if (isInitialPersistence) {
570             DO=ActivityDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
571          } else {
572             DO=getPersistedObject(var,ti);
573          }
574          // when this attribute is persisted - it is never changed
575
if (isInitialPersistence) {
576             DO.setActivity(getPersistedActivityObject(var.getActivityId(),ti));
577             DO.setVariableDefinitionId(var.getDefinitionId());
578          }
579
580          Object JavaDoc vv=var.getValue();
581          boolean isBLOB=false;
582          boolean wasBLOB=false;
583          if (vv instanceof Boolean JavaDoc) {
584             DO.setVariableValueBOOL(((Boolean JavaDoc)vv).booleanValue());
585             DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN);
586          } else if (vv instanceof Long JavaDoc) {
587             DO.setVariableValueLONG(((Long JavaDoc)vv).longValue());
588             DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG);
589          } else if (vv instanceof String JavaDoc) {
590             String JavaDoc sv=(String JavaDoc)vv;
591             if (sv.length()<=max_vchar_size) {
592                DO.setVariableValueVCHAR(sv);
593                wasBLOB=true;
594                DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR);
595             } else {
596                DO.setVariableValueVCHAR(null);
597                isBLOB=true;
598             }
599          } else if (vv instanceof Double JavaDoc) {
600             DO.setVariableValueDBL(((Double JavaDoc)vv).doubleValue());
601             DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE);
602          } else if (vv instanceof java.util.Date JavaDoc) {
603             DO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)vv).getTime()));
604             DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE);
605          } else if (vv==null) {
606             short vt=DO.getVariableType();
607             if (vt==DODSPersistentManager.DB_TYPE_DATE) {
608                DO.setVariableValueDATE(null);
609             } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) {
610                DO.setVariableValueVCHAR(null);
611             } else {
612                DO.setVariableValue(null);
613                DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
614             }
615          } else {
616             isBLOB=true;
617          }
618
619          if (isBLOB) {
620             DO.setVariableValue(MiscUtilities.serialize(vv));
621             DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
622          }
623          if (wasBLOB) {
624             DO.setVariableValue(null);
625          }
626
627          DO.setIsResult(var.isResultVariable());
628          ((SharkDODSTransaction)ti).store(DO);
629          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
630
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
631
cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] persisted");
632       }
633       catch (Throwable JavaDoc tr) {
634          cus.error(LOG_CHANNEL,"Persisting of ActivityVariable failed");
635          throw new PersistenceException("Persisting of ActivityVariable failed", tr);
636       }
637    }
638    
639    public void persistVariablesWOB (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException {
640       try {
641          ActivityDataWOBDO DO=null;
642          if (isInitialPersistence) {
643             DO=ActivityDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
644          } else {
645             DO=getPersistedObject2(var,ti);
646          }
647          // when this attribute is persisted - it is never changed
648
if (isInitialPersistence) {
649             DO.setActivity(getPersistedActivityObject(var.getActivityId(),ti));
650             DO.setVariableDefinitionId(var.getDefinitionId());
651          }
652
653          Object JavaDoc vv=var.getValue();
654          boolean isBLOB=false;
655          boolean wasBLOB=false;
656          if (vv instanceof Boolean JavaDoc) {
657             DO.setVariableValueBOOL(((Boolean JavaDoc)vv).booleanValue());
658             DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN);
659          } else if (vv instanceof Long JavaDoc) {
660             DO.setVariableValueLONG(((Long JavaDoc)vv).longValue());
661             DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG);
662          } else if (vv instanceof String JavaDoc) {
663             String JavaDoc sv=(String JavaDoc)vv;
664             if (sv.length()<=max_vchar_size) {
665                DO.setVariableValueVCHAR(sv);
666                wasBLOB=true;
667                DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR);
668             } else {
669                DO.setVariableValueVCHAR(null);
670                isBLOB=true;
671             }
672          } else if (vv instanceof Double JavaDoc) {
673             DO.setVariableValueDBL(((Double JavaDoc)vv).doubleValue());
674             DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE);
675          } else if (vv instanceof java.util.Date JavaDoc) {
676             DO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)vv).getTime()));
677             DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE);
678          } else if (vv==null) {
679             short vt=DO.getVariableType();
680             if (vt==DODSPersistentManager.DB_TYPE_DATE) {
681                DO.setVariableValueDATE(null);
682             } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) {
683                DO.setVariableValueVCHAR(null);
684             } else {
685                ActivityDataBLOBDO bDO=null;
686                if (isInitialPersistence) {
687                   bDO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
688                } else {
689                   bDO=getPersistedObject(DO, ti);
690                }
691                bDO.setActivityDataWOB(DO);
692                bDO.setVariableValue(null);
693                DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
694                ((SharkDODSTransaction)ti).store(bDO);
695             }
696          } else {
697             isBLOB=true;
698          }
699
700          if (isBLOB) {
701             ActivityDataBLOBDO bDO=null;
702             if (isInitialPersistence) {
703                bDO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
704             } else {
705                bDO=getPersistedObject(DO, ti);
706             }
707             bDO.setActivityDataWOB(DO);
708             bDO.setVariableValue(MiscUtilities.serialize(vv));
709             DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB);
710             ((SharkDODSTransaction)ti).store(bDO);
711          }
712 // if (wasBLOB) {
713
// DO.setVariableValue(null);
714
// }
715

716          DO.setIsResult(var.isResultVariable());
717          ((SharkDODSTransaction)ti).store(DO);
718          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
719
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
720
cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] persisted");
721       }
722       catch (Throwable JavaDoc tr) {
723          cus.error(LOG_CHANNEL,"Persisting of ActivityVariable failed");
724          throw new PersistenceException("Persisting of ActivityVariable failed", tr);
725       }
726    }
727    
728    public void persist (AndJoinEntryInterface aje,SharkTransaction ti) throws PersistenceException {
729       try {
730          AndJoinEntryDO DO=AndJoinEntryDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
731          DO.setProcess(getPersistedProcessObject(aje.getProcessId(),ti));
732          DO.setActivitySetDefinitionId(aje.getActivitySetDefinitionId());
733          DO.setActivityDefinitionId(aje.getActivityDefinitionId());
734          DO.setActivity(getPersistedActivityObject(aje.getActivityId(),ti));
735          DO.setCNT(getNextDecId("andjoinentry"));
736          ((SharkDODSTransaction)ti).store(DO);
737          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
738
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
739
cus.info(LOG_CHANNEL,"AndJoinEntry[id="+aje.getProcessId()+",aDefId="+aje.getActivityDefinitionId()+",actId="+aje.getActivityId()+"] persisted");
740       }
741       catch (Throwable JavaDoc tr) {
742          cus.error(LOG_CHANNEL,"Persisting of AndJoinEntry [id="+aje.getProcessId()+",aDefId="+aje.getActivityDefinitionId()+",actId="+aje.getActivityId()+"] failed");
743          throw new PersistenceException(
744             "Persisting of AndJoinEntry [id="+aje.getProcessId()+
745                ",aDefId="+aje.getActivityDefinitionId()+
746                ",actId="+aje.getActivityId()+"] failed",tr);
747       }
748    }
749
750    public void persist(DeadlinePersistenceInterface dpe, boolean isInitialPersistence, SharkTransaction ti) throws PersistenceException {
751       try {
752          DeadlineDO DO=null;
753          if (isInitialPersistence) {
754             DO=DeadlineDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
755          } else {
756             DO=getPersistedObject(dpe,ti);
757          }
758          // when this attribute is persisted - it is never changed
759
if (isInitialPersistence) {
760             DO.setProcess(getPersistedProcessObject(dpe.getProcessId(),ti));
761             DO.setActivity(getPersistedActivityObject(dpe.getActivityId(),ti));
762             DO.setExceptionName(dpe.getExceptionName());
763             DO.setTimeLimit(dpe.getTimeLimit());
764             DO.setIsSynchronous(dpe.isSynchronous());
765             DO.setCNT(getNextDecId("deadline"));
766          } else {
767             DO.setIsExecuted(dpe.isExecuted());
768          }
769          ((SharkDODSTransaction)ti).store(DO);
770          //if (DO.isDirty()) DO.save(((SharkDODSTransaction)ti).getDODSTransaction());
771
//if (DO.isVirgin()) {(((SharkDODSTransaction)ti).getDODSTransaction()).write();}
772
cus.info(LOG_CHANNEL,"Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] persisted");
773       }
774       catch (Throwable JavaDoc tr) {
775          cus.error(LOG_CHANNEL,"Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed");
776          throw new PersistenceException(
777             "Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed",tr);
778       }
779    }
780
781    public ProcessMgrPersistenceInterface restoreProcessMgr (String JavaDoc mgrName,SharkTransaction ti) throws PersistenceException {
782       return restore(getPersistedProcessMgrObject(mgrName,ti));
783    }
784
785    protected ProcessMgrPersistenceInterface restore (ProcessDefinitionDO DO) throws PersistenceException {
786       if (DO==null) return null;
787       ProcessMgrPersistenceInterface engineObj=new DODSProcessMgr();
788
789       try {
790          engineObj.setName(DO.getName());
791          engineObj.setPackageId(DO.getPackageId());
792          engineObj.setProcessDefinitionId(DO.getProcessDefinitionId());
793          engineObj.setVersion(DO.getProcessDefinitionVersion());
794          engineObj.setCreated(DO.getProcessDefinitionCreated());
795          engineObj.setState(DO.getState());
796          cus.debug(LOG_CHANNEL,"ProcessDefinition[packageId="+DO.getPackageId()+",id="+DO.getProcessDefinitionId()+" restored");
797       }
798       catch (Throwable JavaDoc tr) {
799          cus.error(LOG_CHANNEL,"Restoring of ProcessDefinition failed");
800          throw new PersistenceException
801             ("Restoring of ProcessDefinition failed", tr);
802       }
803       return engineObj;
804    }
805
806    public ProcessPersistenceInterface restoreProcess (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
807       return restore(getPersistedProcessObject(procId,ti));
808    }
809
810    protected ProcessPersistenceInterface restore (ProcessDO DO) throws PersistenceException {
811       if (DO==null) return null;
812
813       ProcessPersistenceInterface engineObj=new DODSProcess();
814       try {
815          engineObj.setId(DO.getId());
816          //engineObj.setProcessMgrName(DO.getProcessDefinition().getName());
817
engineObj.setProcessMgrName(DO.getPDefName());
818          engineObj.setName(DO.getName());
819          engineObj.setDescription(DO.getDescription());
820          engineObj.setPriority(DO.getPriority());
821          engineObj.setState(DO.getState().getName());
822          engineObj.setCreatedTime(DO.getCreated());
823          engineObj.setStartedTime(DO.getStarted());
824          engineObj.setLastStateTime(DO.getLastStateTime());
825          engineObj.setLimitTime(DO.getLimitTime());
826
827          /*if (rDO!=null) {
828             ActivityDO ar = rDO.getActivityRequester();
829             if (null != ar) {
830                engineObj.setActivityRequesterId(ar.getId());
831                engineObj.setActivityRequestersProcessId(ar.getProcess().getId());
832             }
833             ResourceDO rr = rDO.getResourceRequester();
834             if (null != rr) {
835                engineObj.setResourceRequesterId(rr.getUsername());
836             }
837             byte[] er=rDO.getExternalRequester();
838
839             if (er!=null && er.length>0) {
840                engineObj.setExternalRequester(MiscUtilities.deserialize(er));
841             }
842          }*/

843          engineObj.setActivityRequesterId(DO.getActivityRequesterId());
844          engineObj.setActivityRequestersProcessId(DO.getActivityRequesterProcessId());
845          engineObj.setResourceRequesterId(DO.getResourceRequesterId());
846          engineObj.setExternalRequesterClassName(DO.getExternalRequesterClassName());
847
848          cus.debug(LOG_CHANNEL,"Process[id="+DO.getId()+"] restored");
849       }
850       catch (Throwable JavaDoc tr) {
851          cus.error(LOG_CHANNEL,"Restoring of Process failed");
852          throw new PersistenceException
853             ("Restoring of Process "+engineObj.getId()+" failed", tr);
854       }
855       return engineObj;
856    }
857
858    public ActivityPersistenceInterface restoreActivity (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
859       return restore(getPersistedActivityObject(actId,ti));
860    }
861
862    protected ActivityPersistenceInterface restore (ActivityDO DO) throws PersistenceException {
863       if (DO==null) return null;
864
865       ActivityPersistenceInterface engineObj=new DODSActivity();
866       try {
867          engineObj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId());
868          engineObj.setActivityDefinitionId(DO.getActivityDefinitionId());
869          engineObj.setId(DO.getId());
870          engineObj.setProcessMgrName(DO.getPDefName());
871          //engineObj.setProcessId(DO.getProcess().getId());
872
engineObj.setProcessId(DO.getProcessId());
873          /*if (DO.getTheResource()!=null) {
874             engineObj.setResourceUsername(DO.getTheResource().getUsername());
875          }*/

876          engineObj.setResourceUsername(DO.getResourceId());
877
878          engineObj.setSubflowProcessId(DO.getPerformer());
879          engineObj.setSubflowAsynchronous(DO.getIsPerformerAsynchronous());
880          engineObj.setName(DO.getName());
881          engineObj.setDescription(DO.getDescription());
882          engineObj.setPriority(DO.getPriority());
883          engineObj.setState(DO.getState().getName());
884          engineObj.setLastStateTime(DO.getLastStateTime());
885          engineObj.setLimitTime(DO.getLimitTime());
886          engineObj.setAcceptedTime(DO.getAccepted());
887          engineObj.setActivatedTime(DO.getActivated());
888          /*if (DO.getBlockActivity()!=null) {
889             engineObj.setBlockActivityId(DO.getBlockActivity().getId());
890          }*/

891          engineObj.setBlockActivityId(DO.getBlockActivityId());
892          cus.debug(LOG_CHANNEL,"Activity[id="+DO.getId()+",definitionId="+DO.getActivityDefinitionId()+"] restored");
893       }
894       catch (Throwable JavaDoc tr) {
895          cus.error(LOG_CHANNEL,"Restoring of Activity failed");
896          throw new PersistenceException
897             ("Restoring of Activity failed", tr);
898       }
899       return engineObj;
900    }
901
902    public ResourcePersistenceInterface restoreResource (String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
903       return restore(getPersistedResourceObject(resUsername,ti));
904    }
905
906    protected ResourcePersistenceInterface restore (ResourceDO DO) throws PersistenceException {
907       if (DO==null) return null;
908
909       ResourcePersistenceInterface engineObj=new DODSResource();
910       try {
911          engineObj.setName(DO.getName());
912          engineObj.setUsername(DO.getUsername());
913          cus.debug(LOG_CHANNEL,"Resource[username="+DO.getUsername()+"] restored");
914       }
915       catch (Throwable JavaDoc tr) {
916          cus.error(LOG_CHANNEL,"Restoring of Resource failed");
917          throw new PersistenceException
918             ("Restoring of Resource failed", tr);
919       }
920       return engineObj;
921    }
922
923    public AssignmentPersistenceInterface restoreAssignment (String JavaDoc actId,String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
924       return restore(getPersistedAssignmentObject(actId,resUsername,ti));
925    }
926
927    protected AssignmentPersistenceInterface restore (AssignmentDO DO) throws PersistenceException {
928       if (DO==null) return null;
929
930       AssignmentPersistenceInterface engineObj=new DODSAssignment();
931       try {
932          String JavaDoc actId=DO.getActivityId();
933          String JavaDoc username=DO.getResourceId();
934          String JavaDoc processId=DO.getActivityProcessId();
935          /*engineObj.setActivityId(actId);
936          engineObj.setResourceUsername(username);
937          engineObj.setProcessId(processId);*/

938          engineObj.setActivityId(actId);
939          engineObj.setResourceUsername(username);
940          engineObj.setProcessId(processId);
941          engineObj.setProcessMgrName(DO.getActivityProcessDefName());
942          engineObj.setValid(DO.getIsValid());
943          engineObj.setAccepted(DO.getIsAccepted());
944          cus.debug(LOG_CHANNEL,"Assignment[activityId="+actId+", username="+username+"] restored");
945       }
946       catch (Throwable JavaDoc tr) {
947          cus.error(LOG_CHANNEL,"Restoring of Assignment failed");
948          throw new PersistenceException
949             ("Restoring of Assignment failed", tr);
950       }
951       return engineObj;
952    }
953
954    public boolean restore (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
955       if (usingStandardVariableDataModel) {
956          return restoreBLOB(var,getPersistedObject(var,ti));
957       } else {
958          return restoreWOB(var,getPersistedObject2(var,ti));
959       }
960    }
961
962    protected boolean restoreBLOB (ProcessVariablePersistenceInterface engineObj,
963                               ProcessDataDO DO) throws PersistenceException {
964       if (DO==null) return false;
965
966       try {
967          engineObj.setProcessId(DO.getProcess().getId());
968          engineObj.setDefinitionId(DO.getVariableDefinitionId());
969
970          short vtype=DO.getVariableType();
971          switch (vtype) {
972             case DODSPersistentManager.DB_TYPE_BOOLEAN :
973                engineObj.setValue(new Boolean JavaDoc(DO.getVariableValueBOOL()));
974                break;
975             case DODSPersistentManager.DB_TYPE_LONG:
976                engineObj.setValue(new Long JavaDoc(DO.getVariableValueLONG()));
977                break;
978             case DODSPersistentManager.DB_TYPE_DOUBLE:
979                engineObj.setValue(new Double JavaDoc(DO.getVariableValueDBL()));
980                break;
981             case DODSPersistentManager.DB_TYPE_VCHAR:
982                engineObj.setValue(DO.getVariableValueVCHAR());
983                break;
984             case DODSPersistentManager.DB_TYPE_DATE:
985                java.sql.Timestamp JavaDoc d=DO.getVariableValueDATE();
986                if (d!=null) {
987                   engineObj.setValue(new java.util.Date JavaDoc(d.getTime()));
988                } else {
989                   engineObj.setValue(null);
990                }
991                break;
992             default:
993                byte[] v=DO.getVariableValue();
994                if (v!=null && v.length>0) {
995                   engineObj.setValue(MiscUtilities.deserialize(v));
996                } else {
997                   engineObj.setValue(null);
998                }
999          }
1000
1001
1002         cus.debug(LOG_CHANNEL,"ProcessVariable[processId="+engineObj.getProcessId()+", definitionId="+engineObj.getDefinitionId()+"] restored");
1003      }
1004      catch (Throwable JavaDoc tr) {
1005         cus.error(LOG_CHANNEL,"Restoring of ProcessVariable failed");
1006         throw new PersistenceException
1007            ("Restoring of ProcessVariable failed", tr);
1008      }
1009      return true;
1010   }
1011
1012   protected boolean restoreWOB (ProcessVariablePersistenceInterface engineObj,
1013         ProcessDataWOBDO DO) throws PersistenceException {
1014
1015      if (DO==null) return false;
1016
1017      try {
1018         engineObj.setProcessId(DO.getProcess().getId());
1019         engineObj.setDefinitionId(DO.getVariableDefinitionId());
1020   
1021         short vtype=DO.getVariableType();
1022         switch (vtype) {
1023            case DODSPersistentManager.DB_TYPE_BOOLEAN :
1024               engineObj.setValue(new Boolean JavaDoc(DO.getVariableValueBOOL()));
1025               break;
1026            case DODSPersistentManager.DB_TYPE_LONG:
1027               engineObj.setValue(new Long JavaDoc(DO.getVariableValueLONG()));
1028               break;
1029            case DODSPersistentManager.DB_TYPE_DOUBLE:
1030               engineObj.setValue(new Double JavaDoc(DO.getVariableValueDBL()));
1031               break;
1032            case DODSPersistentManager.DB_TYPE_VCHAR:
1033               engineObj.setValue(DO.getVariableValueVCHAR());
1034               break;
1035            case DODSPersistentManager.DB_TYPE_DATE:
1036               java.sql.Timestamp JavaDoc d=DO.getVariableValueDATE();
1037               if (d!=null) {
1038                  engineObj.setValue(new java.util.Date JavaDoc(d.getTime()));
1039               } else {
1040                  engineObj.setValue(null);
1041               }
1042               break;
1043            default:
1044               byte[] v=DO.getProcessDataBLOBDO().getVariableValue();
1045               if (v!=null && v.length>0) {
1046                  engineObj.setValue(MiscUtilities.deserialize(v));
1047               } else {
1048                  engineObj.setValue(null);
1049               }
1050         }
1051      
1052         cus.debug(LOG_CHANNEL,"ProcessVariable[processId="+engineObj.getProcessId()+", definitionId="+engineObj.getDefinitionId()+"] restored");
1053      }
1054      catch (Throwable JavaDoc tr) {
1055         cus.error(LOG_CHANNEL,"Restoring of ProcessVariable failed");
1056         throw new PersistenceException
1057            ("Restoring of ProcessVariable failed", tr);
1058      }
1059      return true;
1060   }
1061   
1062   public boolean restore (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
1063      if (usingStandardVariableDataModel) {
1064         return restoreBLOB(var,getPersistedObject(var,ti));
1065      } else {
1066         return restoreWOB(var,getPersistedObject2(var,ti));
1067      }
1068   }
1069
1070   protected boolean restoreBLOB (ActivityVariablePersistenceInterface engineObj,
1071                              ActivityDataDO DO) throws PersistenceException {
1072      if (DO==null) return false;
1073
1074      try {
1075         engineObj.setActivityId(DO.getActivity().getId());
1076         engineObj.setDefinitionId(DO.getVariableDefinitionId());
1077
1078         short vtype=DO.getVariableType();
1079         switch (vtype) {
1080            case DODSPersistentManager.DB_TYPE_BOOLEAN :
1081               engineObj.setValue(new Boolean JavaDoc(DO.getVariableValueBOOL()));
1082               break;
1083            case DODSPersistentManager.DB_TYPE_LONG:
1084               engineObj.setValue(new Long JavaDoc(DO.getVariableValueLONG()));
1085               break;
1086            case DODSPersistentManager.DB_TYPE_DOUBLE:
1087               engineObj.setValue(new Double JavaDoc(DO.getVariableValueDBL()));
1088               break;
1089            case DODSPersistentManager.DB_TYPE_VCHAR:
1090               engineObj.setValue(DO.getVariableValueVCHAR());
1091               break;
1092            case DODSPersistentManager.DB_TYPE_DATE:
1093               java.sql.Timestamp JavaDoc d=DO.getVariableValueDATE();
1094               if (d!=null) {
1095                  engineObj.setValue(new java.util.Date JavaDoc(d.getTime()));
1096               } else {
1097                  engineObj.setValue(null);
1098               }
1099               break;
1100            default:
1101               byte[] v=DO.getVariableValue();
1102               if (v!=null && v.length>0) {
1103                  engineObj.setValue(MiscUtilities.deserialize(v));
1104               } else {
1105                  engineObj.setValue(null);
1106               }
1107         }
1108
1109         engineObj.setResultVariable(DO.getIsResult());
1110         cus.debug(LOG_CHANNEL,"ActivityVariable[activityId="+engineObj.getActivityId()+", definitionId="+engineObj.getDefinitionId()+"] restored");
1111      }
1112      catch (Throwable JavaDoc tr) {
1113         cus.error(LOG_CHANNEL,"Restoring of Variable failed");
1114         throw new PersistenceException
1115            ("Restoring of Variable failed", tr);
1116      }
1117      return true;
1118   }
1119
1120   protected boolean restoreWOB (ActivityVariablePersistenceInterface engineObj,
1121         ActivityDataWOBDO DO) throws PersistenceException {
1122      if (DO==null) return false;
1123      try {
1124         engineObj.setActivityId(DO.getActivity().getId());
1125         engineObj.setDefinitionId(DO.getVariableDefinitionId());
1126
1127         short vtype=DO.getVariableType();
1128         switch (vtype) {
1129            case DODSPersistentManager.DB_TYPE_BOOLEAN :
1130               engineObj.setValue(new Boolean JavaDoc(DO.getVariableValueBOOL()));
1131               break;
1132            case DODSPersistentManager.DB_TYPE_LONG:
1133               engineObj.setValue(new Long JavaDoc(DO.getVariableValueLONG()));
1134               break;
1135            case DODSPersistentManager.DB_TYPE_DOUBLE:
1136               engineObj.setValue(new Double JavaDoc(DO.getVariableValueDBL()));
1137               break;
1138            case DODSPersistentManager.DB_TYPE_VCHAR:
1139               engineObj.setValue(DO.getVariableValueVCHAR());
1140               break;
1141            case DODSPersistentManager.DB_TYPE_DATE:
1142               java.sql.Timestamp JavaDoc d=DO.getVariableValueDATE();
1143               if (d!=null) {
1144                  engineObj.setValue(new java.util.Date JavaDoc(d.getTime()));
1145               } else {
1146                  engineObj.setValue(null);
1147               }
1148               break;
1149            default:
1150               byte[] v=DO.getActivityDataBLOBDO().getVariableValue();
1151               if (v!=null && v.length>0) {
1152                  engineObj.setValue(MiscUtilities.deserialize(v));
1153               } else {
1154                  engineObj.setValue(null);
1155               }
1156         }
1157
1158         engineObj.setResultVariable(DO.getIsResult());
1159         cus.debug(LOG_CHANNEL,"ActivityVariable[activityId="+engineObj.getActivityId()+", definitionId="+engineObj.getDefinitionId()+"] restored");
1160      }
1161      catch (Throwable JavaDoc tr) {
1162         cus.error(LOG_CHANNEL,"Restoring of Variable failed");
1163         throw new PersistenceException
1164            ("Restoring of Variable failed", tr);
1165      }
1166      return true;
1167   }
1168   
1169   public void deleteProcessMgr (String JavaDoc mgrName,SharkTransaction ti) throws PersistenceException {
1170      try {
1171         ProcessDefinitionDO DO=getPersistedProcessMgrObject(mgrName,ti);
1172         if (DO.getProcessDOArrayCount()>0) return;
1173         ((SharkDODSTransaction)ti).erase(DO);
1174         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1175
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1176
cus.info(LOG_CHANNEL,"ProcessDefinition[name="+mgrName+"] deleted");
1177      } catch (Throwable JavaDoc tr) {
1178         cus.error(LOG_CHANNEL,"Deleting of ProcessDefinition failed");
1179         throw new PersistenceException
1180            ("Deleting of ProcessDefinition failed", tr);
1181      }
1182   }
1183
1184   public void deleteProcess (String JavaDoc procId,boolean administrative,SharkTransaction ti) throws PersistenceException {
1185      if (!deleteFinishedProcesses && !administrative) return;
1186      try {
1187         Set procIds=new HashSet();
1188         performCascadeDeletion(procId,procIds,(SharkDODSTransaction)ti);
1189         procIds.remove(procId);
1190         cus.info(LOG_CHANNEL,"Main Process[id="+procId+"] deleted");
1191         cus.info(LOG_CHANNEL,"Sub-Processes "+procIds+"] deleted");
1192// System.out.println("Process[id="+procId+"] deleted");
1193
// System.out.println("Subprocesses "+procIds+"] deleted");
1194
} catch (Throwable JavaDoc tr) {
1195         cus.error(LOG_CHANNEL,"Deleting of Process failed");
1196         throw new PersistenceException
1197            ("Deleting of Process failed", tr);
1198      }
1199   }
1200
1201   protected void performCascadeDeletion (String JavaDoc procId,Set procIds,SharkDODSTransaction ti) throws Exception JavaDoc {
1202      ProcessDO pDO=getPersistedProcessObject(procId,ti);
1203      ProcessRequesterDO pReqDO=getPersistedRequesterObject(procId,ti);
1204      ((SharkDODSTransaction)ti).erase(pDO);
1205      ((SharkDODSTransaction)ti).erase(pReqDO);
1206      if (pDO==null) {
1207// System.out.println("PRoc "+procId+" can't be found!");
1208
return;
1209      }
1210      procIds.add(procId);
1211      performCascadeErasageFromBuffer(pDO,procIds,(SharkDODSTransaction)ti);
1212// if (true) return;
1213
String JavaDoc SQLWHERE="Activities.Process="+pDO.get_Handle()+" AND Activities.Performer IS NOT NULL"; //AND Activities.IsPerformerAsynchronous='false'";;
1214
ActivityQuery query=new ActivityQuery(ti.getDODSTransaction());
1215      QueryBuilder qb=qb=query.getQueryBuilder();
1216      qb.addWhere(SQLWHERE);
1217// System.out.println("SQLWP="+qb.getSQLwithParms());
1218
ActivityDO[] DOs = query.getDOArray();
1219      Set deleteFurther=new HashSet();
1220      if (DOs!=null) {
1221         for (int i=0;i<DOs.length; i++) {
1222            if (!DOs[i].getIsPerformerAsynchronous()) {
1223               deleteFurther.add(DOs[i].getPerformer());
1224            }
1225         }
1226      }
1227      deleteFurther.removeAll(procIds);
1228// System.out.println("Further deleting subprocesses "+deleteFurther+" for process "+procId);
1229
Iterator it=deleteFurther.iterator();
1230      while (it.hasNext()) {
1231         String JavaDoc fpid=(String JavaDoc)it.next();
1232         performCascadeDeletion(fpid, procIds, ti);
1233      }
1234      
1235   }
1236   
1237   protected void performCascadeErasageFromBuffer (ProcessDO pDO,Set procIds,SharkDODSTransaction sdt) throws Exception JavaDoc {
1238      try {
1239//System.out.println("PCEFB for "+pDO);
1240
BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1241         Set actOIdsToRemove=new HashSet();
1242         Set procIdsToRemove=new HashSet();
1243         Set toRemove=new HashSet();
1244         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO");
1245              it.hasNext();) {
1246            ActivityDO o = (ActivityDO)it.next();
1247            if (pOId.equals(o.oid_getProcess())) {
1248               toRemove.add(o);
1249               actOIdsToRemove.add(o.get_OId().toBigDecimal());
1250               if (o.getPerformer()!=null && !o.getIsPerformerAsynchronous()) {
1251                  procIdsToRemove.add(o.getPerformer());
1252               }
1253            }
1254         }
1255         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
1256              it.hasNext();) {
1257            ProcessDataDO o = (ProcessDataDO)it.next();
1258            if (pOId.equals(o.oid_getProcess())) {
1259               toRemove.add(o);
1260            }
1261         }
1262         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
1263              it.hasNext();) {
1264            DeadlineDO o = (DeadlineDO)it.next();
1265            if (pOId.equals(o.oid_getProcess())) {
1266               toRemove.add(o);
1267            }
1268         }
1269         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO");
1270              it.hasNext();) {
1271            AndJoinEntryDO o = (AndJoinEntryDO)it.next();
1272            if (pOId.equals(o.oid_getProcess())) {
1273               toRemove.add(o);
1274            }
1275         }
1276
1277         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1278              it.hasNext();) {
1279            AssignmentDO o = (AssignmentDO)it.next();
1280            if (actOIdsToRemove.contains(o.oid_getActivity())) {
1281               toRemove.add(o);
1282            }
1283         }
1284         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
1285              it.hasNext();) {
1286            ActivityDataDO o = (ActivityDataDO)it.next();
1287            if (actOIdsToRemove.contains(o.oid_getActivity())) {
1288               toRemove.add(o);
1289            }
1290         }
1291         for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
1292              it.hasNext();) {
1293            ProcessRequesterDO o = (ProcessRequesterDO)it.next();
1294            if (actOIdsToRemove.contains(o.oid_getActivityRequester()) || o.getId().equals(pDO.getId())) {
1295               toRemove.add(o);
1296            }
1297         }
1298         sdt.erase(toRemove);
1299         Iterator it=procIdsToRemove.iterator();
1300         while (it.hasNext()) {
1301            performCascadeDeletion((String JavaDoc)it.next(), procIds, sdt);
1302         }
1303      } catch (Throwable JavaDoc tr) {
1304         throw new PersistenceException("Problems while performing cascade deletion from Buffer",tr);
1305      }
1306   }
1307
1308   public void deleteActivity (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
1309      // NEVER DELETE ACTIVITIES
1310
if (true) return;
1311      try {
1312         ActivityDO DO=getPersistedActivityObject(actId,ti);
1313         DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1314         (((SharkDODSTransaction)ti).getDODSTransaction()).write();
1315         cus.info(LOG_CHANNEL,"Activity[id="+actId+"] deleted");
1316      } catch (Throwable JavaDoc tr) {
1317         cus.error(LOG_CHANNEL,"Deleting of Activity failed");
1318         throw new PersistenceException
1319            ("Deleting of Activity failed", tr);
1320      }
1321   }
1322
1323   public void deleteResource (String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
1324      // NEVER DELETE RESOURCES
1325
if (true) return;
1326      try {
1327         ResourceDO DO=getPersistedResourceObject(resUsername,ti);
1328         DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1329         (((SharkDODSTransaction)ti).getDODSTransaction()).write();
1330         cus.info(LOG_CHANNEL,"Resource[username="+resUsername+"] deleted");
1331      } catch (Throwable JavaDoc tr) {
1332         cus.error(LOG_CHANNEL,"Deleting of Resource failed");
1333         throw new PersistenceException
1334            ("Deleting of Resource failed", tr);
1335      }
1336   }
1337
1338   public void deleteAssignment(String JavaDoc actId,String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
1339      //if (!delete) return;
1340
try {
1341         AssignmentDO DO=getPersistedAssignmentObject(actId,resUsername,ti);
1342         ((SharkDODSTransaction)ti).erase(DO);
1343         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1344
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1345
cus.info(LOG_CHANNEL,"Assignment[activityId="+actId+", username="+resUsername+"] deleted");
1346      } catch (Throwable JavaDoc tr) {
1347         cus.error(LOG_CHANNEL,"Deleting of Assignment failed");
1348         throw new PersistenceException
1349            ("Deleting of Assignment failed", tr);
1350      }
1351   }
1352
1353   public void deleteAndJoinEntries (String JavaDoc procId,
1354                                     String JavaDoc asDefId,
1355                                     String JavaDoc aDefId,
1356                                     SharkTransaction ti) throws PersistenceException {
1357      try {
1358         AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti);
1359         if (DOs!=null) {
1360            for (int i=0; i<DOs.length; i++) {
1361               ((SharkDODSTransaction)ti).erase(DOs[i]);
1362               //DOs[i].delete(((SharkDODSTransaction)ti).getDODSTransaction());
1363
}
1364            cus.info(LOG_CHANNEL,"AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] deleted");
1365         } else {
1366            cus.info(LOG_CHANNEL,"There are no AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] to delete");
1367         }
1368         //(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1369
} catch (Throwable JavaDoc tr) {
1370         cus.error(LOG_CHANNEL,"Deleting of AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] failed");
1371         throw new PersistenceException
1372            ("Deleting of AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] failed", tr);
1373      }
1374
1375   }
1376
1377   public void deleteDeadlines (String JavaDoc procId,
1378                                SharkTransaction ti) throws PersistenceException {
1379      if (true) return;
1380      try {
1381         DeadlineDO[] DOs=getPersistedDeadlines(procId,-1,ti);
1382         if (DOs!=null) {
1383            for (int i=0; i<DOs.length; i++) {
1384               ((SharkDODSTransaction)ti).erase(DOs[i]);
1385               //DOs[i].delete(((SharkDODSTransaction)ti).getDODSTransaction());
1386
}
1387            cus.info(LOG_CHANNEL,"Deadlines for process "+procId+" deleted");
1388         } else {
1389            cus.info(LOG_CHANNEL,"There are no Deadlines defined for the proces "+procId);
1390         }
1391         //(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1392
} catch (Throwable JavaDoc tr) {
1393         cus.error(LOG_CHANNEL,"Deleting deadlines for the process "+procId+" failed");
1394         throw new PersistenceException
1395            ("Deleting deadlines for the process "+procId+" failed", tr);
1396      }
1397   }
1398
1399   public void deleteDeadlines (String JavaDoc procId,
1400                                String JavaDoc actId,
1401                                SharkTransaction ti) throws PersistenceException {
1402      if (true) return;
1403      try {
1404         DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,-1,ti);
1405         if (DOs!=null) {
1406            for (int i=0; i<DOs.length; i++) {
1407               ((SharkDODSTransaction)ti).erase(DOs[i]);
1408               //DOs[i].delete(((SharkDODSTransaction)ti).getDODSTransaction());
1409
}
1410            cus.info(LOG_CHANNEL,"Deadlines for activity "+actId+" deleted");
1411         } else {
1412            cus.info(LOG_CHANNEL,"There are no Deadlines defined for the activity "+actId);
1413         }
1414         //(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1415
} catch (Throwable JavaDoc tr) {
1416         cus.error(LOG_CHANNEL,"Deleting deadlines for the activity "+actId+" failed");
1417         throw new PersistenceException
1418            ("Deleting deadlines for the activity "+actId+" failed", tr);
1419      }
1420   }
1421
1422   public void delete (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
1423      // NEVER DELETE PROCESS VARIABLES
1424
if (true) return;
1425      try {
1426         ProcessDataDO DO=getPersistedObject(var,ti);
1427         DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1428         (((SharkDODSTransaction)ti).getDODSTransaction()).write();
1429         cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] deleted");
1430      } catch (Throwable JavaDoc tr) {
1431         cus.error(LOG_CHANNEL,"Deleting of ProcessVariable failed");
1432         throw new PersistenceException
1433            ("Deleting of ProcessVariable failed", tr);
1434      }
1435   }
1436
1437   public void delete (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
1438      // NEVER DELETE ACTIVITY VARIABLES
1439
if (true) return;
1440      try {
1441         ActivityDataDO DO=getPersistedObject(var,ti);
1442         DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1443         (((SharkDODSTransaction)ti).getDODSTransaction()).write();
1444         cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] deleted");
1445      } catch (Throwable JavaDoc tr) {
1446         cus.error(LOG_CHANNEL,"Deleting of ActivityVariable failed");
1447         throw new PersistenceException
1448            ("Deleting of ActivityVariable failed", tr);
1449      }
1450   }
1451
1452   public List getAllProcessMgrs (SharkTransaction ti) throws PersistenceException {
1453      List ret=new ArrayList();
1454
1455      ProcessDefinitionDO[] mgrs=getAllPersistedProcessMgrs(ti,null,null,null,null);
1456      if (mgrs!=null) {
1457         for (int i=0;i<mgrs.length; i++) {
1458            ProcessMgrPersistenceInterface mgr=restore(mgrs[i]);
1459            ret.add(mgr);
1460         }
1461      }
1462      return ret;
1463   }
1464
1465   public List getAllProcesses (SharkTransaction ti) throws PersistenceException {
1466      List ret=new ArrayList();
1467
1468      ProcessDO[] procs=getPersistedProcesses(ti,0,null,null,null,null,null);
1469      try {
1470         if (procs!=null) {
1471            for (int i=0;i<procs.length; i++) {
1472               ProcessPersistenceInterface proc=restore(procs[i]);
1473               ret.add(proc);
1474            }
1475         }
1476         return ret;
1477      } catch (Throwable JavaDoc e) {
1478         throw new PersistenceException(e);
1479      }
1480   }
1481
1482   public List getAllRunningProcesses(SharkTransaction ti) throws PersistenceException {
1483      List ret=new ArrayList();
1484
1485      ProcessDO[] procs=getPersistedProcesses(ti,1,null,null,null,null,null);
1486      try {
1487         if (procs!=null) {
1488            for (int i=0;i<procs.length; i++) {
1489               ProcessPersistenceInterface proc=restore(procs[i]);
1490               ret.add(proc);
1491            }
1492         }
1493         return ret;
1494      } catch (Throwable JavaDoc e) {
1495         throw new PersistenceException(e);
1496      }
1497   }
1498
1499   public List getAllFinishedProcesses(SharkTransaction ti) throws PersistenceException {
1500      List ret=new ArrayList();
1501
1502      ProcessDO[] procs=getPersistedProcesses(ti,-1,null,null,null,null,null);
1503      try {
1504         if (procs!=null) {
1505            for (int i=0;i<procs.length; i++) {
1506               ProcessPersistenceInterface proc=restore(procs[i]);
1507               ret.add(proc);
1508            }
1509         }
1510         return ret;
1511      } catch (Throwable JavaDoc e) {
1512         throw new PersistenceException(e);
1513      }
1514   }
1515
1516   public List getAllFinishedProcesses(SharkTransaction ti,java.util.Date JavaDoc finishedBefore) throws PersistenceException {
1517      List ret=new ArrayList();
1518
1519      ProcessDO[] procs=getPersistedProcesses(ti,-1,null,null,null,finishedBefore,null);
1520      try {
1521         if (procs!=null) {
1522            for (int i=0;i<procs.length; i++) {
1523               ProcessPersistenceInterface proc=restore(procs[i]);
1524               ret.add(proc);
1525            }
1526         }
1527         return ret;
1528      } catch (Throwable JavaDoc e) {
1529         throw new PersistenceException(e);
1530      }
1531   }
1532
1533   public List getAllFinishedProcesses(SharkTransaction ti,String JavaDoc pkgId) throws PersistenceException {
1534      List ret=new ArrayList();
1535
1536      ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,null,null,null,null);
1537      try {
1538         if (procs!=null) {
1539            for (int i=0;i<procs.length; i++) {
1540               ProcessPersistenceInterface proc=restore(procs[i]);
1541               ret.add(proc);
1542            }
1543         }
1544         return ret;
1545      } catch (Throwable JavaDoc e) {
1546         throw new PersistenceException(e);
1547      }
1548   }
1549
1550   public List getAllFinishedProcesses(SharkTransaction ti,String JavaDoc pkgId,String JavaDoc procDefId) throws PersistenceException {
1551      List ret=new ArrayList();
1552
1553      ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,procDefId,null,null,null);
1554      try {
1555         if (procs!=null) {
1556            for (int i=0;i<procs.length; i++) {
1557               ProcessPersistenceInterface proc=restore(procs[i]);
1558               ret.add(proc);
1559            }
1560         }
1561         return ret;
1562      } catch (Throwable JavaDoc e) {
1563         throw new PersistenceException(e);
1564      }
1565   }
1566
1567   public List getAllFinishedProcesses(SharkTransaction ti,String JavaDoc pkgId,String JavaDoc procDefId,String JavaDoc pkgVer) throws PersistenceException {
1568      List ret=new ArrayList();
1569
1570      ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,procDefId,pkgVer,null,null);
1571      try {
1572         if (procs!=null) {
1573            for (int i=0;i<procs.length; i++) {
1574               ProcessPersistenceInterface proc=restore(procs[i]);
1575               ret.add(proc);
1576            }
1577         }
1578         return ret;
1579      } catch (Throwable JavaDoc e) {
1580         throw new PersistenceException(e);
1581      }
1582   }
1583
1584   public List getAllActivities (SharkTransaction ti) throws PersistenceException {
1585      List ret=new ArrayList();
1586
1587      ActivityDO[] acts=getPersistedActivities(ti,0,null,null);
1588      if (acts!=null) {
1589         for (int i=0;i<acts.length; i++) {
1590            ActivityPersistenceInterface act=restore(acts[i]);
1591            ret.add(act);
1592         }
1593      }
1594      return ret;
1595   }
1596
1597   public List getAllResources (SharkTransaction ti) throws PersistenceException {
1598      List ret=new ArrayList();
1599
1600      ResourceDO[] ress=getAllPersistedResources(ti, null);
1601      if (ress!=null) {
1602         for (int i=0;i<ress.length; i++) {
1603            ResourcePersistenceInterface res=restore(ress[i]);
1604            ret.add(res);
1605         }
1606      }
1607      return ret;
1608   }
1609
1610   public List getAllAssignments (SharkTransaction ti) throws PersistenceException {
1611      List ret=new ArrayList();
1612
1613      AssignmentDO[] ass=getAllPersistedAssignments(ti,null);
1614      if (ass!=null) {
1615         for (int i=0;i<ass.length; i++) {
1616            AssignmentPersistenceInterface as=restore(ass[i]);
1617            ret.add(as);
1618         }
1619      }
1620      return ret;
1621   }
1622
1623   public List getAllProcessesForMgr (String JavaDoc mgrName,SharkTransaction ti) throws PersistenceException {
1624      List ret=new ArrayList();
1625
1626      try {
1627         ProcessDefinitionDO pDO=getPersistedProcessMgrObject(mgrName,ti);
1628         if (pDO!=null) {
1629            ProcessDO[] procs=pDO.getProcessDOArray();
1630            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1631            List list = new ArrayList(Arrays.asList(procs));
1632
1633            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO");
1634                 it.hasNext();) {
1635               ProcessDO o = (ProcessDO)it.next();
1636               if (pOId.equals(o.oid_getProcessDefinition())) {
1637                  int index = list.indexOf(o);
1638                  if (-1 != index)
1639                     list.remove(o);
1640               }
1641            }
1642            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO");
1643                 it.hasNext();) {
1644               ProcessDO o = (ProcessDO)it.next();
1645               if (pOId.equals(o.oid_getProcessDefinition())) {
1646                  int index = list.indexOf(o);
1647                  if (-1 == index)
1648                     list.add(o);
1649                  else {
1650                     list.set(index, o);
1651                  }
1652               }
1653            }
1654            procs = new ProcessDO[list.size()];
1655            list.toArray(procs);
1656            for (int j=0; j<procs.length; j++) {
1657               ProcessPersistenceInterface proc=restore(procs[j]);
1658               ret.add(proc);
1659            }
1660         }
1661         return ret;
1662      }
1663      catch (Throwable JavaDoc t) {
1664         throw new PersistenceException(t);
1665      }
1666   }
1667
1668   public List getProcessesForMgr (String JavaDoc mgrName,String JavaDoc procState,SharkTransaction ti) throws PersistenceException {
1669      List ret=new ArrayList();
1670
1671      ProcessDO[] DOs=null;
1672      ProcessQuery query = null;
1673      try {
1674         query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1675         BigDecimal JavaDoc state=(BigDecimal JavaDoc)_prStates.get(procState);
1676         QueryBuilder qb=qb=query.getQueryBuilder();
1677         qb.addWhere(ProcessDO.State,state,QueryBuilder.EQUAL);
1678         DOs = query.getDOArray();
1679         List list = new ArrayList(Arrays.asList(DOs));
1680
1681         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO");
1682              it.hasNext();) {
1683            list.remove(it.next());
1684         }
1685         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO");
1686              it.hasNext();) {
1687            ProcessDO o = (ProcessDO)it.next();
1688            boolean stateOK=o.oid_getState().equals(state);
1689            int index = list.indexOf(o);
1690            if (-1 == index) {
1691               if (stateOK) {
1692                  list.add(o);
1693               }
1694            } else {
1695               if (stateOK) {
1696                  list.set(index, o);
1697               } else {
1698                  list.remove(o);
1699               }
1700            }
1701         }
1702         DOs = new ProcessDO[list.size()];
1703         list.toArray(DOs);
1704         for (int j=0; j<DOs.length; j++) {
1705            ProcessPersistenceInterface proc=restore(DOs[j]);
1706            ret.add(proc);
1707         }
1708
1709         return ret;
1710      } catch (Throwable JavaDoc t) {
1711         throw new PersistenceException(t);
1712      }
1713   }
1714
1715   public List getAllActivitiesForProcess(String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
1716      List ret=new ArrayList();
1717
1718      try {
1719         ProcessDO pDO=getPersistedProcessObject(procId,ti);
1720         if (pDO!=null) {
1721            ActivityDO[] acts=pDO.getActivityDOArray();
1722            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1723            List list = new ArrayList(Arrays.asList(acts));
1724
1725            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO");
1726                 it.hasNext();) {
1727               ActivityDO o = (ActivityDO)it.next();
1728               if (pOId.equals(o.oid_getProcess())) {
1729                  int index = list.indexOf(o);
1730                  if (-1 != index)
1731                     list.remove(o);
1732               }
1733            }
1734            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO");
1735                 it.hasNext();) {
1736               ActivityDO o = (ActivityDO)it.next();
1737               if (pOId.equals(o.oid_getProcess())) {
1738                  int index = list.indexOf(o);
1739                  if (-1 == index)
1740                     list.add(o);
1741                  else {
1742                     list.set(index, o);
1743                  }
1744               }
1745            }
1746            acts = new ActivityDO[list.size()];
1747            list.toArray(acts);
1748            for (int j=0; j<acts.length; j++) {
1749               //System.err.println("getAllActivitiesForProcess:"+acts[j].getId()+"("+acts[j].getState().getKeyValue()+", "+acts[j].isVirgin()+")"+ti);
1750
ActivityPersistenceInterface act=restore(acts[j]);
1751               ret.add(act);
1752            }
1753         }
1754         return ret;
1755      }
1756      catch (Throwable JavaDoc t) {
1757         throw new PersistenceException(t);
1758      }
1759   }
1760
1761   public List getActivitiesForProcess(String JavaDoc procId,String JavaDoc actState,SharkTransaction ti) throws PersistenceException {
1762      List ret=new ArrayList();
1763      try {
1764         ProcessDO pDO=getPersistedProcessObject(procId,ti);
1765         BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1766         BigDecimal JavaDoc state=(BigDecimal JavaDoc)_acStates.get(actState);
1767
1768         ActivityDO[] DOs=null;
1769         ActivityQuery query = null;
1770         query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1771         QueryBuilder qb=qb=query.getQueryBuilder();
1772
1773         qb.addWhere(ActivityDO.Process,pOId,QueryBuilder.EQUAL);
1774         qb.addWhere(ActivityDO.State,state,QueryBuilder.EQUAL);
1775         DOs = query.getDOArray();
1776         List list = new ArrayList(Arrays.asList(DOs));
1777         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO");
1778              it.hasNext();) {
1779            list.remove(it.next());
1780         }
1781         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO");
1782              it.hasNext();) {
1783            ActivityDO o = (ActivityDO)it.next();
1784            boolean stateOK=o.oid_getState().equals(state);
1785            int index = list.indexOf(o);
1786            if (-1 == index) {
1787               if (stateOK) {
1788                  list.add(o);
1789               }
1790            } else {
1791               if (stateOK) {
1792                  list.set(index, o);
1793               } else {
1794                  list.remove(o);
1795               }
1796            }
1797         }
1798         DOs = new ActivityDO[list.size()];
1799         list.toArray(DOs);
1800         for (int j=0; j<DOs.length; j++) {
1801            ActivityPersistenceInterface act=restore(DOs[j]);
1802            ret.add(act);
1803         }
1804
1805         return ret;
1806      }
1807      catch (Throwable JavaDoc t) {
1808         throw new PersistenceException(t);
1809      }
1810
1811   }
1812
1813   public List getAllFinishedActivitiesForProcess(String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
1814      List ret=new ArrayList();
1815
1816      try {
1817         ProcessDO pDO=getPersistedProcessObject(procId,ti);
1818         if (pDO!=null) {
1819            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1820            ActivityDO[] acts=getPersistedActivities(ti,-1,pOId,null);
1821
1822            if (acts!=null) {
1823               for (int j=0; j<acts.length; j++) {
1824                  //System.err.println("getAllActivitiesForProcess:"+acts[j].getId()+"("+acts[j].getState().getKeyValue()+", "+acts[j].isVirgin()+")"+ti);
1825
ActivityPersistenceInterface act=restore(acts[j]);
1826                  ret.add(act);
1827               }
1828            }
1829         }
1830         return ret;
1831      }
1832      catch (Throwable JavaDoc t) {
1833         throw new PersistenceException(t);
1834      }
1835   }
1836
1837
1838   public List getAllActiveActivitiesForProcess(String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
1839      List ret=new ArrayList();
1840
1841      try {
1842         ProcessDO pDO=getPersistedProcessObject(procId,ti);
1843         if (pDO!=null) {
1844            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
1845            ActivityDO[] acts=getPersistedActivities(ti,1,pOId,null);
1846
1847            if (acts!=null) {
1848               for (int j=0; j<acts.length; j++) {
1849                  //System.err.println("getAllActivitiesForProcess:"+acts[j].getId()+"("+acts[j].getState().getKeyValue()+", "+acts[j].isVirgin()+")"+ti);
1850
ActivityPersistenceInterface act=restore(acts[j]);
1851                  ret.add(act);
1852               }
1853            }
1854         }
1855         return ret;
1856      }
1857      catch (Throwable JavaDoc t) {
1858         throw new PersistenceException(t);
1859      }
1860   }
1861
1862   /**
1863    * Returns all assignments for the resource, no matter if its activity
1864    * is in "closed" state (or some of its sub-states).
1865    */

1866   public List getAllAssignmentsForResource (String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
1867      List ret=new ArrayList();
1868
1869      try {
1870         // restore all assignments
1871
ResourceDO rDO=getPersistedResourceObject(resUsername,ti);
1872         if (rDO!=null) {
1873            AssignmentDO[] ass=rDO.getAssignmentDOArray();
1874            BigDecimal JavaDoc rOId = rDO.get_OId().toBigDecimal();
1875            List list = new ArrayList(Arrays.asList(ass));
1876
1877            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1878                 it.hasNext();) {
1879               AssignmentDO o = (AssignmentDO)it.next();
1880               if (rOId.equals(o.oid_getTheResource())) {
1881                  int index = list.indexOf(o);
1882                  if (-1 != index)
1883                     list.remove(o);
1884               }
1885            }
1886            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1887                 it.hasNext();) {
1888               AssignmentDO o = (AssignmentDO)it.next();
1889               if (rOId.equals(o.oid_getTheResource())) {
1890                  int index = list.indexOf(o);
1891                  if (-1 == index)
1892                     list.add(o);
1893                  else {
1894                     list.set(index, o);
1895                  }
1896               }
1897            }
1898            ass = new AssignmentDO[list.size()];
1899            list.toArray(ass);
1900            for (int i=0;i<ass.length; i++) {
1901               AssignmentDO assDO=ass[i];
1902               AssignmentPersistenceInterface as=restore(assDO);
1903               ret.add(as);
1904            }
1905         }
1906         return ret;
1907      }
1908      catch (Throwable JavaDoc t) {
1909         throw new PersistenceException(t);
1910      }
1911   }
1912
1913   /**
1914    * Returns all assignments which activity is not in "closed" state, or some
1915    * of its sub-states.
1916    */

1917   /*public List getAllAssignmentsForNotClosedActivitiesForResource (String resUsername,SharkTransaction ti) throws PersistenceException {
1918      List ret=new ArrayList();
1919
1920      try {
1921         // restore all assignments
1922         ResourceDO rDO=getPersistedResourceObject(resUsername,ti);
1923         if (rDO!=null) {
1924            AssignmentDO[] ass=rDO.getAssignmentDOArray();
1925            BigDecimal rOId = rDO.get_OId().toBigDecimal();
1926            List list = new ArrayList(Arrays.asList(ass));
1927
1928            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1929                 it.hasNext();) {
1930               AssignmentDO o = (AssignmentDO)it.next();
1931               if (rOId.equals(o.oid_getTheResource())) {
1932                  int index = list.indexOf(o);
1933                  if (-1 != index)
1934                     list.remove(o);
1935               }
1936            }
1937            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1938                 it.hasNext();) {
1939               AssignmentDO o = (AssignmentDO)it.next();
1940               if (rOId.equals(o.oid_getTheResource())) {
1941                  int index = list.indexOf(o);
1942                  if (-1 == index)
1943                     list.add(o);
1944                  else {
1945                     list.set(index, o);
1946                  }
1947               }
1948            }
1949            ass = new AssignmentDO[list.size()];
1950            list.toArray(ass);
1951            for (int i=0;i<ass.length; i++) {
1952               AssignmentDO assDO=ass[i];
1953               String state=assDO.getActivity().getState().getKeyValue();
1954               // restore assignment
1955               if (!state.startsWith("closed")) {
1956                  AssignmentPersistenceInterface as=restore(assDO);
1957                  ret.add(as);
1958               }
1959            }
1960         }
1961         return ret;
1962      }
1963      catch (Throwable t) {
1964         throw new PersistenceException(t);
1965      }
1966   }*/

1967
1968   /**
1969    * Returns only the assignments that can be currently executed by the resource
1970    * with a given username. This means the ones which activity is not finished
1971    * and not accepted (it doesn't have TheResource field set), and the ones
1972    * which activity is accepted by this resource (its TheResource field is set
1973    * to the resource with given username).
1974    */

1975   public List getAllValidAssignmentsForResource (String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
1976      List ret=new ArrayList();
1977
1978      try {
1979         // restore all assignments
1980
ResourceDO rDO=getPersistedResourceObject(resUsername,ti);
1981         if (rDO!=null) {
1982            AssignmentDO[] ass=rDO.getAssignmentDOArray();
1983            BigDecimal JavaDoc rOId = rDO.get_OId().toBigDecimal();
1984            List list = new ArrayList(Arrays.asList(ass));
1985
1986            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1987                 it.hasNext();) {
1988               AssignmentDO o = (AssignmentDO)it.next();
1989               //if (rOId.equals(o.getResourceId())) {
1990
if (rOId.equals(o.oid_getTheResource())) {
1991                  int index = list.indexOf(o);
1992                  if (-1 != index)
1993                     list.remove(o);
1994               }
1995            }
1996            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
1997                 it.hasNext();) {
1998               AssignmentDO o = (AssignmentDO)it.next();
1999               if (rOId.equals(o.oid_getTheResource()) && o.getIsValid()) {
2000                  int index = list.indexOf(o);
2001                  if (-1 == index)
2002                     list.add(o);
2003                  else {
2004                     list.set(index, o);
2005                  }
2006               }
2007            }
2008            ass = new AssignmentDO[list.size()];
2009            list.toArray(ass);
2010            for (int i=0;i<ass.length; i++) {
2011               AssignmentDO assDO=ass[i];
2012               //ActivityDO actDO=assDO.getActivity();
2013
/*if (assDO==null) {
2014                System.out.println("ASSDO is null");
2015                } else if (assDO.getActivity()==null) {
2016                System.out.println("ASSDOACT for ass "+assDO+" is null and is"+(assDO.isVirgin()?"":"n't")+" virgin.");
2017                }*/

2018               //BigDecimal arOId=actDO.oid_getTheResource();
2019
//String state=actDO.getState().getKeyValue();
2020
//if (!state.startsWith("closed") && (arOId==null || rOId.equals(arOId))) {
2021
if (assDO.getIsValid()) {
2022                  AssignmentPersistenceInterface as=restore(assDO);
2023                  ret.add(as);
2024               }
2025            }
2026         }
2027         return ret;
2028      }
2029      catch (Throwable JavaDoc t) {
2030         throw new PersistenceException(t);
2031      }
2032   }
2033
2034   /**
2035    * Returns all assignments that are ever created for that activity, no
2036    * matter if activity is already in "closed" state or some of its sub-states.
2037    */

2038   public List getAllAssignmentsForActivity (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
2039      List ret=new ArrayList();
2040      try {
2041         // restore all assignments
2042
ActivityDO aDO=getPersistedActivityObject(actId,ti);
2043         if (aDO!=null) {
2044            AssignmentDO[] ass=aDO.getAssignmentDOArray();
2045            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2046            List list = new ArrayList(Arrays.asList(ass));
2047
2048            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2049                 it.hasNext();) {
2050               AssignmentDO o = (AssignmentDO)it.next();
2051               if (aOId.equals(o.oid_getActivity())) {
2052                  int index = list.indexOf(o);
2053                  if (-1 != index)
2054                     list.remove(o);
2055               }
2056            }
2057            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2058                 it.hasNext();) {
2059               AssignmentDO o = (AssignmentDO)it.next();
2060               if (aOId.equals(o.oid_getActivity())) {
2061                  int index = list.indexOf(o);
2062                  if (-1 == index)
2063                     list.add(o);
2064                  else {
2065                     list.set(index, o);
2066                  }
2067               }
2068            }
2069            ass = new AssignmentDO[list.size()];
2070            list.toArray(ass);
2071            for (int i=0;i<ass.length; i++) {
2072               AssignmentDO assDO=ass[i];
2073               AssignmentPersistenceInterface as=restore(assDO);
2074               ret.add(as);
2075            }
2076         }
2077
2078         return ret;
2079      }
2080      catch (Throwable JavaDoc t) {
2081         throw new PersistenceException(t);
2082      }
2083   }
2084
2085   /**
2086    * If activity is in "closed" state, or some of its sub-states, returns an
2087    * empty list, otherwise returns all assignments that are ever created for
2088    * that activity.
2089    */

2090   /*public List getAllAssignmentsForNotClosedActivity (String actId,SharkTransaction ti) throws PersistenceException {
2091      List ret=new ArrayList();
2092      try {
2093         // restore all assignments
2094         ActivityDO aDO=getPersistedActivityObject(actId,ti);
2095         if (aDO!=null) {
2096            String actState=aDO.getState().getKeyValue();
2097            if (!actState.startsWith("closed")) {
2098               AssignmentDO[] ass=aDO.getAssignmentDOArray();
2099               BigDecimal aOId = aDO.get_OId().toBigDecimal();
2100               List list = new ArrayList(Arrays.asList(ass));
2101
2102               for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2103                    it.hasNext();) {
2104                  AssignmentDO o = (AssignmentDO)it.next();
2105                  if (aOId.equals(o.oid_getActivity())) {
2106                     int index = list.indexOf(o);
2107                     if (-1 != index)
2108                        list.remove(o);
2109                  }
2110               }
2111               for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2112                    it.hasNext();) {
2113                  AssignmentDO o = (AssignmentDO)it.next();
2114                  if (aOId.equals(o.oid_getActivity())) {
2115                     int index = list.indexOf(o);
2116                     if (-1 == index)
2117                        list.add(o);
2118                     else {
2119                        list.set(index, o);
2120                     }
2121                  }
2122               }
2123               ass = new AssignmentDO[list.size()];
2124               list.toArray(ass);
2125               for (int i=0;i<ass.length; i++) {
2126                  AssignmentDO assDO=ass[i];
2127                  AssignmentPersistenceInterface as=restore(assDO);
2128                  ret.add(as);
2129               }
2130            }
2131         }
2132
2133         return ret;
2134      }
2135      catch (Throwable t) {
2136         throw new PersistenceException(t);
2137      }
2138   }*/

2139
2140   /**
2141    * If activity is in "closed" state, or some of its sub-states, returns an
2142    * empty list, otherwise it returns either all assignments that are ever
2143    * created for that activity if activity is not accepted, or just the
2144    * assignment for the resource that accepted activity.
2145    */

2146   public List getAllValidAssignmentsForActivity (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
2147      List ret=new ArrayList();
2148      try {
2149         // restore all assignments
2150
ActivityDO aDO=getPersistedActivityObject(actId,ti);
2151         //BigDecimal rOId=aDO.oid_getTheResource();
2152

2153         if (aDO!=null) {
2154            String JavaDoc actState=aDO.getState().getKeyValue();
2155            if (!actState.startsWith("closed")) {
2156               AssignmentDO[] ass=aDO.getAssignmentDOArray();
2157               BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2158               List list = new ArrayList(Arrays.asList(ass));
2159
2160               for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2161                    it.hasNext();) {
2162                  AssignmentDO o = (AssignmentDO)it.next();
2163                  if (aOId.equals(o.oid_getActivity())) {
2164                     int index = list.indexOf(o);
2165                     if (-1 != index)
2166                        list.remove(o);
2167                  }
2168               }
2169               for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
2170                    it.hasNext();) {
2171                  AssignmentDO o = (AssignmentDO)it.next();
2172                  if (aOId.equals(o.oid_getActivity()) && o.getIsValid()) {
2173                     int index = list.indexOf(o);
2174                     if (-1 == index)
2175                        list.add(o);
2176                     else {
2177                        list.set(index, o);
2178                     }
2179                  }
2180               }
2181               ass = new AssignmentDO[list.size()];
2182               list.toArray(ass);
2183               for (int i=0;i<ass.length; i++) {
2184                  AssignmentDO assDO=ass[i];
2185                  //ResourceDO arDO=assDO.getTheResource();
2186
//if (rOId==null || rOId.equals(assDO.oid_getTheResource())) {
2187
if (assDO.getIsValid()) {
2188                     AssignmentPersistenceInterface as=restore(assDO);
2189                     ret.add(as);
2190                  }
2191               }
2192            }
2193         }
2194
2195         return ret;
2196      }
2197      catch (Throwable JavaDoc t) {
2198         throw new PersistenceException(t);
2199      }
2200   }
2201
2202   public List getAllVariablesForProcess (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
2203      if (usingStandardVariableDataModel) {
2204         return getAllVariablesForProcessBLOB(procId, ti);
2205      } else {
2206         return getAllVariablesForProcessWOB(procId, ti);
2207      }
2208   }
2209
2210   protected List getAllVariablesForProcessBLOB (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
2211      List ret=new ArrayList();
2212      try {
2213         ProcessDO pDO=getPersistedProcessObject(procId,ti);
2214         if (pDO!=null) {
2215            ProcessDataDO[] DOs=pDO.getProcessDataDOArray();
2216            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
2217            List list = new ArrayList(Arrays.asList(DOs));
2218
2219            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
2220                 it.hasNext();) {
2221               ProcessDataDO o = (ProcessDataDO)it.next();
2222               if (pOId.equals(o.oid_getProcess())) {
2223                  int index = list.indexOf(o);
2224                  if (-1 != index)
2225                     list.remove(o);
2226               }
2227            }
2228            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
2229                 it.hasNext();) {
2230               ProcessDataDO o = (ProcessDataDO)it.next();
2231               if (pOId.equals(o.oid_getProcess())) {
2232                  int index = list.indexOf(o);
2233                  if (-1 == index)
2234                     list.add(o);
2235                  else {
2236                     list.set(index, o);
2237                  }
2238               }
2239            }
2240            DOs = new ProcessDataDO[list.size()];
2241            list.toArray(DOs);
2242            for (int i=0;i<DOs.length; i++) {
2243               ProcessDataDO DO=DOs[i];
2244               ProcessVariablePersistenceInterface var=new DODSProcessVariable();
2245               restoreBLOB(var,DO);
2246               ret.add(var);
2247            }
2248         }
2249
2250         return ret;
2251      }
2252      catch (Throwable JavaDoc t) {
2253         //t.printStackTrace();
2254
throw new PersistenceException(t);
2255      }
2256   }
2257   
2258   protected List getAllVariablesForProcessWOB (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
2259      List ret=new ArrayList();
2260      try {
2261         ProcessDO pDO=getPersistedProcessObject(procId,ti);
2262         if (pDO!=null) {
2263            ProcessDataWOBDO[] DOs=pDO.getProcessDataWOBDOArray();
2264            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
2265            List list = new ArrayList(Arrays.asList(DOs));
2266
2267            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO");
2268                 it.hasNext();) {
2269               ProcessDataWOBDO o = (ProcessDataWOBDO)it.next();
2270               if (pOId.equals(o.oid_getProcess())) {
2271                  int index = list.indexOf(o);
2272                  if (-1 != index)
2273                     list.remove(o);
2274               }
2275            }
2276            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO");
2277                 it.hasNext();) {
2278               ProcessDataWOBDO o = (ProcessDataWOBDO)it.next();
2279               if (pOId.equals(o.oid_getProcess())) {
2280                  int index = list.indexOf(o);
2281                  if (-1 == index)
2282                     list.add(o);
2283                  else {
2284                     list.set(index, o);
2285                  }
2286               }
2287            }
2288            DOs = new ProcessDataWOBDO[list.size()];
2289            list.toArray(DOs);
2290            for (int i=0;i<DOs.length; i++) {
2291               ProcessDataWOBDO DO=DOs[i];
2292               ProcessVariablePersistenceInterface var=new DODSProcessVariable();
2293               restoreWOB(var,DO);
2294               ret.add(var);
2295            }
2296         }
2297
2298         return ret;
2299      }
2300      catch (Throwable JavaDoc t) {
2301         //t.printStackTrace();
2302
throw new PersistenceException(t);
2303      }
2304   }
2305
2306   public List getProcessVariables(String JavaDoc procId,List variableIds,SharkTransaction ti) throws PersistenceException {
2307      if (usingStandardVariableDataModel) {
2308         return getProcessVariablesBLOB(procId, variableIds, ti);
2309      } else {
2310         return getProcessVariablesWOB(procId, variableIds, ti);
2311      }
2312   }
2313
2314   public List getProcessVariablesBLOB(String JavaDoc procId,List variableIds,SharkTransaction ti) throws PersistenceException {
2315      List ret=new ArrayList();
2316      try {
2317         Map map=new HashMap();
2318         ProcessDO pDO=getPersistedProcessObject(procId,ti);
2319         if (pDO!=null) {
2320            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
2321            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
2322                 it.hasNext();) {
2323               ProcessDataDO o = (ProcessDataDO)it.next();
2324               if (pOId.equals(o.oid_getProcess()) && variableIds.contains(o.getVariableDefinitionId())) {
2325                  map.put(o.getVariableDefinitionId(),o);
2326                  //System.out.println("FOUND variable in Buffer: id="+o.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(o.getVariableValue()));
2327
}
2328            }
2329         }
2330         
2331// System.out.println("FOUND "+map.size()+" variables in Buffer");
2332

2333         if (pDO.isPersistent() && map.size()!=variableIds.size()) {
2334            if (variableIds.size()-map.size()>1) {
2335// System.out.println("QUERY ON PDATA DB EXECUTED for "+procId+", there are already "+map.size()+" vars found !");
2336
ProcessDataDO[] DOs=pDO.getProcessDataDOArray();
2337               for (int i=0; i<DOs.length; i++) {
2338                  if (!map.containsKey(DOs[i].getVariableDefinitionId())) {
2339                     map.put(DOs[i].getVariableDefinitionId(),DOs[i]);
2340                     ((SharkDODSTransaction)ti)._read(DOs[i]);
2341                  }
2342// System.out.println("FOUND variable in DB: id="+DOs[i].getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DOs[i].getVariableValue()));
2343
}
2344            } else {
2345               DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction();
2346               for (int i=0; i<variableIds.size(); i++) {
2347                  String JavaDoc varId=(String JavaDoc)variableIds.get(i);
2348                  if (map.containsKey(varId)) continue;
2349                  ProcessDataQuery q=new ProcessDataQuery(dbt);
2350                  q.setQueryProcess(pDO);
2351                  q.setQueryVariableDefinitionId(varId);
2352                  ProcessDataDO DO=q.getNextDO();
2353                  if (DO!=null) {
2354// System.out.println("FOUND single variable in DB: id="+DO.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DO.getVariableValue()));
2355
map.put(varId,DO);
2356                     ((SharkDODSTransaction)ti)._read(DO);
2357                  } else {
2358// System.out.println("Can't find variable "+varId+" for process "+procId);
2359
}
2360               }
2361            }
2362         }
2363// System.out.println("FOUND "+map.size()+" variables in Buffer and DB");
2364

2365         ProcessDataDO[] DOs = new ProcessDataDO[map.size()];
2366         DOs = (ProcessDataDO[])map.values().toArray(DOs);
2367         if (DOs!=null) {
2368            for (int i=0;i<DOs.length; i++) {
2369               ProcessDataDO DO=DOs[i];
2370               ProcessVariablePersistenceInterface var=new DODSProcessVariable();
2371               restoreBLOB(var,DO);
2372               ret.add(var);
2373            }
2374         }
2375
2376
2377         return ret;
2378      }
2379      catch (Throwable JavaDoc t) {
2380         //t.printStackTrace();
2381
throw new PersistenceException(t);
2382      }
2383
2384   }
2385      
2386   public List getProcessVariablesWOB(String JavaDoc procId,List variableIds,SharkTransaction ti) throws PersistenceException {
2387      List ret=new ArrayList();
2388      try {
2389         Map map=new HashMap();
2390         ProcessDO pDO=getPersistedProcessObject(procId,ti);
2391         if (pDO!=null) {
2392            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
2393            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO");
2394                 it.hasNext();) {
2395               ProcessDataWOBDO o = (ProcessDataWOBDO)it.next();
2396               if (pOId.equals(o.oid_getProcess()) && variableIds.contains(o.getVariableDefinitionId())) {
2397                  map.put(o.getVariableDefinitionId(),o);
2398                  //System.out.println("FOUND variable in Buffer: id="+o.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(o.getVariableValue()));
2399
}
2400            }
2401         }
2402         
2403// System.out.println("FOUND "+map.size()+" variables in Buffer");
2404

2405         if (pDO.isPersistent() && map.size()!=variableIds.size()) {
2406            if (variableIds.size()-map.size()>1) {
2407// System.out.println("QUERY ON PDATA DB EXECUTED for "+procId+", there are already "+map.size()+" vars found !");
2408
ProcessDataWOBDO[] DOs=pDO.getProcessDataWOBDOArray();
2409               for (int i=0; i<DOs.length; i++) {
2410                  if (!map.containsKey(DOs[i].getVariableDefinitionId())) {
2411                     map.put(DOs[i].getVariableDefinitionId(),DOs[i]);
2412                     ((SharkDODSTransaction)ti)._read(DOs[i]);
2413                  }
2414// System.out.println("FOUND variable in DB: id="+DOs[i].getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DOs[i].getVariableValue()));
2415
}
2416            } else {
2417               DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction();
2418               for (int i=0; i<variableIds.size(); i++) {
2419                  String JavaDoc varId=(String JavaDoc)variableIds.get(i);
2420                  if (map.containsKey(varId)) continue;
2421                  ProcessDataWOBQuery q=new ProcessDataWOBQuery(dbt);
2422                  q.setQueryProcess(pDO);
2423                  q.setQueryVariableDefinitionId(varId);
2424                  ProcessDataWOBDO DO=q.getNextDO();
2425                  if (DO!=null) {
2426// System.out.println("FOUND single variable in DB: id="+DO.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DO.getVariableValue()));
2427
map.put(varId,DO);
2428                     ((SharkDODSTransaction)ti)._read(DO);
2429                  } else {
2430// System.out.println("Can't find variable "+varId+" for process "+procId);
2431
}
2432               }
2433            }
2434         }
2435// System.out.println("FOUND "+map.size()+" variables in Buffer and DB");
2436

2437         ProcessDataWOBDO[] DOs = new ProcessDataWOBDO[map.size()];
2438         DOs = (ProcessDataWOBDO[])map.values().toArray(DOs);
2439         if (DOs!=null) {
2440            for (int i=0;i<DOs.length; i++) {
2441               ProcessDataWOBDO DO=DOs[i];
2442               ProcessVariablePersistenceInterface var=new DODSProcessVariable();
2443               restoreWOB(var,DO);
2444               ret.add(var);
2445            }
2446         }
2447
2448
2449         return ret;
2450      }
2451      catch (Throwable JavaDoc t) {
2452         //t.printStackTrace();
2453
throw new PersistenceException(t);
2454      }
2455
2456   }
2457
2458   public List getAllVariablesForActivity (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
2459      if (usingStandardVariableDataModel) {
2460         return getAllVariablesForActivityBLOB(actId, ti);
2461      } else {
2462         return getAllVariablesForActivityWOB(actId, ti);
2463      }
2464   }
2465
2466   public List getAllVariablesForActivityBLOB (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
2467      List ret=new ArrayList();
2468      try {
2469         ActivityDO aDO=getPersistedActivityObject(actId,ti);
2470         if (aDO!=null) {
2471            ActivityDataDO[] DOs=aDO.getActivityDataDOArray();
2472            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2473            List list = new ArrayList(Arrays.asList(DOs));
2474
2475            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
2476                 it.hasNext();) {
2477               ActivityDataDO o = (ActivityDataDO)it.next();
2478               if (aOId.equals(o.oid_getActivity())) {
2479                  int index = list.indexOf(o);
2480                  if (-1 != index)
2481                     list.remove(o);
2482               }
2483            }
2484            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
2485                 it.hasNext();) {
2486               ActivityDataDO o = (ActivityDataDO)it.next();
2487               if (aOId.equals(o.oid_getActivity())) {
2488                  int index = list.indexOf(o);
2489                  if (-1 == index)
2490                     list.add(o);
2491                  else {
2492                     list.set(index, o);
2493                  }
2494               }
2495            }
2496            DOs = new ActivityDataDO[list.size()];
2497            list.toArray(DOs);
2498            for (int i=0;i<DOs.length; i++) {
2499               ActivityDataDO DO=DOs[i];
2500               ActivityVariablePersistenceInterface var=new DODSActivityVariable();
2501               restoreBLOB(var,DO);
2502               ret.add(var);
2503            }
2504         }
2505
2506         return ret;
2507      }
2508      catch (Throwable JavaDoc t) {
2509         throw new PersistenceException(t);
2510      }
2511   }
2512
2513   public List getAllVariablesForActivityWOB (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
2514      List ret=new ArrayList();
2515      try {
2516         ActivityDO aDO=getPersistedActivityObject(actId,ti);
2517         if (aDO!=null) {
2518            ActivityDataWOBDO[] DOs=aDO.getActivityDataWOBDOArray();
2519            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2520            List list = new ArrayList(Arrays.asList(DOs));
2521
2522            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO");
2523                 it.hasNext();) {
2524               ActivityDataWOBDO o = (ActivityDataWOBDO)it.next();
2525               if (aOId.equals(o.oid_getActivity())) {
2526                  int index = list.indexOf(o);
2527                  if (-1 != index)
2528                     list.remove(o);
2529               }
2530            }
2531            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO");
2532                 it.hasNext();) {
2533               ActivityDataWOBDO o = (ActivityDataWOBDO)it.next();
2534               if (aOId.equals(o.oid_getActivity())) {
2535                  int index = list.indexOf(o);
2536                  if (-1 == index)
2537                     list.add(o);
2538                  else {
2539                     list.set(index, o);
2540                  }
2541               }
2542            }
2543            DOs = new ActivityDataWOBDO[list.size()];
2544            list.toArray(DOs);
2545            for (int i=0;i<DOs.length; i++) {
2546               ActivityDataWOBDO DO=DOs[i];
2547               ActivityVariablePersistenceInterface var=new DODSActivityVariable();
2548               restoreWOB(var,DO);
2549               ret.add(var);
2550            }
2551         }
2552
2553         return ret;
2554      }
2555      catch (Throwable JavaDoc t) {
2556         throw new PersistenceException(t);
2557      }
2558   }
2559   
2560   public List getActivityVariables(String JavaDoc actId,List variableIds,SharkTransaction ti) throws PersistenceException {
2561      if (usingStandardVariableDataModel) {
2562         return getActivityVariablesBLOB(actId, variableIds, ti);
2563      } else {
2564         return getActivityVariablesWOB(actId, variableIds, ti);
2565      }
2566   }
2567
2568   public List getActivityVariablesBLOB(String JavaDoc actId,List variableIds,SharkTransaction ti) throws PersistenceException {
2569      List ret=new ArrayList();
2570      try {
2571         Map map=new HashMap();
2572         ActivityDO aDO=getPersistedActivityObject(actId,ti);
2573         if (aDO!=null) {
2574            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2575            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
2576                 it.hasNext();) {
2577               ActivityDataDO o = (ActivityDataDO)it.next();
2578               if (aOId.equals(o.oid_getActivity()) && variableIds.contains(o.getVariableDefinitionId())) {
2579                  map.put(o.getVariableDefinitionId(),o);
2580                  //System.out.println("FOUND variable in Buffer: id="+o.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(o.getVariableValue()));
2581
}
2582            }
2583         }
2584         
2585// System.out.println("FOUND "+map.size()+" variables in Buffer");
2586

2587         if (aDO.isPersistent() && map.size()!=variableIds.size()) {
2588            if (map.size()==0) {
2589// System.out.println("QUERY ON PDATA DB EXECUTED for "+procId+", there are already "+map.size()+" vars found !");
2590
ActivityDataDO[] DOs=aDO.getActivityDataDOArray();
2591               for (int i=0; i<DOs.length; i++) {
2592                  if (!map.containsKey(DOs[i].getVariableDefinitionId())) {
2593                     map.put(DOs[i].getVariableDefinitionId(),DOs[i]);
2594                     ((SharkDODSTransaction)ti)._read(DOs[i]);
2595                  }
2596// System.out.println("FOUND variable in DB: id="+DOs[i].getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DOs[i].getVariableValue()));
2597
}
2598            } else {
2599               DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction();
2600               for (int i=0; i<variableIds.size(); i++) {
2601                  String JavaDoc varId=(String JavaDoc)variableIds.get(i);
2602                  if (map.containsKey(varId)) continue;
2603                  ActivityDataQuery q=new ActivityDataQuery(dbt);
2604                  q.setQueryActivity(aDO);
2605                  q.setQueryVariableDefinitionId(varId);
2606                  ActivityDataDO DO=q.getNextDO();
2607                  if (DO!=null) {
2608// System.out.println("FOUND single variable in DB: id="+DO.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DO.getVariableValue()));
2609
map.put(varId,DO);
2610                     ((SharkDODSTransaction)ti)._read(DO);
2611                  } else {
2612// System.out.println("Can't find variable "+varId+" for process "+procId);
2613
}
2614               }
2615            }
2616         }
2617// System.out.println("FOUND "+map.size()+" variables in Buffer and DB");
2618

2619         ActivityDataDO[] DOs = new ActivityDataDO[map.size()];
2620         DOs = (ActivityDataDO[])map.values().toArray(DOs);
2621         if (DOs!=null) {
2622            for (int i=0;i<DOs.length; i++) {
2623               ActivityDataDO DO=DOs[i];
2624               ActivityVariablePersistenceInterface var=new DODSActivityVariable();
2625               restoreBLOB(var,DO);
2626               ret.add(var);
2627            }
2628         }
2629
2630
2631         return ret;
2632      }
2633      catch (Throwable JavaDoc t) {
2634         //t.printStackTrace();
2635
throw new PersistenceException(t);
2636      }
2637
2638   }
2639
2640   public List getActivityVariablesWOB(String JavaDoc actId,List variableIds,SharkTransaction ti) throws PersistenceException {
2641      List ret=new ArrayList();
2642      try {
2643         Map map=new HashMap();
2644         ActivityDO aDO=getPersistedActivityObject(actId,ti);
2645         if (aDO!=null) {
2646            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
2647            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO");
2648                 it.hasNext();) {
2649               ActivityDataWOBDO o = (ActivityDataWOBDO)it.next();
2650               if (aOId.equals(o.oid_getActivity()) && variableIds.contains(o.getVariableDefinitionId())) {
2651                  map.put(o.getVariableDefinitionId(),o);
2652                  //System.out.println("FOUND variable in Buffer: id="+o.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(o.getVariableValue()));
2653
}
2654            }
2655         }
2656         
2657// System.out.println("FOUND "+map.size()+" variables in Buffer");
2658

2659         if (aDO.isPersistent() && map.size()!=variableIds.size()) {
2660            if (map.size()==0) {
2661// System.out.println("QUERY ON PDATA DB EXECUTED for "+procId+", there are already "+map.size()+" vars found !");
2662
ActivityDataWOBDO[] DOs=aDO.getActivityDataWOBDOArray();
2663               for (int i=0; i<DOs.length; i++) {
2664                  if (!map.containsKey(DOs[i].getVariableDefinitionId())) {
2665                     map.put(DOs[i].getVariableDefinitionId(),DOs[i]);
2666                     ((SharkDODSTransaction)ti)._read(DOs[i]);
2667                  }
2668// System.out.println("FOUND variable in DB: id="+DOs[i].getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DOs[i].getVariableValue()));
2669
}
2670            } else {
2671               DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction();
2672               for (int i=0; i<variableIds.size(); i++) {
2673                  String JavaDoc varId=(String JavaDoc)variableIds.get(i);
2674                  if (map.containsKey(varId)) continue;
2675                  ActivityDataWOBQuery q=new ActivityDataWOBQuery(dbt);
2676                  q.setQueryActivity(aDO);
2677                  q.setQueryVariableDefinitionId(varId);
2678                  ActivityDataWOBDO DO=q.getNextDO();
2679                  if (DO!=null) {
2680// System.out.println("FOUND single variable in DB: id="+DO.getVariableDefinitionId()+", val="+MiscUtilities.deserialize(DO.getVariableValue()));
2681
map.put(varId,DO);
2682                     ((SharkDODSTransaction)ti)._read(DO);
2683                  } else {
2684// System.out.println("Can't find variable "+varId+" for process "+procId);
2685
}
2686               }
2687            }
2688         }
2689// System.out.println("FOUND "+map.size()+" variables in Buffer and DB");
2690

2691         ActivityDataWOBDO[] DOs = new ActivityDataWOBDO[map.size()];
2692         DOs = (ActivityDataWOBDO[])map.values().toArray(DOs);
2693         if (DOs!=null) {
2694            for (int i=0;i<DOs.length; i++) {
2695               ActivityDataWOBDO DO=DOs[i];
2696               ActivityVariablePersistenceInterface var=new DODSActivityVariable();
2697               restoreWOB(var,DO);
2698               ret.add(var);
2699            }
2700         }
2701
2702         return ret;
2703      }
2704      catch (Throwable JavaDoc t) {
2705         //t.printStackTrace();
2706
throw new PersistenceException(t);
2707      }
2708
2709   }
2710   
2711   public List getResourceRequestersProcessIds (String JavaDoc resUsername,SharkTransaction ti) throws PersistenceException {
2712      List ret=new ArrayList();
2713      try {
2714         ResourceDO rDO=getPersistedResourceObject(resUsername,ti);
2715         if (rDO!=null) {
2716            ProcessRequesterDO[] DOs=rDO.getProcessRequesterDOArray();
2717            BigDecimal JavaDoc rOId = rDO.get_OId().toBigDecimal();
2718            List list = new ArrayList(Arrays.asList(DOs));
2719            // remove DOs that also have activity requester
2720
if (DOs!=null) {
2721               for (int i=0; i<DOs.length; i++) {
2722                  if (DOs[i].getActivityRequester()!=null) {
2723                     list.remove(DOs[i]);
2724                  }
2725               }
2726            }
2727
2728            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
2729                 it.hasNext();) {
2730               ProcessRequesterDO o = (ProcessRequesterDO)it.next();
2731               if (rOId.equals(o.oid_getResourceRequester())) {
2732                  int index = list.indexOf(o);
2733                  if (-1 != index)
2734                     list.remove(o);
2735               }
2736            }
2737            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
2738                 it.hasNext();) {
2739               ProcessRequesterDO o = (ProcessRequesterDO)it.next();
2740               if (rOId.equals(o.oid_getResourceRequester()) && o.getActivityRequester()==null) {
2741                  int index = list.indexOf(o);
2742                  if (-1 == index)
2743                     list.add(o);
2744                  else {
2745                     list.set(index, o);
2746                  }
2747               }
2748            }
2749            DOs = new ProcessRequesterDO[list.size()];
2750            list.toArray(DOs);
2751            for (int i=0;i<DOs.length; i++) {
2752               ret.add(DOs[i].getId());
2753            }
2754         }
2755         return ret;
2756      }
2757      catch (Throwable JavaDoc t) {
2758         throw new PersistenceException(t);
2759      }
2760   }
2761
2762   public List getAndJoinEntries (String JavaDoc procId,
2763                                  String JavaDoc asDefId,
2764                                  String JavaDoc aDefId,
2765                                  SharkTransaction ti) throws PersistenceException {
2766      List ret=new ArrayList();
2767      try {
2768         AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti);
2769         if (DOs!=null) {
2770            for (int i=0;i<DOs.length; i++) {
2771               AndJoinEntryDO DO=DOs[i];
2772               AndJoinEntryInterface aj=new DODSAndJoinEntry();
2773               // restore AndJoinEntry
2774
aj.setProcessId(DO.getProcess().getId());
2775               aj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId());
2776               aj.setActivityDefinitionId(DO.getActivityDefinitionId());
2777               aj.setActivityId(DO.getActivity().getId());
2778               ((SharkDODSTransaction)ti)._read(DO);
2779               ret.add(aj);
2780            }
2781         }
2782
2783         return ret;
2784      }
2785      catch (Throwable JavaDoc t) {
2786         throw new PersistenceException(t);
2787      }
2788   }
2789
2790   public int howManyAndJoinEntries (String JavaDoc procId,
2791                                     String JavaDoc asDefId,
2792                                     String JavaDoc aDefId,
2793                                     SharkTransaction ti) throws PersistenceException {
2794      try {
2795         AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti);
2796         if (DOs!=null) {
2797            return DOs.length;
2798         } else {
2799            return 0;
2800         }
2801      } catch (Throwable JavaDoc tr) {
2802         throw new PersistenceException(tr);
2803      }
2804   }
2805
2806   public int getExecuteCount(String JavaDoc procId,
2807                              String JavaDoc asDefId,
2808                              String JavaDoc aDefId,
2809                              SharkTransaction ti) throws PersistenceException {
2810      ActivityQuery qry = new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction());
2811      try {
2812         qry.setQueryProcess(getPersistedProcessObject(procId, ti));
2813         qry.setQueryActivitySetDefinitionId(asDefId);
2814         qry.setQueryActivityDefinitionId(aDefId);
2815         return qry.getCount();
2816      } catch (Throwable JavaDoc e) {
2817         throw new PersistenceException(e);
2818      }
2819   }
2820
2821   public List getAllDeadlinesForProcess (String JavaDoc procId,
2822                                          SharkTransaction ti) throws PersistenceException {
2823      List ret=new ArrayList();
2824      try {
2825         DeadlineDO[] DOs=getPersistedDeadlines(procId,-1,ti);
2826         if (DOs!=null) {
2827            for (int i=0;i<DOs.length; i++) {
2828               DeadlineDO DO=DOs[i];
2829               DeadlinePersistenceInterface dl=new DODSDeadline();
2830               // restore Deadline
2831
dl.setProcessId(procId);
2832               dl.setActivityId(DO.getActivity().getId());
2833               dl.setExceptionName(DO.getExceptionName());
2834               dl.setSynchronous(DO.getIsSynchronous());
2835               dl.setExecuted(DO.getIsExecuted());
2836               dl.setUniqueId(DO.getCNT().toString());
2837               dl.setTimeLimit(DO.getTimeLimit());
2838               ((SharkDODSTransaction)ti)._read(DO);
2839               ret.add(dl);
2840            }
2841         }
2842
2843         return ret;
2844      }
2845      catch (Throwable JavaDoc t) {
2846         throw new PersistenceException(t);
2847      }
2848   }
2849
2850   public List getAllDeadlinesForProcess (String JavaDoc procId,
2851                                          long timeLimitBoundary,
2852                                          SharkTransaction ti) throws PersistenceException {
2853      List ret=new ArrayList();
2854      try {
2855         DeadlineDO[] DOs=getPersistedDeadlines(procId,timeLimitBoundary,ti);
2856         if (DOs!=null) {
2857            for (int i=0;i<DOs.length; i++) {
2858               DeadlineDO DO=DOs[i];
2859               DeadlinePersistenceInterface dl=new DODSDeadline();
2860               // restore Deadline
2861
dl.setProcessId(procId);
2862               dl.setActivityId(DO.getActivity().getId());
2863               dl.setExceptionName(DO.getExceptionName());
2864               dl.setSynchronous(DO.getIsSynchronous());
2865               dl.setExecuted(DO.getIsExecuted());
2866               dl.setUniqueId(DO.getCNT().toString());
2867               dl.setTimeLimit(DO.getTimeLimit());
2868               ((SharkDODSTransaction)ti)._read(DO);
2869               ret.add(dl);
2870            }
2871         }
2872
2873         return ret;
2874      }
2875      catch (Throwable JavaDoc t) {
2876         throw new PersistenceException(t);
2877      }
2878   }
2879
2880   public List getAllDeadlinesForActivity (String JavaDoc procId,
2881                                           String JavaDoc actId,
2882                                           SharkTransaction ti) throws PersistenceException {
2883      List ret=new ArrayList();
2884      try {
2885         DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,-1,ti);
2886         if (DOs!=null) {
2887            for (int i=0;i<DOs.length; i++) {
2888               DeadlineDO DO=DOs[i];
2889               DeadlinePersistenceInterface dl=new DODSDeadline();
2890               // restore Deadline
2891
dl.setProcessId(procId);
2892               dl.setActivityId(actId);
2893               dl.setExceptionName(DO.getExceptionName());
2894               dl.setSynchronous(DO.getIsSynchronous());
2895               dl.setExecuted(DO.getIsExecuted());
2896               dl.setUniqueId(DO.getCNT().toString());
2897               dl.setTimeLimit(DO.getTimeLimit());
2898               ((SharkDODSTransaction)ti)._read(DO);
2899               ret.add(dl);
2900            }
2901         }
2902
2903         return ret;
2904      }
2905      catch (Throwable JavaDoc t) {
2906         throw new PersistenceException(t);
2907      }
2908   }
2909
2910   public List getAllDeadlinesForActivity (String JavaDoc procId,
2911                                           String JavaDoc actId,
2912                                           long timeLimitBoundary,
2913                                           SharkTransaction ti) throws PersistenceException {
2914      List ret=new ArrayList();
2915      try {
2916         DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,timeLimitBoundary,ti);
2917         if (DOs!=null) {
2918            for (int i=0;i<DOs.length; i++) {
2919               DeadlineDO DO=DOs[i];
2920               DeadlinePersistenceInterface dl=new DODSDeadline();
2921               // restore Deadline
2922
dl.setProcessId(procId);
2923               dl.setActivityId(actId);
2924               dl.setExceptionName(DO.getExceptionName());
2925               dl.setSynchronous(DO.getIsSynchronous());
2926               dl.setExecuted(DO.getIsExecuted());
2927               dl.setUniqueId(DO.getCNT().toString());
2928               dl.setTimeLimit(DO.getTimeLimit());
2929               ((SharkDODSTransaction)ti)._read(DO);
2930               ret.add(dl);
2931            }
2932         }
2933
2934         return ret;
2935      }
2936      catch (Throwable JavaDoc t) {
2937         throw new PersistenceException(t);
2938      }
2939   }
2940
2941   public List getAllIdsForProcessesWithExpiriedDeadlines (long timeLimitBoundary,SharkTransaction ti) throws PersistenceException {
2942      List ret=new ArrayList();
2943      try {
2944         BigDecimal JavaDoc procOpenRunningState=(BigDecimal JavaDoc)_prStates.get("open.running");
2945         BigDecimal JavaDoc actNotStartedState=(BigDecimal JavaDoc)_acStates.get("open.not_running.not_started");
2946         BigDecimal JavaDoc actRunningState=(BigDecimal JavaDoc)_acStates.get("open.running");
2947         String JavaDoc oidCol=ProcessDO.get_OIdColumnName();
2948         String JavaDoc sqlWherePS="Processes.State="+procOpenRunningState;
2949         String JavaDoc sqlWhereLT="Processes.Id NOT IN (SELECT LockTable.Id FROM LockTable)";
2950         String JavaDoc sqlWhereDL="Processes."+oidCol+" IN (SELECT Deadlines.Process FROM Deadlines WHERE Deadlines.TimeLimit < "+timeLimitBoundary+" AND (SELECT COUNT(*) AS counter FROM Activities WHERE Activities."+oidCol+"=Deadlines.Activity AND (Activities.State="+actNotStartedState+" OR Activities.State="+actRunningState+"))>0)";
2951         ProcessDO[] DOs=null;
2952         ProcessQuery query = null;
2953         query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction());
2954         QueryBuilder qb=qb=query.getQueryBuilder();
2955         qb.addWhere(sqlWherePS);
2956         qb.addWhere(sqlWhereLT);
2957         qb.addWhere(sqlWhereDL);
2958         //System.out.println("SQLWP="+qb.getSQLwithParms());
2959
DOs = query.getDOArray();
2960         if (DOs!=null) {
2961            for (int i=0;i<DOs.length; i++) {
2962               ret.add(DOs[i].getId());
2963            }
2964         }
2965
2966      } catch (Throwable JavaDoc t) {
2967         throw new PersistenceException(t);
2968      }
2969      return ret;
2970   }
2971
2972   protected ProcessDefinitionDO getPersistedObject (ProcessMgrPersistenceInterface mgr,SharkTransaction ti) throws PersistenceException {
2973      ProcessDefinitionDO DO=getPersistedProcessMgrObject(mgr.getName(),ti);
2974
2975      try {
2976         if (DO==null) {
2977            DO=ProcessDefinitionDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
2978         }
2979         return DO;
2980      }
2981      catch (Throwable JavaDoc t) {
2982         throw new PersistenceException(t);
2983      }
2984
2985   }
2986
2987   protected ProcessDefinitionDO getPersistedProcessMgrObject (String JavaDoc name,SharkTransaction ti) throws PersistenceException {
2988      ProcessDefinitionDO DO=null;
2989      ProcessDefinitionQuery query = null;
2990      try {
2991         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO");
2992              it.hasNext();) {
2993            DO = (ProcessDefinitionDO)it.next();
2994            if (name.equals(DO.getName()))
2995               return DO;
2996         }
2997         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO");
2998              it.hasNext();) {
2999            DO = (ProcessDefinitionDO)it.next();
3000            if (name.equals(DO.getName()))
3001               return null;
3002         }
3003         query=new ProcessDefinitionQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3004         //set query
3005
query.setQueryName(name);
3006         // Throw an exception if more than one object is found
3007
query.requireUniqueInstance();
3008         DO = query.getNextDO();
3009         ((SharkDODSTransaction)ti)._read(DO);
3010         return DO;
3011      }
3012      catch (Throwable JavaDoc t) {
3013         throw new PersistenceException(t);
3014      }
3015   }
3016
3017   protected ProcessDefinitionDO[] getAllPersistedProcessMgrs (SharkTransaction ti,String JavaDoc pkgId,String JavaDoc pDefId,String JavaDoc pkgVersion, String JavaDoc where) throws PersistenceException {
3018      ProcessDefinitionDO[] DOs=null;
3019
3020      ProcessDefinitionQuery query = null;
3021      try {
3022         query=new ProcessDefinitionQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3023         if (pkgId!=null) {
3024            query.setQueryPackageId(pkgId);
3025            if (pkgVersion!=null) {
3026               query.setQueryProcessDefinitionVersion(pkgVersion);
3027            }
3028            if (pDefId!=null) {
3029               query.setQueryProcessDefinitionId(pDefId);
3030            }
3031         } else if (null != where) {
3032            query.getQueryBuilder().addWhere(where);
3033         }
3034         DOs = query.getDOArray();
3035         List list = new ArrayList(Arrays.asList(DOs));
3036         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO");
3037              it.hasNext();) {
3038            ProcessDefinitionDO o = (ProcessDefinitionDO)it.next();
3039            if (pkgId!=null) {
3040               if(!pkgId.equals(o.getPackageId())) continue;
3041               if (pkgVersion!=null && !pkgVersion.equals(o.getProcessDefinitionVersion())) continue;
3042               if (pDefId!=null && !pDefId.equals(o.getProcessDefinitionId())) continue;
3043            }
3044
3045            int index = list.indexOf(o);
3046            if (-1 != index)
3047               list.remove(o);
3048         }
3049         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO");
3050              it.hasNext();) {
3051            ProcessDefinitionDO o = (ProcessDefinitionDO)it.next();
3052            if (pkgId!=null) {
3053               if(!pkgId.equals(o.getPackageId())) continue;
3054               if (pkgVersion!=null && !pkgVersion.equals(o.getProcessDefinitionVersion())) continue;
3055               if (pDefId!=null && !pDefId.equals(o.getProcessDefinitionId())) continue;
3056            }
3057
3058            int index = list.indexOf(o);
3059            if (-1 == index)
3060               list.add(o);
3061            else {
3062               list.set(index, o);
3063            }
3064            //if (!list.contains(o))
3065
// list.add(o);
3066
}
3067         DOs = new ProcessDefinitionDO[list.size()];
3068         list.toArray(DOs);
3069         return DOs;
3070      } catch (Throwable JavaDoc t) {
3071         throw new PersistenceException(t);
3072      }
3073   }
3074
3075   protected ProcessDO getPersistedObject (ProcessPersistenceInterface proc,SharkTransaction ti) throws PersistenceException {
3076      ProcessDO DO=getPersistedProcessObject(proc.getId(),ti);
3077
3078      try {
3079         if (DO==null) {
3080            DO=ProcessDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3081         }
3082         return DO;
3083      }
3084      catch (Throwable JavaDoc t) {
3085         throw new PersistenceException(t);
3086      }
3087   }
3088
3089   // type=-1 -> closed.xxx
3090
// type=0 -> all
3091
// type=1 -> open.running
3092
//
3093
protected ProcessDO[] getPersistedProcesses(SharkTransaction ti,
3094                                               int type,
3095                                               String JavaDoc pkgId,
3096                                               String JavaDoc pDefId,
3097                                               String JavaDoc pkgVer,
3098                                               java.util.Date JavaDoc lastStateTimeBoundary,
3099                                               String JavaDoc sqlWhere) throws PersistenceException {
3100
3101      ProcessDefinitionDO[] pdefDOs=null;
3102      if (pkgId!=null) {
3103         pdefDOs = getAllPersistedProcessMgrs(ti, pkgId, pDefId, pkgVer, null);
3104      }
3105
3106      long lstb=-1;
3107      if (lastStateTimeBoundary!=null) {
3108         lstb=lastStateTimeBoundary.getTime();
3109      }
3110
3111      ProcessDO[] DOs=null;
3112      ProcessQuery query = null;
3113      try {
3114         query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3115         BigDecimal JavaDoc openRunningState=null;
3116         QueryBuilder qb=qb=query.getQueryBuilder();
3117         if (lastStateTimeBoundary!=null) {
3118            qb.addWhere(ProcessDO.LastStateTime,lstb,QueryBuilder.LESS_THAN);
3119         }
3120         if (pkgId!=null) {
3121            if (pdefDOs!=null && pdefDOs.length>0) {
3122               qb.addWhereOpenParen();
3123               for (int i=0; i<pdefDOs.length; i++) {
3124                  qb.addWhere(ProcessDO.ProcessDefinition,
3125                              pdefDOs[i].get_OId().toBigDecimal(),
3126                              QueryBuilder.EQUAL);
3127                  if (i<pdefDOs.length-1) {
3128                     qb.addWhereOr();
3129                  }
3130
3131               }
3132               qb.addWhereCloseParen();
3133            }
3134
3135         }
3136
3137         if (type==1) {
3138            openRunningState=(BigDecimal JavaDoc)_prStates.get("open.running");
3139            qb.addWhere(ProcessDO.State,openRunningState,QueryBuilder.EQUAL);
3140         } else if (type==-1) {
3141            qb.addWhereOpenParen();
3142            for (int i=0; i<_prClosedStatesBigDecimals.size(); i++) {
3143               qb.addWhere(ProcessDO.State,
3144                              (BigDecimal JavaDoc)_prClosedStatesBigDecimals.get(i),
3145                           QueryBuilder.EQUAL);
3146               if (i<_prClosedStatesBigDecimals.size()-1) {
3147                  qb.addWhereOr();
3148               }
3149            }
3150            qb.addWhereCloseParen();
3151         }
3152         if (null != sqlWhere) {
3153            qb.addWhere(sqlWhere);
3154         }
3155         DOs = query.getDOArray();
3156         List list = new ArrayList(Arrays.asList(DOs));
3157
3158         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO");
3159              it.hasNext();) {
3160            ProcessDO o = (ProcessDO)it.next();
3161            if (type==1 && !o.oid_getState().equals(openRunningState)) continue;
3162            if (type==-1 && !_prClosedStatesBigDecimals.contains(o.oid_getState())) continue;
3163            if (lastStateTimeBoundary!=null && o.getLastStateTime()>lstb) continue;
3164            if (pkgId!=null) {
3165               ProcessDefinitionDO pDefDO=o.getProcessDefinition();
3166               if (!pkgId.equals(pDefDO.getPackageId())) continue;
3167               if (pDefId!=null && !pDefId.equals(pDefDO.getProcessDefinitionId())) continue;
3168            }
3169            int index = list.indexOf(o);
3170            if (-1 != index)
3171               list.remove(o);
3172         }
3173         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO");
3174              it.hasNext();) {
3175            ProcessDO o = (ProcessDO)it.next();
3176            if (type==1 && !o.oid_getState().equals(openRunningState)) continue;
3177            if (type==-1 && !_prClosedStatesBigDecimals.contains(o.oid_getState())) continue;
3178            if (lastStateTimeBoundary!=null && o.getLastStateTime()>lstb) continue;
3179            if (pkgId!=null) {
3180               ProcessDefinitionDO pDefDO=o.getProcessDefinition();
3181               if (!pkgId.equals(pDefDO.getPackageId())) continue;
3182               if (pDefId!=null && !pDefId.equals(pDefDO.getProcessDefinitionId())) continue;
3183            }
3184            int index = list.indexOf(o);
3185            if (-1 == index)
3186               list.add(o);
3187            else {
3188               list.set(index, o);
3189            }
3190            //if (!list.contains(o))
3191
// list.add(o);
3192
}
3193         DOs = new ProcessDO[list.size()];
3194         list.toArray(DOs);
3195         return DOs;
3196      }
3197      catch (Throwable JavaDoc t) {
3198         throw new PersistenceException(t);
3199      }
3200   }
3201
3202   protected ProcessDO getPersistedProcessObject (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
3203      ProcessDO DO=null;
3204
3205      ProcessQuery query = null;
3206      try {
3207         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO");
3208              it.hasNext();) {
3209            DO = (ProcessDO)it.next();
3210            if (procId.equals(DO.getId()))
3211               return DO;
3212         }
3213         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO");
3214              it.hasNext();) {
3215            DO = (ProcessDO)it.next();
3216            if (procId.equals(DO.getId()))
3217               return null;
3218         }
3219         query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3220         //set query
3221
query.setQueryId(procId);
3222         // Throw an exception if more than one object is found
3223
query.requireUniqueInstance();
3224         DO = query.getNextDO();
3225         ((SharkDODSTransaction)ti)._read(DO);
3226         return DO;
3227      }
3228      catch (Throwable JavaDoc t) {
3229         throw new PersistenceException(t);
3230      }
3231   }
3232
3233   protected ProcessRequesterDO getProcessRequester(String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
3234      ProcessRequesterDO DO=getPersistedRequesterObject(procId,ti);
3235      try {
3236         if (null == DO) {
3237            DO=ProcessRequesterDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3238         }
3239         return DO;
3240      } catch (Throwable JavaDoc t) {
3241         throw new PersistenceException(t);
3242      }
3243   }
3244
3245   protected ProcessRequesterDO getPersistedRequesterObject (String JavaDoc procId,SharkTransaction ti) throws PersistenceException {
3246      ProcessRequesterDO DO=null;
3247      ProcessRequesterQuery query = null;
3248      try {
3249         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
3250              it.hasNext();) {
3251            DO = (ProcessRequesterDO)it.next();
3252            if (procId.equals(DO.getId()))
3253               return DO;
3254         }
3255         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
3256              it.hasNext();) {
3257            DO = (ProcessRequesterDO)it.next();
3258            if (procId.equals(DO.getId()))
3259               return null;
3260         }
3261         query=new ProcessRequesterQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3262         //set query
3263
query.setQueryId(procId);
3264         // Throw an exception if more than one object is found
3265
query.requireUniqueInstance();
3266         DO = query.getNextDO();
3267         ((SharkDODSTransaction)ti)._read(DO);
3268         return DO;
3269      }
3270      catch (Throwable JavaDoc t) {
3271         throw new PersistenceException(t);
3272      }
3273   }
3274
3275   /*protected ProcessRequesterDO getProcessRequesterByActId (String actId,SharkTransaction ti) throws PersistenceException {
3276    ProcessRequesterDO DO=null;
3277    ProcessRequesterQuery query = null;
3278    try {
3279    for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO");
3280    it.hasNext();) {
3281    DO = (ProcessRequesterDO)it.next();
3282    ActivityDO aDO=DO.getActivityRequester();
3283    if (aDO!=null && actId.equals(aDO.getId()))
3284    return DO;
3285    }
3286    return null;
3287    }
3288    catch (Throwable t) {
3289    throw new PersistenceException(t);
3290    }
3291    }*/

3292
3293   protected ActivityDO getPersistedObject (ActivityPersistenceInterface act,SharkTransaction ti) throws PersistenceException {
3294      //if (act.getActivityDefinitionId().equals("seeFirstRes")) System.out.println("GPO1");
3295
ActivityDO DO=getPersistedActivityObject(act.getId(),ti);
3296      //if (act.getActivityDefinitionId().equals("seeFirstRes")) System.out.println("GPO2");
3297

3298      try {
3299         if (DO==null) {
3300            DO=ActivityDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3301         }
3302         return DO;
3303      }
3304      catch (Throwable JavaDoc t) {
3305         throw new PersistenceException(t);
3306      }
3307   }
3308
3309   // type=-1 -> closed.xxx
3310
// type=0 -> all
3311
// type=1 -> open.xxx
3312
//
3313
protected ActivityDO[] getPersistedActivities (SharkTransaction ti,int type,BigDecimal JavaDoc procOId, String JavaDoc sqlWhere) throws PersistenceException {
3314
3315      ActivityDO[] DOs=null;
3316      ActivityQuery query = null;
3317      try {
3318         query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3319         QueryBuilder qb=qb=query.getQueryBuilder();
3320
3321         if (procOId!=null) {
3322            qb.addWhere(ActivityDO.Process,procOId,QueryBuilder.EQUAL);
3323         }
3324
3325         if (sqlWhere!=null) {
3326            qb.addWhere(sqlWhere);
3327         }
3328
3329         if (type==1) {
3330            qb.addWhereOpenParen();
3331            for (int i=0; i<_actOpenStatesBigDecimals.size(); i++) {
3332               qb.addWhere(ActivityDO.State,
3333                              (BigDecimal JavaDoc)_actOpenStatesBigDecimals.get(i),
3334                           QueryBuilder.EQUAL);
3335               if (i<_actOpenStatesBigDecimals.size()-1) {
3336                  qb.addWhereOr();
3337               }
3338            }
3339            qb.addWhereCloseParen();
3340         } else if (type==-1) {
3341            qb.addWhereOpenParen();
3342            for (int i=0; i<_actClosedStatesBigDecimals.size(); i++) {
3343               qb.addWhere(ActivityDO.State,
3344                              (BigDecimal JavaDoc)_actClosedStatesBigDecimals.get(i),
3345                           QueryBuilder.EQUAL);
3346               if (i<_actClosedStatesBigDecimals.size()-1) {
3347                  qb.addWhereOr();
3348               }
3349            }
3350            qb.addWhereCloseParen();
3351         }
3352         DOs = query.getDOArray();
3353         List list = new ArrayList(Arrays.asList(DOs));
3354         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO");
3355              it.hasNext();) {
3356            ActivityDO o = (ActivityDO)it.next();
3357            if (procOId!=null && !o.oid_getProcess().equals(procOId)) continue;
3358            if (type==1 && !_actOpenStatesBigDecimals.contains(o.oid_getState())) continue;
3359            if (type==-1 && !_actClosedStatesBigDecimals.contains(o.oid_getState())) continue;
3360            int index = list.indexOf(o);
3361            if (-1 != index)
3362               list.remove(o);
3363         }
3364         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO");
3365              it.hasNext();) {
3366            ActivityDO o = (ActivityDO)it.next();
3367            if (procOId!=null && !o.oid_getProcess().equals(procOId)) continue;
3368            if (type==1 && !_actOpenStatesBigDecimals.contains(o.oid_getState())) {
3369               list.remove(o);
3370               continue;
3371            }
3372            if (type==-1 && !_actClosedStatesBigDecimals.contains(o.oid_getState())) continue;
3373            int index = list.indexOf(o);
3374            if (-1 == index) {
3375               list.add(o);
3376            }
3377            else {
3378               list.set(index, o);
3379            }
3380            //if (!list.contains(o))
3381
// list.add(o);
3382
}
3383         DOs = new ActivityDO[list.size()];
3384         list.toArray(DOs);
3385         return DOs;
3386      }
3387      catch (Throwable JavaDoc t) {
3388         throw new PersistenceException(t);
3389      }
3390   }
3391
3392   protected ActivityDO getPersistedActivityObject (String JavaDoc actId,SharkTransaction ti) throws PersistenceException {
3393      if (null == actId)
3394         return null;
3395
3396      ActivityDO DO=null;
3397      ActivityQuery query = null;
3398
3399      try {
3400         //System.err.print("getPersistedActivityObject:"+actId+""+ti+"[");
3401
for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO");
3402              it.hasNext();) {
3403            DO = (ActivityDO)it.next();
3404            //System.err.print("\n\t"+DO.getId()+"("+DO.getState().getKeyValue()+")");
3405
if (actId.equals(DO.getId())) {
3406               //System.err.println("<<<]");
3407
return DO;
3408            }
3409         }
3410         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO");
3411              it.hasNext();) {
3412            DO = (ActivityDO)it.next();
3413            //System.err.print("\n\t"+DO.getId()+"("+DO.getState().getKeyValue()+")");
3414
if (actId.equals(DO.getId())) {
3415               //System.err.println("<<<]");
3416
return null;
3417            }
3418         }
3419         //System.err.println("]");
3420
//if (actId!=null && actId.equals("3_1_test_testSubflow")) System.out.println("GPAO1");
3421
query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3422         //if (actId!=null && actId.equals("3_1_test_testSubflow")) System.out.println("GPAO2");
3423
//set query
3424
query.setQueryId(actId);
3425         //if (actId!=null && actId.equals("3_1_test_testSubflow")) System.out.println("GPAO3");
3426
// Throw an exception if more than one object is found
3427
query.requireUniqueInstance();
3428         //if (actId!=null && actId.equals("3_1_test_testSubflow")) System.out.println("GPAO4");
3429

3430         DO = query.getNextDO();
3431         //if (actId!=null && actId.equals("3_1_test_testSubflow")) System.out.println("GPAO5");
3432
((SharkDODSTransaction)ti)._read(DO);
3433         return DO;
3434      }
3435      catch (Throwable JavaDoc t) {
3436         //t.printStackTrace();
3437
throw new PersistenceException(t);
3438      }
3439   }
3440
3441   protected ResourceDO getPersistedObject (ResourcePersistenceInterface res,SharkTransaction ti) throws PersistenceException {
3442      ResourceDO DO=getPersistedResourceObject(res.getUsername(),ti);
3443
3444      try {
3445         if (DO==null) {
3446            DO=ResourceDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3447         }
3448         return DO;
3449      }
3450      catch (Throwable JavaDoc t) {
3451         throw new PersistenceException(t);
3452      }
3453   }
3454
3455   protected ResourceDO getPersistedResourceObject (String JavaDoc username,SharkTransaction ti) throws PersistenceException {
3456      if (null == username)
3457         return null;
3458      ResourceDO DO=null;
3459      ResourceQuery query = null;
3460      try {
3461         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ResourceDO");
3462              it.hasNext();) {
3463            DO = (ResourceDO)it.next();
3464            if (username.equals(DO.getUsername()))
3465               return DO;
3466         }
3467         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ResourceDO");
3468              it.hasNext();) {
3469            DO = (ResourceDO)it.next();
3470            if (username.equals(DO.getUsername()))
3471               return null;
3472         }
3473         query=new ResourceQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3474         //set query
3475
query.setQueryUsername(username);
3476         // Throw an exception if more than one object is found
3477
query.requireUniqueInstance();
3478         DO = query.getNextDO();
3479         ((SharkDODSTransaction)ti)._read(DO);
3480
3481         return DO;
3482      }
3483      catch (Throwable JavaDoc t) {
3484         throw new PersistenceException(t);
3485      }
3486   }
3487
3488   protected ResourceDO[] getAllPersistedResources (SharkTransaction ti, String JavaDoc sqlWhere) throws PersistenceException {
3489      ResourceDO[] DOs=null;
3490
3491      ResourceQuery query = null;
3492      try {
3493         query=new ResourceQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3494         if (null != sqlWhere) {
3495            query.getQueryBuilder().addWhere(sqlWhere);
3496         }
3497         DOs = query.getDOArray();
3498         List list = new ArrayList(Arrays.asList(DOs));
3499         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ResourceDO");
3500              it.hasNext();) {
3501            Object JavaDoc o = it.next();
3502            int index = list.indexOf(o);
3503            if (-1 != index)
3504               list.remove(o);
3505         }
3506         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ResourceDO");
3507              it.hasNext();) {
3508            Object JavaDoc o = it.next();
3509            int index = list.indexOf(o);
3510            if (-1 == index)
3511               list.add(o);
3512            else {
3513               list.set(index, o);
3514            }
3515            //if (!list.contains(o))
3516
// list.add(o);
3517
}
3518         DOs = new ResourceDO[list.size()];
3519         list.toArray(DOs);
3520         return DOs;
3521      }
3522      catch (Throwable JavaDoc t) {
3523         throw new PersistenceException(t);
3524      }
3525   }
3526
3527   protected AssignmentDO getPersistedObject (AssignmentPersistenceInterface ass,SharkTransaction ti) throws PersistenceException {
3528      AssignmentDO DO=getPersistedAssignmentObject(ass.getActivityId(),ass.getResourceUsername(),ti);
3529
3530      try {
3531         if (DO==null) {
3532            DO=AssignmentDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3533         }
3534         return DO;
3535      }
3536      catch (Throwable JavaDoc t) {
3537         throw new PersistenceException(t);
3538      }
3539   }
3540
3541   protected AssignmentDO getPersistedAssignmentObject (String JavaDoc actId,String JavaDoc username,SharkTransaction ti) throws PersistenceException {
3542      AssignmentDO DO=null;
3543
3544      //System.out.println("Searching for ass["+actId+","+username+"]");
3545

3546      AssignmentQuery query = null;
3547      try {
3548         //ResourceDO rDO = getPersistedResourceObject(username,ti);
3549
//ActivityDO aDO = getPersistedActivityObject(actId,ti);
3550
for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
3551              it.hasNext();) {
3552            DO = (AssignmentDO)it.next();
3553            if (username.equals(DO.getResourceId())
3554                && actId.equals(DO.getActivity().getId())) {
3555               //System.out.println("DO from Buffer:"+DO);
3556
return DO;
3557            }
3558         }
3559         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
3560              it.hasNext();) {
3561            DO = (AssignmentDO)it.next();
3562            if (username.equals(DO.getResourceId())
3563                && actId.equals(DO.getActivityId())) {
3564               //System.out.println("DO from Deleted Buffer:"+DO);
3565
return null;
3566            }
3567         }
3568         DBTransaction dbt = ((SharkDODSTransaction)ti).getDODSTransaction();
3569         query=new AssignmentQuery(dbt);
3570         //set query
3571
query.setQueryActivityId(actId);
3572         query.setQueryResourceId(username);
3573         // Throw an exception if more than one object is found
3574
query.requireUniqueInstance();
3575         DO = query.getNextDO();
3576         ((SharkDODSTransaction)ti)._read(DO);
3577
3578         //System.out.println("RDO from DB:"+DO);
3579
return DO;
3580      }
3581      catch (Throwable JavaDoc t) {
3582         throw new PersistenceException(t);
3583      }
3584   }
3585
3586   protected AssignmentDO[] getAllPersistedAssignments (SharkTransaction ti, String JavaDoc sqlWhere) throws PersistenceException {
3587      AssignmentDO[] DOs=null;
3588
3589      AssignmentQuery query = null;
3590      try {
3591         query=new AssignmentQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3592         if (null != sqlWhere) {
3593            query.getQueryBuilder().addWhere(sqlWhere);
3594         }
3595         DOs = query.getDOArray();
3596         List list = new ArrayList(Arrays.asList(DOs));
3597         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
3598              it.hasNext();) {
3599            Object JavaDoc o = it.next();
3600            int index = list.indexOf(o);
3601            if (-1 != index)
3602               list.remove(o);
3603         }
3604         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO");
3605              it.hasNext();) {
3606            Object JavaDoc o = it.next();
3607            int index = list.indexOf(o);
3608            if (-1 == index)
3609               list.add(o);
3610            else {
3611               list.set(index, o);
3612            }
3613            //if (!list.contains(o))
3614
// list.add(o);
3615
}
3616         DOs = new AssignmentDO[list.size()];
3617         list.toArray(DOs);
3618         return DOs;
3619      }
3620      catch (Throwable JavaDoc t) {
3621         throw new PersistenceException(t);
3622      }
3623   }
3624
3625   protected AndJoinEntryDO[] getPersistedAndJoinEntries (String JavaDoc procId,
3626                                                          String JavaDoc asDefId,
3627                                                          String JavaDoc aDefId,
3628                                                          SharkTransaction ti) throws PersistenceException {
3629      AndJoinEntryDO[] DOs=null;
3630
3631      AndJoinEntryQuery query = null;
3632      try {
3633         query=new AndJoinEntryQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3634         query.setQueryProcess(getPersistedProcessObject(procId,ti));
3635         query.setQueryActivitySetDefinitionId(asDefId);
3636         query.setQueryActivityDefinitionId(aDefId);
3637         DOs = query.getDOArray();
3638         List list = new ArrayList(Arrays.asList(DOs));
3639         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO");
3640              it.hasNext();) {
3641            AndJoinEntryDO ajedo = (AndJoinEntryDO)it.next();
3642            int index = list.indexOf(ajedo);
3643            if (((asDefId==null && ajedo.getActivitySetDefinitionId()==null) || (asDefId!=null && asDefId.equals(ajedo.getActivitySetDefinitionId())))
3644                && (aDefId.equals(ajedo.getActivityDefinitionId()))
3645                && procId.equals(ajedo.getProcess().getId())) {
3646               if (-1 != index)
3647                  list.remove(ajedo);
3648            }
3649         }
3650         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO");
3651              it.hasNext();) {
3652            AndJoinEntryDO ajedo = (AndJoinEntryDO)it.next();
3653            int index = list.indexOf(ajedo);
3654            if (((asDefId==null && ajedo.getActivitySetDefinitionId()==null) || (asDefId!=null && asDefId.equals(ajedo.getActivitySetDefinitionId())))
3655                && (aDefId.equals(ajedo.getActivityDefinitionId()))
3656                && procId.equals(ajedo.getProcess().getId())) {
3657               if (-1 == index)
3658                  list.add(ajedo);
3659               else {
3660                  list.set(index, ajedo);
3661               }
3662            }
3663         }
3664         DOs = new AndJoinEntryDO[list.size()];
3665         list.toArray(DOs);
3666         return DOs;
3667      }
3668      catch (Throwable JavaDoc t) {
3669         throw new PersistenceException(t);
3670      }
3671   }
3672
3673      protected DeadlineDO[] getPersistedDeadlines (String JavaDoc procId,long timeLimitBoundary,SharkTransaction ti) throws PersistenceException {
3674      DeadlineDO[] DOs=null;
3675
3676      DeadlineQuery query = null;
3677      try {
3678         query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3679         query.setQueryProcess(getPersistedProcessObject(procId,ti));
3680         if (timeLimitBoundary>=0) {
3681            query.setQueryTimeLimit(timeLimitBoundary,QueryBuilder.LESS_THAN);
3682         }
3683         DOs = query.getDOArray();
3684         List list = new ArrayList(Arrays.asList(DOs));
3685         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3686              it.hasNext();) {
3687            DeadlineDO ddo = (DeadlineDO)it.next();
3688            int index = list.indexOf(ddo);
3689            if (procId.equals(ddo.getProcess().getId())) {
3690               if (-1 != index)
3691                  list.remove(ddo);
3692            }
3693         }
3694         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3695              it.hasNext();) {
3696            DeadlineDO ddo = (DeadlineDO)it.next();
3697            int index = list.indexOf(ddo);
3698            if (procId.equals(ddo.getProcess().getId())) {
3699               if (-1 == index)
3700                  list.add(ddo);
3701               else {
3702                  list.set(index, ddo);
3703               }
3704            }
3705         }
3706         DOs = new DeadlineDO[list.size()];
3707         list.toArray(DOs);
3708         return DOs;
3709      }
3710      catch (Throwable JavaDoc t) {
3711         throw new PersistenceException(t);
3712      }
3713   }
3714
3715   protected DeadlineDO[] getActivitiesPersistedDeadlines (String JavaDoc actId,long timeLimitBoundary,SharkTransaction ti) throws PersistenceException {
3716      DeadlineDO[] DOs=null;
3717
3718      DeadlineQuery query = null;
3719      try {
3720         query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3721         query.setQueryActivity(getPersistedActivityObject(actId,ti));
3722         if (timeLimitBoundary>=0) {
3723            query.setQueryTimeLimit(timeLimitBoundary,QueryBuilder.LESS_THAN);
3724         }
3725         DOs = query.getDOArray();
3726         List list = new ArrayList(Arrays.asList(DOs));
3727         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3728              it.hasNext();) {
3729            DeadlineDO ddo = (DeadlineDO)it.next();
3730            int index = list.indexOf(ddo);
3731            if (actId.equals(ddo.getActivity().getId())) {
3732               if (-1 != index)
3733                  list.remove(ddo);
3734            }
3735         }
3736         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3737              it.hasNext();) {
3738            DeadlineDO ddo = (DeadlineDO)it.next();
3739            int index = list.indexOf(ddo);
3740            if (actId.equals(ddo.getActivity().getId())) {
3741               if (-1 == index)
3742                  list.add(ddo);
3743               else {
3744                  list.set(index, ddo);
3745               }
3746            }
3747         }
3748         DOs = new DeadlineDO[list.size()];
3749         list.toArray(DOs);
3750         return DOs;
3751      }
3752      catch (Throwable JavaDoc t) {
3753         throw new PersistenceException(t);
3754      }
3755   }
3756
3757   protected DeadlineDO getPersistedObject (DeadlinePersistenceInterface dpe,SharkTransaction ti) throws PersistenceException {
3758      DeadlineDO DO=getPersistedDeadlineObject(dpe.getUniqueId(),ti);
3759
3760      try {
3761         if (DO==null) {
3762            DO=DeadlineDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3763         }
3764         return DO;
3765      }
3766      catch (Throwable JavaDoc t) {
3767         throw new PersistenceException(t);
3768      }
3769   }
3770
3771   protected DeadlineDO getPersistedDeadlineObject (String JavaDoc uniqueId,SharkTransaction ti) throws PersistenceException {
3772
3773      if (uniqueId==null) return null;
3774
3775      DeadlineDO DO=null;
3776      DeadlineQuery query = null;
3777      try {
3778         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3779              it.hasNext();) {
3780            DO = (DeadlineDO)it.next();
3781            if (uniqueId.equals(DO.getCNT()))
3782               return DO;
3783         }
3784         for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO");
3785              it.hasNext();) {
3786            DO = (DeadlineDO)it.next();
3787            if (uniqueId.equals(DO.getCNT()))
3788               return null;
3789         }
3790         query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3791         //set query
3792
query.setQueryCNT(new BigDecimal JavaDoc(uniqueId));
3793         // Throw an exception if more than one object is found
3794
query.requireUniqueInstance();
3795         DO = query.getNextDO();
3796         ((SharkDODSTransaction)ti)._read(DO);
3797
3798         return DO;
3799      }
3800      catch (Throwable JavaDoc t) {
3801         throw new PersistenceException(t);
3802      }
3803   }
3804
3805   protected ProcessDataDO getPersistedObject (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
3806      ProcessDataDO DO=
3807         getPersistedProcessVariableObject(var.getProcessId(),var.getDefinitionId(),ti);
3808
3809      try {
3810         if (DO==null) {
3811            DO=ProcessDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3812         }
3813         return DO;
3814      }
3815      catch (Throwable JavaDoc t) {
3816         throw new PersistenceException(t);
3817      }
3818   }
3819
3820   protected ProcessDataDO getPersistedProcessVariableObject (String JavaDoc procId,
3821                                                              String JavaDoc defId,SharkTransaction ti) throws PersistenceException {
3822      ProcessDataDO DO=null;
3823
3824      ProcessDataQuery query = null;
3825      try {
3826         ProcessDO pDO=getPersistedProcessObject(procId,ti);
3827         if (null != pDO) {
3828            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
3829            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
3830                 it.hasNext();) {
3831               DO = (ProcessDataDO)it.next();
3832               if (defId.equals(DO.getVariableDefinitionId())
3833                   && pOId.equals(DO.oid_getProcess()))
3834                  return DO;
3835            }
3836            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
3837                 it.hasNext();) {
3838               DO = (ProcessDataDO)it.next();
3839               if (defId.equals(DO.getVariableDefinitionId())
3840                   && pOId.equals(DO.oid_getProcess()))
3841                  return null;
3842            }
3843         }
3844         query=new ProcessDataQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3845         //set query
3846
query.setQueryProcess(pDO);
3847         query.setQueryVariableDefinitionId(defId);
3848         // Throw an exception if more than one object is found
3849
query.requireUniqueInstance();
3850         DO = query.getNextDO();
3851         ((SharkDODSTransaction)ti)._read(DO);
3852
3853         return DO;
3854      }
3855      catch (Throwable JavaDoc t) {
3856         throw new PersistenceException(t);
3857      }
3858   }
3859   
3860   protected ProcessDataWOBDO getPersistedObject2 (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
3861      ProcessDataWOBDO DO=
3862         getPersistedProcessVariableObject2(var.getProcessId(),var.getDefinitionId(),ti);
3863
3864      try {
3865         if (DO==null) {
3866            DO=ProcessDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3867         }
3868         return DO;
3869      }
3870      catch (Throwable JavaDoc t) {
3871         throw new PersistenceException(t);
3872      }
3873   }
3874
3875   protected ProcessDataWOBDO getPersistedProcessVariableObject2 (String JavaDoc procId,
3876                                                              String JavaDoc defId,SharkTransaction ti) throws PersistenceException {
3877      ProcessDataWOBDO DO=null;
3878
3879      try {
3880         ProcessDO pDO=getPersistedProcessObject(procId,ti);
3881         if (null != pDO) {
3882            BigDecimal JavaDoc pOId = pDO.get_OId().toBigDecimal();
3883            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO");
3884                 it.hasNext();) {
3885               DO = (ProcessDataWOBDO)it.next();
3886               if (defId.equals(DO.getVariableDefinitionId())
3887                   && pOId.equals(DO.oid_getProcess()))
3888                  return DO;
3889            }
3890            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO");
3891                 it.hasNext();) {
3892               DO = (ProcessDataWOBDO)it.next();
3893               if (defId.equals(DO.getVariableDefinitionId())
3894                   && pOId.equals(DO.oid_getProcess()))
3895                  return null;
3896            }
3897         }
3898         ProcessDataWOBQuery query=new ProcessDataWOBQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3899         //set query
3900
query.setQueryProcess(pDO);
3901         query.setQueryVariableDefinitionId(defId);
3902         // Throw an exception if more than one object is found
3903
query.requireUniqueInstance();
3904         DO = query.getNextDO();
3905         ((SharkDODSTransaction)ti)._read(DO);
3906
3907         return DO;
3908      }
3909      catch (Throwable JavaDoc t) {
3910         throw new PersistenceException(t);
3911      }
3912   }
3913
3914   protected ProcessDataBLOBDO getPersistedObject (ProcessDataWOBDO pdDO,SharkTransaction ti) throws PersistenceException {
3915      ProcessDataBLOBDO DO=
3916         getPersistedProcessVariableBLOBObject(pdDO,ti);
3917
3918      try {
3919         if (DO==null) {
3920            DO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3921         }
3922         return DO;
3923      }
3924      catch (Throwable JavaDoc t) {
3925         throw new PersistenceException(t);
3926      }
3927   }
3928
3929   protected ProcessDataBLOBDO getPersistedProcessVariableBLOBObject (ProcessDataWOBDO pdDO,SharkTransaction ti) throws PersistenceException {
3930      ProcessDataBLOBDO DO=null;
3931
3932      try {
3933         if (null != pdDO) {
3934            BigDecimal JavaDoc pdOId = pdDO.get_OId().toBigDecimal();
3935            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataBLOBDO");
3936                 it.hasNext();) {
3937               DO = (ProcessDataBLOBDO)it.next();
3938               if (pdOId.equals(DO.oid_getProcessDataWOB()))
3939                  return DO;
3940            }
3941            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataBLOBDO");
3942                 it.hasNext();) {
3943               DO = (ProcessDataBLOBDO)it.next();
3944               if (pdOId.equals(DO.oid_getProcessDataWOB()))
3945                  return null;
3946            }
3947         }
3948         ProcessDataBLOBQuery query=new ProcessDataBLOBQuery(((SharkDODSTransaction)ti).getDODSTransaction());
3949         //set query
3950
query.setQueryProcessDataWOB(pdDO);
3951         // Throw an exception if more than one object is found
3952
query.requireUniqueInstance();
3953         DO = query.getNextDO();
3954         ((SharkDODSTransaction)ti)._read(DO);
3955
3956         return DO;
3957      }
3958      catch (Throwable JavaDoc t) {
3959         throw new PersistenceException(t);
3960      }
3961   }
3962
3963   protected ActivityDataDO getPersistedObject (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
3964      ActivityDataDO DO=
3965         getPersistedActivityVariableObject(var.getActivityId(),var.getDefinitionId(),ti);
3966
3967      try {
3968         if (DO==null) {
3969            DO=ActivityDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
3970         }
3971         return DO;
3972      }
3973      catch (Throwable JavaDoc t) {
3974         throw new PersistenceException(t);
3975      }
3976   }
3977
3978   protected ActivityDataDO getPersistedActivityVariableObject (String JavaDoc actId,
3979                                                                String JavaDoc defId,SharkTransaction ti) throws PersistenceException {
3980      ActivityDataDO DO=null;
3981
3982      ActivityDataQuery query = null;
3983      try {
3984         ActivityDO aDO=getPersistedActivityObject(actId,ti);
3985         if (null != aDO) {
3986            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
3987            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
3988                 it.hasNext();) {
3989               DO = (ActivityDataDO)it.next();
3990               if (defId.equals(DO.getVariableDefinitionId())
3991                   && aOId.equals(DO.oid_getActivity()))
3992                  return DO;
3993            }
3994            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataDO");
3995                 it.hasNext();) {
3996               DO = (ActivityDataDO)it.next();
3997               if (defId.equals(DO.getVariableDefinitionId())
3998                   && aOId.equals(DO.oid_getActivity()))
3999                  return null;
4000            }
4001         }
4002         query=new ActivityDataQuery(((SharkDODSTransaction)ti).getDODSTransaction());
4003         //set query
4004

4005         query.setQueryActivity(aDO);
4006         query.setQueryVariableDefinitionId(defId);
4007         // Throw an exception if more than one object is found
4008
query.requireUniqueInstance();
4009         DO = query.getNextDO();
4010         ((SharkDODSTransaction)ti)._read(DO);
4011
4012         return DO;
4013      }
4014      catch (Throwable JavaDoc t) {
4015         throw new PersistenceException(t);
4016      }
4017   }
4018
4019   protected ActivityDataWOBDO getPersistedObject2 (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException {
4020      ActivityDataWOBDO DO=
4021         getPersistedActivityVariableObject2(var.getActivityId(),var.getDefinitionId(),ti);
4022
4023      try {
4024         if (DO==null) {
4025            DO=ActivityDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
4026         }
4027         return DO;
4028      }
4029      catch (Throwable JavaDoc t) {
4030         throw new PersistenceException(t);
4031      }
4032   }
4033
4034   protected ActivityDataWOBDO getPersistedActivityVariableObject2 (String JavaDoc actId,
4035                                                                String JavaDoc defId,SharkTransaction ti) throws PersistenceException {
4036      ActivityDataWOBDO DO=null;
4037
4038      try {
4039         ActivityDO aDO=getPersistedActivityObject(actId,ti);
4040         if (null != aDO) {
4041            BigDecimal JavaDoc aOId = aDO.get_OId().toBigDecimal();
4042            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO");
4043                 it.hasNext();) {
4044               DO = (ActivityDataWOBDO)it.next();
4045               if (defId.equals(DO.getVariableDefinitionId())
4046                   && aOId.equals(DO.oid_getActivity()))
4047                  return DO;
4048            }
4049            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO");
4050                 it.hasNext();) {
4051               DO = (ActivityDataWOBDO)it.next();
4052               if (defId.equals(DO.getVariableDefinitionId())
4053                   && aOId.equals(DO.oid_getActivity()))
4054                  return null;
4055            }
4056         }
4057         ActivityDataWOBQuery query = new ActivityDataWOBQuery(((SharkDODSTransaction)ti).getDODSTransaction());
4058         //set query
4059

4060         query.setQueryActivity(aDO);
4061         query.setQueryVariableDefinitionId(defId);
4062         // Throw an exception if more than one object is found
4063
query.requireUniqueInstance();
4064         DO = query.getNextDO();
4065         ((SharkDODSTransaction)ti)._read(DO);
4066
4067         return DO;
4068      }
4069      catch (Throwable JavaDoc t) {
4070         throw new PersistenceException(t);
4071      }
4072   }
4073
4074   protected ActivityDataBLOBDO getPersistedObject (ActivityDataWOBDO adDO,SharkTransaction ti) throws PersistenceException {
4075      ActivityDataBLOBDO DO=
4076         getPersistedActivityVariableBLOBObject(adDO,ti);
4077
4078      try {
4079         if (DO==null) {
4080            DO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
4081         }
4082         return DO;
4083      }
4084      catch (Throwable JavaDoc t) {
4085         throw new PersistenceException(t);
4086      }
4087   }
4088
4089   protected ActivityDataBLOBDO getPersistedActivityVariableBLOBObject (ActivityDataWOBDO adDO,SharkTransaction ti) throws PersistenceException {
4090      ActivityDataBLOBDO DO=null;
4091
4092      try {
4093         if (null != adDO) {
4094            BigDecimal JavaDoc pdOId = adDO.get_OId().toBigDecimal();
4095            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataBLOBDO");
4096                 it.hasNext();) {
4097               DO = (ActivityDataBLOBDO)it.next();
4098               if (pdOId.equals(DO.oid_getActivityDataWOB()))
4099                  return DO;
4100            }
4101            for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataBLOBDO");
4102                 it.hasNext();) {
4103               DO = (ActivityDataBLOBDO)it.next();
4104               if (pdOId.equals(DO.oid_getActivityDataWOB()))
4105                  return null;
4106            }
4107         }
4108         ActivityDataBLOBQuery query=new ActivityDataBLOBQuery(((SharkDODSTransaction)ti).getDODSTransaction());
4109         //set query
4110
query.setQueryActivityDataWOB(adDO);
4111         // Throw an exception if more than one object is found
4112
query.requireUniqueInstance();
4113         DO = query.getNextDO();
4114         ((SharkDODSTransaction)ti)._read(DO);
4115
4116         return DO;
4117      }
4118      catch (Throwable JavaDoc t) {
4119         throw new PersistenceException(t);
4120      }
4121   }
4122
4123   protected ActivityStateDO getPersistedActivityStateObject (
4124      String JavaDoc value,boolean searchByKeyValue,DBTransaction ti) throws PersistenceException {
4125      ActivityStateDO DO=null;
4126
4127      ActivityStateQuery query = null;
4128      try {
4129         query=new ActivityStateQuery(ti);
4130         //set query
4131
if (searchByKeyValue) {
4132            query.setQueryKeyValue(value);
4133         }
4134         else {
4135            query.setQueryName(value);
4136         }
4137         query.requireUniqueInstance();
4138         DO = query.getNextDO();
4139
4140         if (DO==null) {
4141            DO=ActivityStateDO.createVirgin(ti);
4142         }
4143         return DO;
4144      }
4145      catch (Throwable JavaDoc t) {
4146         t.printStackTrace();
4147         throw new PersistenceException(t);
4148      }
4149   }
4150
4151   protected ProcessStateDO getPersistedProcessStateObject (
4152      String JavaDoc value,boolean searchByKeyValue,DBTransaction ti) throws PersistenceException {
4153      ProcessStateDO DO=null;
4154
4155      ProcessStateQuery query = null;
4156      try {
4157         query=new ProcessStateQuery(ti);
4158         //set query
4159
if (searchByKeyValue) {
4160            query.setQueryKeyValue(value);
4161         }
4162         else {
4163            query.setQueryName(value);
4164         }
4165         query.requireUniqueInstance();
4166         DO = query.getNextDO();
4167
4168         if (DO==null) {
4169            DO=ProcessStateDO.createVirgin(ti);
4170         }
4171         return DO;
4172      }
4173      catch (Throwable JavaDoc t) {
4174         t.printStackTrace();
4175         throw new PersistenceException(t);
4176      }
4177   }
4178
4179   // creation of empty objects
4180
public ActivityPersistenceInterface createActivity () {
4181      return new DODSActivity();
4182   }
4183
4184   public ProcessPersistenceInterface createProcess () {
4185      return new DODSProcess();
4186   }
4187
4188   public ProcessMgrPersistenceInterface createProcessMgr () {
4189      return new DODSProcessMgr();
4190   }
4191
4192   public AssignmentPersistenceInterface createAssignment () {
4193      return new DODSAssignment();
4194   }
4195
4196   public ResourcePersistenceInterface createResource () {
4197      return new DODSResource();
4198   }
4199
4200   public ProcessVariablePersistenceInterface createProcessVariable () {
4201      return new DODSProcessVariable();
4202   }
4203
4204   public ActivityVariablePersistenceInterface createActivityVariable () {
4205      return new DODSActivityVariable();
4206   }
4207
4208   public AndJoinEntryInterface createAndJoinEntry () {
4209      return new DODSAndJoinEntry();
4210   }
4211
4212   public DeadlinePersistenceInterface createDeadline() {
4213      return new DODSDeadline();
4214   }
4215
4216   public BigDecimal JavaDoc getNextDecId(String JavaDoc idName) throws PersistenceException {
4217      try {
4218         return DODSUtilities.getNext(idName);
4219      } catch (Exception JavaDoc e) {
4220         throw new PersistenceException("Couldn't allocate id",e);
4221      }
4222   }
4223
4224   public String JavaDoc getNextId(String JavaDoc idName) throws PersistenceException {
4225      return getNextDecId(idName).toString();
4226   }
4227
4228   public List getProcessMgrsWhere(SharkTransaction ti, String JavaDoc sqlWhere) throws PersistenceException {
4229      List ret = new ArrayList();
4230
4231      ProcessDefinitionDO[] mgrs = getAllPersistedProcessMgrs(ti,
4232                                                              null,
4233                                                              null,
4234                                                              null,
4235                                                              sqlWhere);
4236      if (mgrs != null) {
4237         for (int i = 0; i < mgrs.length; i++) {
4238            ProcessMgrPersistenceInterface mgr = restore(mgrs[i]);
4239            ret.add(mgr);
4240         }
4241      }
4242      return ret;
4243   }
4244
4245   public List getResourcesWhere(SharkTransaction t, String JavaDoc sqlWhere) throws PersistenceException {
4246      List ret=new ArrayList();
4247      if (null != sqlWhere && sqlWhere.trim().length() < 1)
4248         sqlWhere = null;
4249      ResourceDO[] ress=getAllPersistedResources(t, sqlWhere);
4250      if (ress!=null) {
4251         for (int i=0;i<ress.length; i++) {
4252            ResourcePersistenceInterface res=restore(ress[i]);
4253            ret.add(res);
4254         }
4255      }
4256      return ret;
4257   }
4258
4259   public List getAssignmentsWhere(SharkTransaction t, String JavaDoc sqlWhere) throws PersistenceException {
4260      List ret=new ArrayList();
4261
4262      /*long t1,t2,t3;
4263      System.out.println("GPASS start");
4264      t1=System.currentTimeMillis();*/

4265      AssignmentDO[] ass=getAllPersistedAssignments(t, sqlWhere);
4266      //t2=System.currentTimeMillis();
4267
if (ass!=null) {
4268         for (int i=0;i<ass.length; i++) {
4269            try {
4270               if (ass[i].getIsValid()) {
4271                  AssignmentPersistenceInterface as=restore(ass[i]);
4272                  ret.add(as);
4273               }
4274            } catch (Throwable JavaDoc ex) {
4275               throw new PersistenceException(ex);
4276            }
4277         }
4278      }
4279      //t3=System.currentTimeMillis();
4280
//System.out.println("GPASS: T="+(t3-t1)+", T1="+(t2-t1)+", SW="+sqlWhere);
4281
return ret;
4282   }
4283
4284   public List getProcessesWhere(SharkTransaction ti, String JavaDoc sqlWhere) throws PersistenceException {
4285         List ret=new ArrayList();
4286         /*long t1,t2,t3;
4287         System.out.println("GPW start");
4288         t1=System.currentTimeMillis();*/

4289         ProcessDO[] procs=getPersistedProcesses(ti,0,null,null,null,null,sqlWhere);
4290
4291         try {
4292            //t2=System.currentTimeMillis();
4293
if (procs!=null) {
4294               for (int i=0;i<procs.length; i++) {
4295                  ProcessPersistenceInterface proc=restore(procs[i]);
4296                  ret.add(proc);
4297               }
4298            }
4299            //t3=System.currentTimeMillis();
4300
//System.out.println("GPW: T="+(t3-t1)+", T1="+(t2-t1)+", SW="+sqlWhere);
4301
return ret;
4302         } catch (Exception JavaDoc e) {
4303            throw new PersistenceException(e);
4304         }
4305      }
4306
4307   public List getActivitiesWhere(SharkTransaction ti, String JavaDoc sqlWhere) throws PersistenceException {
4308      List ret=new ArrayList();
4309      /*System.out.println("GAW start");
4310      long t1,t2,t3;
4311      t1=System.currentTimeMillis();*/

4312      ActivityDO[] acts=getPersistedActivities(ti,0,null,sqlWhere);
4313      //t2=System.currentTimeMillis();
4314
if (acts!=null) {
4315         for (int i=0;i<acts.length; i++) {
4316            ActivityPersistenceInterface act=restore(acts[i]);
4317            ret.add(act);
4318         }
4319      }
4320      //t3=System.currentTimeMillis();
4321
//System.out.println("GAW: T="+(t3-t1)+", T1="+(t2-t1));
4322
return ret;
4323   }
4324
4325
4326// protected static final String bigStringA="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
4327
// protected static final String bigStringB="BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
4328
// protected static final String bigStringC="CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
4329
//
4330
// protected long initNoOfPDefs, initNoOfProcesses, initNoOfActivities;
4331
// protected long curNoOfPDefs, curNoOfProcesses, curNoOfActivities;
4332
//
4333
// protected boolean initedForTests=false;
4334
//
4335
// protected long curentTime;
4336
//
4337
// protected PrintStream testOverallCreationStream=null;
4338
// protected PrintStream testProcDefCreationStream=null;
4339
// protected PrintStream testProcessCreationStream=null;
4340
// protected PrintStream testActivityCreationStream=null;
4341
// protected PrintStream testIndexedProcDefQueriesStream=null;
4342
// protected PrintStream testIndexedProcessQueriesStream=null;
4343
// protected PrintStream testIndexedActivityQueriesStream=null;
4344
// protected PrintStream testNonIndexedProcDefQueriesStream=null;
4345
// protected PrintStream testNonIndexedProcessQueriesStream=null;
4346
// protected PrintStream testNonIndexedActivityQueriesStream=null;
4347
// protected PrintStream testProcDefDeletionStream=null;
4348
// protected PrintStream testProcessDeletionStream=null;
4349
// protected PrintStream testActivityDeletionStream=null;
4350
//
4351
// protected String commentForLog="";
4352
//
4353
// public static void main (String[] args) throws Throwable {
4354
//
4355
// if (args==null || args.length<5) {
4356
// printUsage();
4357
// System.exit(1);
4358
// }
4359
// String configFilePath=args[0];
4360
// String logFilePrefix=args[1];
4361
// String testType=args[2];
4362
// int transactionCount = new Integer(args[3]).intValue();
4363
// int noOfOpPerTransaction = new Integer(args[4]).intValue();
4364
//
4365
// DODSPersistentManager pManager=new DODSPersistentManager();
4366
// if (args.length>5) {
4367
// pManager.commentForLog = args[5];
4368
// }
4369
// pManager.initForTests(configFilePath,logFilePrefix);
4370
//
4371
// if (testType.equals("all") || testType.equals("allnodel")) {
4372
// pManager.testOverallCreation(transactionCount,noOfOpPerTransaction);
4373
// pManager.testProcDefCreation(transactionCount,noOfOpPerTransaction);
4374
// pManager.testProcessCreation(transactionCount,noOfOpPerTransaction);
4375
// pManager.testActivityCreation(transactionCount,noOfOpPerTransaction);
4376
// pManager.testIndexedPDefQueries(transactionCount,noOfOpPerTransaction);
4377
// pManager.testIndexedProcessQueries(transactionCount,noOfOpPerTransaction);
4378
// pManager.testIndexedActivityQueries(transactionCount,noOfOpPerTransaction);
4379
// pManager.testNonIndexedPDefQueries(transactionCount,noOfOpPerTransaction);
4380
// pManager.testNonIndexedProcessQueries(transactionCount,noOfOpPerTransaction);
4381
// pManager.testNonIndexedActivityQueries(transactionCount,noOfOpPerTransaction);
4382
// if (testType.equals("all")) {
4383
// pManager.testActivityDeletion(transactionCount,noOfOpPerTransaction);
4384
// pManager.testProcessDeletion(transactionCount,noOfOpPerTransaction);
4385
// pManager.testProcDefDeletion(transactionCount,noOfOpPerTransaction);
4386
// }
4387
// } else if (testType.equals("ocre")) {
4388
// pManager.testOverallCreation(transactionCount,noOfOpPerTransaction);
4389
// } else if (testType.equals("pdcre")) {
4390
// pManager.testProcDefCreation(transactionCount,noOfOpPerTransaction);
4391
// } else if (testType.equals("pcre")) {
4392
// pManager.testProcessCreation(transactionCount,noOfOpPerTransaction);
4393
// } else if (testType.equals("acre")) {
4394
// pManager.testActivityCreation(transactionCount,noOfOpPerTransaction);
4395
// } else if (testType.equals("ipdq")) {
4396
// pManager.testIndexedPDefQueries(transactionCount,noOfOpPerTransaction);
4397
// } else if (testType.equals("ipq")) {
4398
// pManager.testIndexedProcessQueries(transactionCount,noOfOpPerTransaction);
4399
// } else if (testType.equals("iaq")) {
4400
// pManager.testIndexedActivityQueries(transactionCount,noOfOpPerTransaction);
4401
// } else if (testType.equals("nipdq")) {
4402
// pManager.testNonIndexedPDefQueries(transactionCount,noOfOpPerTransaction);
4403
// } else if (testType.equals("nipq")) {
4404
// pManager.testNonIndexedProcessQueries(transactionCount,noOfOpPerTransaction);
4405
// } else if (testType.equals("niaq")) {
4406
// pManager.testNonIndexedActivityQueries(transactionCount,noOfOpPerTransaction);
4407
// } else if (testType.equals("pddel")) {
4408
// pManager.testProcDefDeletion(transactionCount,noOfOpPerTransaction);
4409
// } else if (testType.equals("pdel")) {
4410
// pManager.testProcessDeletion(transactionCount,noOfOpPerTransaction);
4411
// } else if (testType.equals("adel")) {
4412
// pManager.testActivityDeletion(transactionCount,noOfOpPerTransaction);
4413
// } else {
4414
// printUsage();
4415
// System.exit(1);
4416
// }
4417
//
4418
// pManager.testCleanup();
4419
// }
4420
//
4421
// public void initForTests (String configFilePath,String logFilePrefix) {
4422
// _prStates = new HashMap();
4423
// _acStates = new HashMap();
4424
// _prClosedStatesBigDecimals = new ArrayList();
4425
// _actClosedStatesBigDecimals = new ArrayList();
4426
// _actOpenStatesBigDecimals = new ArrayList();
4427
//
4428
// String userDir=System.getProperty("user.dir");
4429
//
4430
// File configFile=new File(configFilePath);
4431
// if (!configFile.exists()) {
4432
// String cfp=userDir+File.separator+configFilePath;
4433
// configFile=new File(cfp);
4434
// if (!configFile.exists()) {
4435
// System.out.println("Configuration file can't be found at "+cfp);
4436
// System.exit(1);
4437
// }
4438
//
4439
// }
4440
// try {
4441
//
4442
// Properties props=new Properties();
4443
// FileInputStream fis=new FileInputStream(configFile);
4444
// props.load(fis);
4445
// fis.close();
4446
// DODSUtilities.init(props);
4447
// //DODS.startup(userDir+File.separator+"conf/Shark.conf");
4448
// initActivityAndProcessStatesTable();
4449
// initObjectCount();
4450
//
4451
// File testFile = new File(logFilePrefix+" - testOverallCreationLog");
4452
// OutputStream fos = new FileOutputStream(testFile,true);
4453
// testOverallCreationStream = new PrintStream(fos);
4454
//
4455
// testFile = new File(logFilePrefix+" - testProcDefCreationLog");
4456
// fos = new FileOutputStream(testFile,true);
4457
// testProcDefCreationStream = new PrintStream(fos);
4458
//
4459
// testFile = new File(logFilePrefix+" - testProcessCreationLog");
4460
// fos = new FileOutputStream(testFile,true);
4461
// testProcessCreationStream = new PrintStream(fos);
4462
//
4463
// testFile = new File(logFilePrefix+" - testActivityCreationLog");
4464
// fos = new FileOutputStream(testFile,true);
4465
// testActivityCreationStream = new PrintStream(fos);
4466
//
4467
// testFile = new File(logFilePrefix+" - testIndexedProcDefQueriesLog");
4468
// fos = new FileOutputStream(testFile,true);
4469
// testIndexedProcDefQueriesStream = new PrintStream(fos);
4470
//
4471
// testFile = new File(logFilePrefix+" - testIndexedProcessQueriesLog");
4472
// fos = new FileOutputStream(testFile,true);
4473
// testIndexedProcessQueriesStream = new PrintStream(fos);
4474
//
4475
// testFile = new File(logFilePrefix+" - testIndexedActivityQueriesLog");
4476
// fos = new FileOutputStream(testFile,true);
4477
// testIndexedActivityQueriesStream = new PrintStream(fos);
4478
//
4479
// testFile = new File(logFilePrefix+" - testNonIndexedProcDefQueriesLog");
4480
// fos = new FileOutputStream(testFile,true);
4481
// testNonIndexedProcDefQueriesStream = new PrintStream(fos);
4482
//
4483
// testFile = new File(logFilePrefix+" - testNonIndexedProcessQueriesLog");
4484
// fos = new FileOutputStream(testFile,true);
4485
// testNonIndexedProcessQueriesStream = new PrintStream(fos);
4486
//
4487
// testFile = new File(logFilePrefix+" - testNonIndexedActivityQueriesLog");
4488
// fos = new FileOutputStream(testFile,true);
4489
// testNonIndexedActivityQueriesStream = new PrintStream(fos);
4490
//
4491
// testFile = new File(logFilePrefix+" - testProcDefDeletionLog");
4492
// fos = new FileOutputStream(testFile,true);
4493
// testProcDefDeletionStream = new PrintStream(fos);
4494
//
4495
// testFile = new File(logFilePrefix+" - testProcessDeletionLog");
4496
// fos = new FileOutputStream(testFile,true);
4497
// testProcessDeletionStream = new PrintStream(fos);
4498
//
4499
// testFile = new File(logFilePrefix+" - testActivityDeletionLog");
4500
// fos = new FileOutputStream(testFile,true);
4501
// testActivityDeletionStream = new PrintStream(fos);
4502
//
4503
// } catch (Exception ex) {
4504
// ex.printStackTrace();
4505
// System.exit(1);
4506
// }
4507
//
4508
// initedForTests=true;
4509
// }
4510
//
4511
// public void testCleanup () {
4512
// initedForTests=false;
4513
// try {
4514
// testOverallCreationStream.close();
4515
// testProcDefCreationStream.close();
4516
// testProcessCreationStream.close();
4517
// testActivityCreationStream.close();
4518
// testIndexedProcDefQueriesStream.close();
4519
// testIndexedProcessQueriesStream.close();
4520
// testIndexedActivityQueriesStream.close();
4521
// testNonIndexedProcDefQueriesStream.close();
4522
// testNonIndexedProcessQueriesStream.close();
4523
// testNonIndexedActivityQueriesStream.close();
4524
// testProcDefDeletionStream.close();
4525
// testProcessDeletionStream.close();
4526
// testActivityDeletionStream.close();
4527
// DODS.shutdown();
4528
// } catch (Exception ex) {
4529
// ex.printStackTrace();
4530
// }
4531
// System.exit(0);
4532
// }
4533
//
4534
// public void testOverallCreation (int transactionCount,int topObjectRowsToInsertPerTransaction) {
4535
// if (!initedForTests) {
4536
// initForTests("conf/Shark.conf","Default");
4537
// }
4538
//
4539
// String testStartMsg=transactionCount+" times creating "+topObjectRowsToInsertPerTransaction+" proc defs and its children: \ntest started at "+(new java.util.Date().toString())+" - Initial no of objects in DB=["+curNoOfPDefs+","+curNoOfProcesses+","+curNoOfActivities+"]";
4540
// writeInitMsg(testOverallCreationStream,testStartMsg,-1);
4541
//
4542
// try{
4543
// DBTransaction dbTrans = null;
4544
// long overallTime=0;
4545
// for(int k=0;k<transactionCount;k++){
4546
// resetCurentTime();
4547
// dbTrans = DODS.getDatabaseManager().createTransaction();
4548
// for (int i=0; i<topObjectRowsToInsertPerTransaction;i++){
4549
// ProcessDefinitionDO pdefDO= ProcessDefinitionDO.createVirgin(dbTrans);
4550
// String keyAStr=String.valueOf(curNoOfPDefs);
4551
// pdefDO.setName(keyAStr);
4552
// pdefDO.setPackageId(keyAStr);
4553
// pdefDO.setProcessDefinitionId(bigStringA);
4554
// pdefDO.setProcessDefinitionCreated(bigStringA);
4555
// pdefDO.setProcessDefinitionVersion("ThisMustBeShort");
4556
// pdefDO.setState(0);
4557
//
4558
// for (int i2=0; i2<topObjectRowsToInsertPerTransaction; i2++) {
4559
// String keyBStr=String.valueOf(curNoOfProcesses);
4560
// ProcessDO pDO=ProcessDO.createVirgin(dbTrans);
4561
// pDO.setId(keyBStr);
4562
// pDO.setProcessDefinition(pdefDO);
4563
// pDO.setName(keyBStr);
4564
// pDO.setDescription(bigStringB);
4565
// pDO.oid_setState((BigDecimal)_prStates.get("open.running"));
4566
//
4567
// for (int i3=0; i3<topObjectRowsToInsertPerTransaction; i3++) {
4568
// String keyCStr=String.valueOf(curNoOfActivities);
4569
// ActivityDO aDO=ActivityDO.createVirgin(dbTrans);
4570
// aDO.setId(keyCStr);
4571
// aDO.setProcess(pDO);
4572
// aDO.setActivityDefinitionId(keyCStr);
4573
// aDO.setDescription(bigStringC);
4574
// aDO.setName(bigStringC);
4575
// aDO.oid_setState((BigDecimal)_acStates.get("open.running"));
4576
// aDO.save();
4577
// curNoOfActivities++;
4578
// }
4579
// pDO.save();
4580
// curNoOfProcesses++;
4581
// }
4582
// pdefDO.save();
4583
// curNoOfPDefs++;
4584
// }
4585
// dbTrans.commit();
4586
// overallTime+=writeTimeDiff(testOverallCreationStream);
4587
// }
4588
// String summary=String.valueOf(curNoOfPDefs)+";"+String.valueOf(overallTime/transactionCount);
4589
// writeSummary(testOverallCreationStream,summary);
4590
// } catch (Exception e){
4591
// e.printStackTrace();
4592
// System.exit(1);
4593
// }
4594
// }
4595
//
4596
// public void testProcDefCreation (int transactionCount,int howManyPerTransaction) {
4597
// if (!initedForTests) {
4598
// initForTests("conf/Shark.conf","Default");
4599
// }
4600
//
4601
// String testStartMsg=transactionCount+" times creating "+howManyPerTransaction+" proc defs: \ntest started at "+(new java.util.Date().toString());
4602
// writeInitMsg(testProcDefCreationStream,testStartMsg,curNoOfPDefs);
4603
//
4604
// try{
4605
// DBTransaction dbTrans = null;
4606
// long overallTime=0;
4607
// for(int k=0;k<transactionCount;k++){
4608
// resetCurentTime();
4609
// dbTrans = DODS.getDatabaseManager().createTransaction();
4610
// for (int i=0; i<howManyPerTransaction; i++){
4611
// ProcessDefinitionDO pdefDO= ProcessDefinitionDO.createVirgin(dbTrans);
4612
// String keyAStr=String.valueOf(curNoOfPDefs);
4613
// pdefDO.setName(keyAStr);
4614
// pdefDO.setPackageId(keyAStr);
4615
// pdefDO.setProcessDefinitionId(bigStringA);
4616
// pdefDO.setProcessDefinitionCreated(bigStringA);
4617
// pdefDO.setProcessDefinitionVersion("ThisMustBeShort");
4618
// pdefDO.setState(0);
4619
// pdefDO.save();
4620
// curNoOfPDefs++;
4621
// }
4622
// dbTrans.commit();
4623
// overallTime+=writeTimeDiff(testProcDefCreationStream);
4624
// }
4625
// String summary=String.valueOf(curNoOfPDefs)+";"+String.valueOf(overallTime/transactionCount);
4626
// writeSummary(testProcDefCreationStream,summary);
4627
// } catch (Exception e){
4628
// e.printStackTrace();
4629
// System.exit(1);
4630
// }
4631
// }
4632
//
4633
// public void testProcessCreation (int transactionCount,int howManyPerTransaction) {
4634
// if (!initedForTests) {
4635
// initForTests("conf/Shark.conf","Default");
4636
// }
4637
//
4638
// String testStartMsg=transactionCount+" times creating "+howManyPerTransaction+" processes: \ntest started at "+(new java.util.Date().toString());
4639
// writeInitMsg(testProcessCreationStream,testStartMsg,curNoOfProcesses);
4640
//
4641
// try{
4642
// long overallTime=0;
4643
// DBTransaction dbTrans = null;
4644
// for(int k=0;k<transactionCount;k++){
4645
// dbTrans = DODS.getDatabaseManager().createTransaction();
4646
//
4647
// ProcessDefinitionDO pdefDO=null;
4648
// if (curNoOfPDefs>0) {
4649
// ProcessDefinitionQuery query = new ProcessDefinitionQuery(dbTrans);
4650
// query.requireUniqueInstance();
4651
// String uniqueFieldValue=String.valueOf((long)(curNoOfPDefs*Math.random()));
4652
// query.setQueryName(uniqueFieldValue);
4653
// pdefDO=query.getNextDO();
4654
// } else {
4655
// System.out.println("Can't create processes because there are no process definitions in DB.");
4656
// dbTrans.release();
4657
// return;
4658
// }
4659
//
4660
// resetCurentTime();
4661
// for (int i2=0; i2<howManyPerTransaction; i2++) {
4662
// String keyBStr=String.valueOf(curNoOfProcesses);
4663
// ProcessDO pDO=ProcessDO.createVirgin(dbTrans);
4664
// pDO.setId(keyBStr);
4665
// pDO.setProcessDefinition(pdefDO);
4666
// pDO.setName(keyBStr);
4667
// pDO.setDescription(bigStringB);
4668
// pDO.oid_setState((BigDecimal)_prStates.get("open.running"));
4669
// pDO.save();
4670
// curNoOfProcesses++;
4671
// }
4672
// dbTrans.commit();
4673
// overallTime+=writeTimeDiff(testProcessCreationStream);
4674
// }
4675
// String summary=String.valueOf(curNoOfProcesses)+";"+String.valueOf(overallTime/transactionCount);
4676
// writeSummary(testProcessCreationStream,summary);
4677
// } catch (Exception e){
4678
// e.printStackTrace();
4679
// System.exit(1);
4680
// }
4681
// }
4682
//
4683
// public void testActivityCreation (int transactionCount,int howManyPerTransaction) {
4684
// if (!initedForTests) {
4685
// initForTests("conf/Shark.conf","Default");
4686
// }
4687
//
4688
// String testStartMsg=transactionCount+" times creating "+howManyPerTransaction+" activities: \ntest started at "+(new java.util.Date().toString());
4689
// writeInitMsg(testActivityCreationStream,testStartMsg,curNoOfActivities);
4690
//
4691
// try{
4692
// DBTransaction dbTrans = null;
4693
// long overallTime=0;
4694
// for(int k=0;k<transactionCount;k++){
4695
//
4696
// dbTrans = DODS.getDatabaseManager().createTransaction();
4697
//
4698
// ProcessDO pDO=null;
4699
// if (curNoOfProcesses>0) {
4700
// ProcessQuery query = new ProcessQuery(dbTrans);
4701
// query.requireUniqueInstance();
4702
// String uniqueFieldValue=String.valueOf((long)(curNoOfProcesses*Math.random()));
4703
// query.setQueryName(uniqueFieldValue);
4704
// pDO=query.getNextDO();
4705
// } else {
4706
// System.out.println("Can't create activities because there are no processes in DB.");
4707
// dbTrans.release();
4708
// return;
4709
// }
4710
//
4711
// resetCurentTime();
4712
// for (int i3=0; i3<howManyPerTransaction; i3++) {
4713
// String keyCStr=String.valueOf(curNoOfActivities);
4714
// ActivityDO aDO=ActivityDO.createVirgin(dbTrans);
4715
// aDO.setId(keyCStr);
4716
// aDO.setProcess(pDO);
4717
// aDO.setActivityDefinitionId(keyCStr);
4718
// aDO.setDescription(bigStringC);
4719
// aDO.setName(bigStringC);
4720
// aDO.oid_setState((BigDecimal)_acStates.get("open.running"));
4721
// aDO.save();
4722
// curNoOfActivities++;
4723
// }
4724
// dbTrans.commit();
4725
// overallTime+=writeTimeDiff(testActivityCreationStream);
4726
// }
4727
// String summary=String.valueOf(curNoOfActivities)+";"+String.valueOf(overallTime/transactionCount);
4728
// writeSummary(testActivityCreationStream,summary);
4729
//
4730
// } catch (Exception e){
4731
// e.printStackTrace();
4732
// System.exit(1);
4733
// }
4734
// }
4735
//
4736
// public void testIndexedPDefQueries (int transactionCount,int queryCount) {
4737
// if (!initedForTests) {
4738
// initForTests("conf/Shark.conf","Default");
4739
// }
4740
//
4741
// String testStartMsg=transactionCount+" times querying for "+queryCount+" proc defs: \ntest started at "+(new java.util.Date().toString());
4742
// writeInitMsg(testIndexedProcDefQueriesStream,testStartMsg,curNoOfPDefs);
4743
//
4744
// try{
4745
// DBTransaction dbTrans=null;
4746
// long overallTime=0;
4747
// for(int k=0;k<transactionCount;k++){
4748
// resetCurentTime();
4749
// dbTrans = DODS.getDatabaseManager().createTransaction();
4750
// for (int i=0; i<queryCount;i++){
4751
// ProcessDefinitionQuery query = new ProcessDefinitionQuery(dbTrans);
4752
// query.requireUniqueInstance();
4753
// String uniqueFieldValue=String.valueOf((long)(curNoOfPDefs*Math.random()));
4754
// query.setQueryName(uniqueFieldValue);
4755
// ProcessDefinitionDO DO=query.getNextDO();
4756
// }
4757
// dbTrans.release();
4758
// overallTime+=writeTimeDiff(testIndexedProcDefQueriesStream);
4759
// }
4760
// String summary=String.valueOf(curNoOfPDefs)+";"+String.valueOf(overallTime/transactionCount);
4761
// writeSummary(testIndexedProcDefQueriesStream,summary);
4762
// } catch (Exception e){
4763
// e.printStackTrace();
4764
// System.exit(1);
4765
// }
4766
// }
4767
//
4768
// public void testIndexedProcessQueries (int transactionCount,int queryCount) {
4769
// if (!initedForTests) {
4770
// initForTests("conf/Shark.conf","Default");
4771
// }
4772
//
4773
// String testStartMsg=transactionCount+" times querying for "+queryCount+" processes: \ntest started at "+(new java.util.Date().toString());
4774
// writeInitMsg(testIndexedProcessQueriesStream,testStartMsg,curNoOfProcesses);
4775
// try{
4776
// DBTransaction dbTrans=null;
4777
// long overallTime=0;
4778
// for(int k=0;k<transactionCount;k++){
4779
// resetCurentTime();
4780
// dbTrans = DODS.getDatabaseManager().createTransaction();
4781
// for (int i=0; i<queryCount;i++){
4782
// ProcessQuery query = new ProcessQuery(dbTrans);
4783
// query.requireUniqueInstance();
4784
// String uniqueFieldValue=String.valueOf((long)(curNoOfProcesses*Math.random()));
4785
// query.setQueryId(uniqueFieldValue);
4786
// ProcessDO DO=query.getNextDO();
4787
// }
4788
// dbTrans.release();
4789
// overallTime+=writeTimeDiff(testIndexedProcessQueriesStream);
4790
// }
4791
// String summary=String.valueOf(curNoOfProcesses)+";"+String.valueOf(overallTime/transactionCount);
4792
// writeSummary(testIndexedProcessQueriesStream,summary);
4793
// } catch (Exception e){
4794
// e.printStackTrace();
4795
// System.exit(1);
4796
// }
4797
// }
4798
//
4799
// public void testIndexedActivityQueries (int transactionCount,int queryCount) {
4800
// if (!initedForTests) {
4801
// initForTests("conf/Shark.conf","Default");
4802
// }
4803
//
4804
// String testStartMsg=transactionCount+" times querying for "+queryCount+" activities: \ntest started at "+(new java.util.Date().toString());
4805
// writeInitMsg(testIndexedActivityQueriesStream,testStartMsg,curNoOfActivities);
4806
// try{
4807
// DBTransaction dbTrans=null;
4808
// long overallTime=0;
4809
// for(int k=0;k<transactionCount;k++){
4810
// resetCurentTime();
4811
// dbTrans = DODS.getDatabaseManager().createTransaction();
4812
// for (int i=0; i<queryCount;i++){
4813
// ActivityQuery query = new ActivityQuery(dbTrans);
4814
// //query.requireUniqueInstance();
4815
// String uniqueFieldValue=String.valueOf((long)(curNoOfActivities*Math.random()));
4816
// query.setQueryId(uniqueFieldValue);
4817
// ActivityDO DO=query.getNextDO();
4818
// }
4819
// dbTrans.release();
4820
// overallTime+=writeTimeDiff(testIndexedActivityQueriesStream);
4821
// }
4822
// String summary=String.valueOf(curNoOfActivities)+";"+String.valueOf(overallTime/transactionCount);
4823
// writeSummary(testIndexedActivityQueriesStream,summary);
4824
// } catch (Exception e){
4825
// e.printStackTrace();
4826
// System.exit(1);
4827
// }
4828
// }
4829
//
4830
// public void testNonIndexedPDefQueries (int transactionCount,int queryCount) {
4831
// if (!initedForTests) {
4832
// initForTests("conf/Shark.conf","Default");
4833
// }
4834
//
4835
// String testStartMsg=transactionCount+" times querying for "+queryCount+" proc defs: \ntest started at "+(new java.util.Date().toString());
4836
// writeInitMsg(testNonIndexedProcDefQueriesStream,testStartMsg,curNoOfPDefs);
4837
// try{
4838
// DBTransaction dbTrans=null;
4839
// long overallTime=0;
4840
// for(int k=0;k<transactionCount;k++){
4841
// resetCurentTime();
4842
// dbTrans = DODS.getDatabaseManager().createTransaction();
4843
// for (int i=0; i<queryCount;i++){
4844
// ProcessDefinitionQuery query = new ProcessDefinitionQuery(dbTrans);
4845
// String uniqueFieldValue=String.valueOf((long)(curNoOfPDefs*Math.random()));
4846
// query.setQueryPackageId(uniqueFieldValue);
4847
// ProcessDefinitionDO DO=query.getNextDO();
4848
// }
4849
// dbTrans.release();
4850
// overallTime+=writeTimeDiff(testNonIndexedProcDefQueriesStream);
4851
// }
4852
// String summary=String.valueOf(curNoOfPDefs)+";"+String.valueOf(overallTime/transactionCount);
4853
// writeSummary(testNonIndexedProcDefQueriesStream,summary);
4854
// } catch (Exception e){
4855
// e.printStackTrace();
4856
// System.exit(1);
4857
// }
4858
// }
4859
//
4860
// public void testNonIndexedProcessQueries (int transactionCount,int queryCount) {
4861
// if (!initedForTests) {
4862
// initForTests("conf/Shark.conf","Default");
4863
// }
4864
//
4865
// String testStartMsg=transactionCount+" times querying for "+queryCount+" processes: \ntest started at "+(new java.util.Date().toString());
4866
// writeInitMsg(testNonIndexedProcessQueriesStream,testStartMsg,curNoOfProcesses);
4867
// try{
4868
// DBTransaction dbTrans=null;
4869
// long overallTime=0;
4870
// for(int k=0;k<transactionCount;k++){
4871
// resetCurentTime();
4872
// dbTrans = DODS.getDatabaseManager().createTransaction();
4873
// for (int i=0; i<queryCount;i++){
4874
// ProcessQuery query = new ProcessQuery(dbTrans);
4875
// String uniqueFieldValue=String.valueOf((long)(curNoOfProcesses*Math.random()));
4876
// query.setQueryName(uniqueFieldValue);
4877
// ProcessDO DO=query.getNextDO();
4878
// }
4879
// dbTrans.release();
4880
// overallTime+=writeTimeDiff(testNonIndexedProcessQueriesStream);
4881
// }
4882
// String summary=String.valueOf(curNoOfProcesses)+";"+String.valueOf(overallTime/transactionCount);
4883
// writeSummary(testNonIndexedProcessQueriesStream,summary);
4884
// } catch (Exception e){
4885
// e.printStackTrace();
4886
// System.exit(1);
4887
// }
4888
// }
4889
//
4890
// public void testNonIndexedActivityQueries (int transactionCount,int queryCount) {
4891
// if (!initedForTests) {
4892
// initForTests("conf/Shark.conf","Default");
4893
// }
4894
//
4895
// String testStartMsg=transactionCount+" times querying for "+queryCount+" activities: \ntest started at "+(new java.util.Date().toString());
4896
// writeInitMsg(testNonIndexedActivityQueriesStream,testStartMsg,curNoOfActivities);
4897
// try{
4898
// DBTransaction dbTrans=null;
4899
// long overallTime=0;
4900
// for(int k=0;k<transactionCount;k++){
4901
// resetCurentTime();
4902
// dbTrans = DODS.getDatabaseManager().createTransaction();
4903
// for (int i=0; i<queryCount;i++){
4904
// ActivityQuery query = new ActivityQuery(dbTrans);
4905
// query.requireUniqueInstance();
4906
// String uniqueFieldValue=String.valueOf((long)(curNoOfActivities*Math.random()));
4907
// query.setQueryActivityDefinitionId(uniqueFieldValue);
4908
// ActivityDO DO=query.getNextDO();
4909
// }
4910
// dbTrans.release();
4911
// overallTime+=writeTimeDiff(testNonIndexedActivityQueriesStream);
4912
// }
4913
// String summary=String.valueOf(curNoOfActivities)+";"+String.valueOf(overallTime/transactionCount);
4914
// writeSummary(testNonIndexedActivityQueriesStream,summary);
4915
//
4916
// } catch (Exception e){
4917
// e.printStackTrace();
4918
// System.exit(1);
4919
// }
4920
// }
4921
//
4922
// public void testProcDefDeletion (int transactionCount,int deleteCount) {
4923
// if (!initedForTests) {
4924
// initForTests("conf/Shark.conf","Default");
4925
// }
4926
//
4927
// String testStartMsg=transactionCount+" times deleting "+deleteCount+" proc defs: \ntest started at "+(new java.util.Date().toString());
4928
// writeInitMsg(testProcDefDeletionStream,testStartMsg,curNoOfPDefs);
4929
// try{
4930
// DBTransaction dbTrans=null;
4931
// long overallTime=0;
4932
// for(int k=0;k<transactionCount;k++){
4933
// resetCurentTime();
4934
// dbTrans = DODS.getDatabaseManager().createTransaction();
4935
// for (int i=0; i<deleteCount;i++){
4936
// ProcessDefinitionQuery query = new ProcessDefinitionQuery(dbTrans);
4937
// query.requireUniqueInstance();
4938
// if (curNoOfPDefs<=0) {
4939
// System.out.println("No more Process definitions to delete");
4940
// break;
4941
// }
4942
// String uniqueFieldValue=String.valueOf(curNoOfPDefs-1);
4943
// query.setQueryName(uniqueFieldValue);
4944
// ProcessDefinitionDO DO=query.getNextDO();
4945
// DO.delete(dbTrans);
4946
// curNoOfPDefs--;
4947
// }
4948
// dbTrans.commit();
4949
// overallTime+=writeTimeDiff(testProcDefDeletionStream);
4950
// }
4951
// String summary=String.valueOf(curNoOfPDefs)+";"+String.valueOf(overallTime/transactionCount);
4952
// writeSummary(testProcDefDeletionStream,summary);
4953
// } catch (Exception e){
4954
// e.printStackTrace();
4955
// System.exit(1);
4956
// }
4957
// }
4958
//
4959
// public void testProcessDeletion (int transactionCount,int deleteCount) {
4960
// if (!initedForTests) {
4961
// initForTests("conf/Shark.conf","Default");
4962
// }
4963
//
4964
// String testStartMsg=transactionCount+" times deleting "+deleteCount+" processes: \ntest started at "+(new java.util.Date().toString());
4965
// writeInitMsg(testProcessDeletionStream,testStartMsg,curNoOfProcesses);
4966
// try{
4967
// DBTransaction dbTrans=null;
4968
// long overallTime=0;
4969
// for(int k=0;k<transactionCount;k++){
4970
// resetCurentTime();
4971
// dbTrans = DODS.getDatabaseManager().createTransaction();
4972
// for (int i=0; i<deleteCount;i++){
4973
// ProcessQuery query = new ProcessQuery(dbTrans);
4974
// query.requireUniqueInstance();
4975
// if (curNoOfProcesses<=0) {
4976
// System.out.println("No more Processes to delete");
4977
// break;
4978
// }
4979
// String uniqueFieldValue=String.valueOf(curNoOfProcesses-1);
4980
// query.setQueryId(uniqueFieldValue);
4981
// ProcessDO DO=query.getNextDO();
4982
// DO.delete(dbTrans);
4983
// curNoOfProcesses--;
4984
// }
4985
// dbTrans.commit();
4986
// overallTime+=writeTimeDiff(testProcessDeletionStream);
4987
// }
4988
// String summary=String.valueOf(curNoOfProcesses)+";"+String.valueOf(overallTime/transactionCount);
4989
// writeSummary(testProcessDeletionStream,summary);
4990
// } catch (Exception e){
4991
// e.printStackTrace();
4992
// System.exit(1);
4993
// }
4994
// }
4995
//
4996
// public void testActivityDeletion (int transactionCount,int deleteCount) {
4997
// if (!initedForTests) {
4998
// initForTests("conf/Shark.conf","Default");
4999
// }
5000
//
5001
// String testStartMsg=transactionCount+" times deleting "+deleteCount+" activities: \ntest started at "+(new java.util.Date().toString());
5002
// writeInitMsg(testActivityDeletionStream,testStartMsg,curNoOfActivities);
5003
// try{
5004
// DBTransaction dbTrans=null;
5005
// long overallTime=0;
5006
// for(int k=0;k<transactionCount;k++){
5007
// resetCurentTime();
5008
// dbTrans = DODS.getDatabaseManager().createTransaction();
5009
// for (int i=0; i<deleteCount;i++){
5010
// ActivityQuery query = new ActivityQuery(dbTrans);
5011
// query.requireUniqueInstance();
5012
// if (curNoOfActivities<=0) {
5013
// System.out.println("No more Activities to delete");
5014
// break;
5015
// }
5016
// String uniqueFieldValue=String.valueOf(curNoOfActivities-1);
5017
// query.setQueryId(uniqueFieldValue);
5018
// ActivityDO DO=query.getNextDO();
5019
// DO.delete(dbTrans);
5020
// curNoOfActivities--;
5021
// }
5022
// dbTrans.commit();
5023
// overallTime+=writeTimeDiff(testActivityDeletionStream);
5024
// }
5025
// String summary=String.valueOf(curNoOfActivities)+";"+String.valueOf(overallTime/transactionCount);
5026
// writeSummary(testActivityDeletionStream,summary);
5027
// } catch (Exception e){
5028
// e.printStackTrace();
5029
// System.exit(1);
5030
// }
5031
// }
5032
//
5033
// protected void initObjectCount () {
5034
// try {
5035
// DBTransaction dbTrans = DODS.getDatabaseManager().createTransaction();
5036
// ProcessDefinitionQuery queryA = new ProcessDefinitionQuery(dbTrans);
5037
// initNoOfPDefs=queryA.getCount();
5038
// curNoOfPDefs=initNoOfPDefs;
5039
//
5040
// ProcessQuery queryB = new ProcessQuery(dbTrans);
5041
// initNoOfProcesses=queryB.getCount();
5042
// curNoOfProcesses=initNoOfProcesses;
5043
//
5044
// ActivityQuery queryC = new ActivityQuery(dbTrans);
5045
// initNoOfActivities=queryC.getCount();
5046
// curNoOfActivities=initNoOfActivities;
5047
// dbTrans.release();
5048
// } catch (Exception ex) {
5049
// ex.printStackTrace();
5050
// System.exit(1);
5051
// }
5052
// }
5053
//
5054
// protected void resetCurentTime() {
5055
// curentTime=System.currentTimeMillis();
5056
// }
5057
//
5058
// protected long writeTimeDiff (PrintStream ps) {
5059
// long diff=System.currentTimeMillis()-curentTime;
5060
// ps.print(System.currentTimeMillis()-curentTime);
5061
// ps.println();
5062
// return diff;
5063
// }
5064
//
5065
// protected void writeInitMsg (PrintStream ps,String mainMsg,long noOfObjs) {
5066
// ps.println();
5067
// ps.println("-------------------------------------------------------------------------------------");
5068
// ps.print(mainMsg);
5069
// if (noOfObjs>=0) {
5070
// ps.println(" - initial No of objects in DB="+noOfObjs);
5071
// ps.println(" Comment: "+this.commentForLog);
5072
// } else {
5073
// ps.println();
5074
// ps.println(" Comment: "+this.commentForLog);
5075
// }
5076
// ps.println("-------------------------------------------------------------------------------------");
5077
// ps.println();
5078
// }
5079
//
5080
// protected void writeSummary (PrintStream ps,String summary) {
5081
// ps.println();
5082
// ps.println("summary:");
5083
// ps.println(summary);
5084
// }
5085
//
5086
// protected static void printUsage () {
5087
// System.err.println("This application is used to start DB tests.");
5088
// System.err.println();
5089
// System.err.println("usage: java DODSPersistentManager confFilePath logFilePrefix testType noOfTransactions noOfOpPerTransaction comment");
5090
// System.err.println();
5091
// System.err.println("arguments:");
5092
// System.err.println(" confFilePath -----------> the path to configuration file.");
5093
// System.err.println(" logFilePrefix-----------> the prefix for log file name.");
5094
// System.err.println(" testType ---------------> the type of test:");
5095
// System.err.println(" - all = test all");
5096
// System.err.println(" - allnodel = test all");
5097
// System.err.println(" - ocre = test overall creation");
5098
// System.err.println(" - pdcre = test process definition creation");
5099
// System.err.println(" - pcre = test process creation");
5100
// System.err.println(" - acre = test activity creation");
5101
// System.err.println(" - ipdq = test indexed process definition queries");
5102
// System.err.println(" - ipq = test indexed process queries");
5103
// System.err.println(" - iaq = test indexed activity queries");
5104
// System.err.println(" - nipdq = test non indexed process definition queries");
5105
// System.err.println(" - nipq = test non indexed process queries");
5106
// System.err.println(" - niaq = test non indexed activity queries");
5107
// System.err.println(" - pddel = test process definition deletion");
5108
// System.err.println(" - pdel = test process deletion");
5109
// System.err.println(" - adel = test activity deletion");
5110
// System.err.println(" noOfTransaction --------> the number of transactions for test operations (the time is measured per transaction).");
5111
// System.err.println(" noOfOpPerTransaction ---> the number of operations that will be performed within one transaction.");
5112
// System.err.println(" comment ----------------> comment that will be written into log file.");
5113
// }
5114

5115}
5116
Popular Tags