KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > eventaudit > DODSEventAuditManager


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

24 public class DODSEventAuditManager implements EventAuditManagerInterface {
25
26    protected static final String JavaDoc LOG_CHANNEL="Persistence";
27    protected static final String JavaDoc PACKAGE_LOADED="packageLoaded";
28    protected static final String JavaDoc PACKAGE_UNLOADED="packageUnloaded";
29    protected static final String JavaDoc PACKAGE_UPDATED="packageUpdated";
30    protected static final String JavaDoc PROCESS_CREATED="processCreated";
31    protected static final String JavaDoc PROCESS_STATE_CHANGED="processStateChanged";
32    protected static final String JavaDoc PROCESS_CONTEXT_CHANGED="processContextChanged";
33    protected static final String JavaDoc ACTIVITY_STATE_CHANGED="activityStateChanged";
34    protected static final String JavaDoc ACTIVITY_CONTEXT_CHANGED="activityContextChanged";
35    protected static final String JavaDoc ACTIVITY_RESULT_CHANGED="activityResultChanged";
36    protected static final String JavaDoc ACTIVITY_ASSIGNMENT_CHANGED="activityAssignmentChanged";
37    protected static final int RESOURCE_TYPE_OBJECT=0;
38    protected static final int PROCESS_DEFINITION_TYPE_OBJECT=1;
39    protected static final int PROCESS_TYPE_OBJECT=2;
40    protected static final int ACTIVITY_TYPE_OBJECT=3;
41    protected static final int ASSIGNMENT_TYPE_OBJECT=4;
42    protected static final int EVENT_AUDIT_ASSIGNMENT_TYPE_OBJECT=5;
43    protected static final int EVENT_AUDIT_DATA_TYPE_OBJECT=6;
44    protected static final int EVENT_AUDIT_STATE_TYPE_OBJECT=7;
45    protected static final int EVENT_AUDIT_CREATE_PROCESS_TYPE_OBJECT=8;
46    protected static final int EVENT_AUDIT_PACKAGE_TYPE_OBJECT=9;
47
48    protected static final String JavaDoc[] activityAndProcessStates={"open.running",
49          "open.not_running.not_started","open.not_running.suspended",
50          "closed.completed", "closed.terminated", "closed.aborted"};
51
52    protected static final String JavaDoc[] eventTypes={PACKAGE_LOADED,PACKAGE_UNLOADED,
53          PACKAGE_UPDATED,PROCESS_CREATED,PROCESS_STATE_CHANGED,
54          PROCESS_CONTEXT_CHANGED,ACTIVITY_STATE_CHANGED,ACTIVITY_CONTEXT_CHANGED,
55          ACTIVITY_RESULT_CHANGED,ACTIVITY_ASSIGNMENT_CHANGED};
56
57    protected static final short DB_TYPE_BOOLEAN=0;
58    protected static final short DB_TYPE_LONG=1;
59    protected static final short DB_TYPE_DOUBLE=2;
60    protected static final short DB_TYPE_VCHAR=3;
61    protected static final short DB_TYPE_DATE=4;
62    protected static final short DB_TYPE_BLOB=5;
63    
64    protected static final int MAX_VCHAR_SIZE_LIMIT=4000;
65
66    protected static int max_vchar_size=4000;
67
68    protected CallbackUtilities cus;
69    protected Map _prStates;
70    protected Map _acStates;
71    protected Map _evTypes;
72
73    protected boolean usingStandardVariableDataModel=true;
74    protected boolean persistOldEventAuditData=true;
75    
76    public void configure (CallbackUtilities cus) throws RootException {
77       this.cus=cus;
78       String JavaDoc mvc=cus.getProperty("DODSEventAuditManager.maxVARCHARSize","4000");
79       try {
80          max_vchar_size=Integer.parseInt(mvc);
81          if (max_vchar_size>MAX_VCHAR_SIZE_LIMIT || max_vchar_size<1) {
82             max_vchar_size=MAX_VCHAR_SIZE_LIMIT;
83             cus.warn("Invalid value "+mvc+" for property DODSEventAuditManager.maxVARCHARSize. Using default value "+max_vchar_size);
84          }
85       } catch (Exception JavaDoc e) {
86          cus.warn("Invalid value "+mvc+" for property DODSEventAuditManager.maxVARCHARSize. Using default value "+max_vchar_size);
87       }
88
89       usingStandardVariableDataModel=new Boolean JavaDoc(cus.getProperty("DODSEventAuditManager.useStandardVariableDataModel","true")).booleanValue();
90       persistOldEventAuditData=new Boolean JavaDoc(cus.getProperty("PERSIST_OLD_EVENT_AUDIT_DATA","true")).booleanValue();
91       
92       _prStates = new HashMap();
93       _acStates = new HashMap();
94       _evTypes = new HashMap();
95       try {
96          try {
97             DODSUtilities.init(cus.getProperties());
98          }
99          catch (Throwable JavaDoc ex) {
100             ex.printStackTrace();
101          }
102          initActivityAndProcessStatesTable();
103          initEventTypesTable();
104       }
105       catch (Throwable JavaDoc tr) {
106          cus.error(LOG_CHANNEL,"Problem with registering database manager with DODS !", new RootException(tr));
107          throw new RootException("Problem with registering database manager with DODS !",tr);
108       }
109    }
110
111    /**
112     * Fills the state table with possible activity and process states. For now,
113     * the 'keyValue' and the 'name' attribute of state record has the same value,
114     * but in the future, if the names of states changes, it will be very easy
115     * to change this table entries without affecting other tables.
116     * NOTE: When new names are introduced, the getPersistentXXX that use it
117     * also has to be changed
118     */

119    protected void initActivityAndProcessStatesTable () throws EventAuditException {
120       DBTransaction t=null;
121       try {
122          t = DODS.getDatabaseManager().createTransaction();
123          for (int i=0; i<activityAndProcessStates.length; i++) {
124             String JavaDoc state=activityAndProcessStates[i];
125             ProcessStateEventAuditDO psDO=getPersistedProcessStateObject(state,true,t);
126             if (!psDO.isPersistent()) {
127                psDO.setKeyValue(state);
128             }
129             psDO.setName(state);
130             psDO.save(t);
131             _prStates.put(state, psDO.get_OId().toBigDecimal());
132             ActivityStateEventAuditDO asDO=getPersistedActivityStateObject(state,true,t);
133             if (!asDO.isPersistent()) {
134                asDO.setKeyValue(state);
135             }
136             asDO.setName(state);
137             asDO.save(t);
138             _acStates.put(state, asDO.get_OId().toBigDecimal());
139          }
140          t.commit();
141       }
142       catch (Throwable JavaDoc thr) {
143          throw new EventAuditException(thr);
144       }
145       finally {
146          try {
147             t.release();
148          } catch (Exception JavaDoc ex) {}
149       }
150    }
151
152    /**
153     * Fills the event type table with possible event types. For now,
154     * the 'keyValue' and the 'name' attribute of event type record has
155     * the same value, but in the future, if the names of event types changes,
156     * it will be very easy to change this table entries without affecting
157     * other tables.
158     * NOTE: When new names are introduced, the getPersistentXXX that use it
159     * also has to be changed
160     */

161    protected void initEventTypesTable () throws EventAuditException {
162       DBTransaction t=null;
163       try {
164          t = DODS.getDatabaseManager().createTransaction();
165          for (int i=0; i<eventTypes.length; i++) {
166             String JavaDoc eventType=eventTypes[i];
167             EventTypeDO etDO=getPersistedEventTypeObject(eventType,true,t);
168             if (!etDO.isPersistent()) {
169                etDO.setKeyValue(eventType);
170             }
171             etDO.setName(eventType);
172             etDO.save(t);
173             _evTypes.put(eventType, etDO.get_OId().toBigDecimal());
174          }
175          t.commit();
176       }
177       catch (Throwable JavaDoc thr) {
178          throw new EventAuditException(thr);
179       }
180       finally {
181          try {
182             t.release();
183          } catch (Exception JavaDoc ex) {}
184       }
185    }
186
187    public void persist(AssignmentEventAuditPersistenceInterface aea,SharkTransaction ti) throws EventAuditException {
188       try {
189          AssignmentEventAuditDO DO=AssignmentEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
190          // when these attributes are persisted - they never change
191
if (!DO.isPersistent()) {
192             DO.setUTCTime(aea.getUTCTime());
193             DO.oid_setTheType((BigDecimal JavaDoc)_evTypes.get(aea.getType()));
194             DO.setProcessId(aea.getProcessId());
195             DO.setActivityId(aea.getActivityId());
196             if (aea.getActivityName()!=null) {
197                DO.setActivityName(aea.getActivityName());
198             }
199             DO.setProcessName(aea.getProcessName());
200             DO.setProcessDefinitionName(aea.getProcessDefinitionName());
201             DO.setProcessDefinitionVersion(aea.getProcessDefinitionVersion());
202             if (aea.getActivityDefinitionId()!=null) {
203                DO.setActivityDefinitionId(aea.getActivityDefinitionId());
204                DO.setActivitySetDefinitionId(aea.getActivitySetDefinitionId());
205             }
206             DO.setProcessDefinitionId(aea.getProcessDefinitionId());
207             DO.setPackageId(aea.getPackageId());
208             DO.setNewResourceUsername(aea.getNewResourceUsername());
209             if (aea.getNewResourceName()!=null) {
210                DO.setNewResourceName(aea.getNewResourceName());
211             }
212             if (aea.getOldResourceUsername()!=null) {
213                DO.setOldResourceUsername(aea.getOldResourceUsername());
214             }
215             if (aea.getOldResourceName()!=null) {
216                DO.setOldResourceName(aea.getOldResourceName());
217             }
218             DO.setIsAccepted(aea.getIsAccepted());
219             DO.setCNT(getNextDecId("assignmenteventaudit"));
220             ((SharkDODSTransaction)ti).store(DO);
221          }
222          cus.info(LOG_CHANNEL,"AssignmentEventAudit[processId="+aea.getProcessId()+",activityId="+aea.getActivityId()+"] persisted");
223       }
224       catch (Throwable JavaDoc tr) {
225          cus.error(LOG_CHANNEL,"Persisting of AssignmentEventAudit failed");
226          //tr.printStackTrace();
227
throw new EventAuditException
228             ("Persisting of AssignmentEventAudit failed", tr);
229       }
230    }
231
232    public void persist(DataEventAuditPersistenceInterface dea,SharkTransaction ti) throws EventAuditException {
233       try {
234          DataEventAuditDO DO=DataEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
235          // when these attributes are persisted - they never change
236
if (!DO.isPersistent()) {
237             DO.setUTCTime(dea.getUTCTime());
238             DO.oid_setTheType((BigDecimal JavaDoc)_evTypes.get(dea.getType()));
239             DO.setProcessId(dea.getProcessId());
240             if (dea.getActivityId()!=null) {
241                DO.setActivityId(dea.getActivityId());
242             }
243             if (dea.getActivityName()!=null) {
244                DO.setActivityName(dea.getActivityName());
245             }
246             DO.setProcessName(dea.getProcessName());
247             DO.setProcessDefinitionName(dea.getProcessDefinitionName());
248             DO.setProcessDefinitionVersion(dea.getProcessDefinitionVersion());
249             if (dea.getActivityDefinitionId()!=null) {
250                DO.setActivityDefinitionId(dea.getActivityDefinitionId());
251                DO.setActivitySetDefinitionId(dea.getActivitySetDefinitionId());
252             }
253             DO.setProcessDefinitionId(dea.getProcessDefinitionId());
254             DO.setPackageId(dea.getPackageId());
255             DO.setCNT(getNextDecId("dataeventaudit"));
256             ((SharkDODSTransaction)ti).store(DO);
257             if (usingStandardVariableDataModel) {
258                if (persistOldEventAuditData) {
259                   persistOldEventAuditDataBLOB(dea,DO,ti);
260                }
261                persistNewEventAuditDataBLOB(dea,DO,ti);
262             } else {
263                if (persistOldEventAuditData) {
264                   persistOldEventAuditDataWOB(dea,DO,ti);
265                }
266                persistNewEventAuditDataWOB(dea,DO,ti);
267             }
268          }
269          if(dea.getActivityId()!=null) {
270             cus.info(LOG_CHANNEL,"DataEventAudit[processId="+dea.getProcessId()+",activityId="+dea.getActivityId()+"] persisted");
271          }
272          else {
273             cus.info(LOG_CHANNEL,"DataEventAudit[processId="+dea.getProcessId()+"] persisted");
274          }
275       }
276       catch (Throwable JavaDoc tr) {
277          cus.error(LOG_CHANNEL,"Persisting of DataEventAudit failed");
278          throw new EventAuditException
279             ("Persisting of DataEventAudit failed", tr);
280       }
281    }
282
283    public void persist(StateEventAuditPersistenceInterface sea,SharkTransaction ti) throws EventAuditException {
284       try {
285          StateEventAuditDO DO=StateEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
286          // when these attributes are persisted - they never change
287

288          if (!DO.isPersistent()) {
289             DO.setUTCTime(sea.getUTCTime());
290             DO.oid_setTheType((BigDecimal JavaDoc)_evTypes.get(sea.getType()));
291             DO.setProcessId(sea.getProcessId());
292             if (sea.getActivityId()!=null) {
293                DO.setActivityId(sea.getActivityId());
294                DO.oid_setNewActivityState((BigDecimal JavaDoc)_acStates.get(sea.getNewState()));
295                if (sea.getOldState()!=null) {
296                   DO.oid_setOldActivityState((BigDecimal JavaDoc)_acStates.get(sea.getOldState()));
297                }
298             }
299             else {
300                DO.oid_setNewProcessState((BigDecimal JavaDoc)_prStates.get(sea.getNewState()));
301                if (sea.getOldState()!=null) {
302                   DO.oid_setOldProcessState((BigDecimal JavaDoc)_prStates.get(sea.getOldState()));
303                }
304             }
305
306             if (sea.getActivityName()!=null) {
307                DO.setActivityName(sea.getActivityName());
308             }
309             DO.setProcessName(sea.getProcessName());
310             DO.setProcessDefinitionName(sea.getProcessDefinitionName());
311             DO.setProcessDefinitionVersion(sea.getProcessDefinitionVersion());
312             if (sea.getActivityDefinitionId()!=null) {
313                DO.setActivityDefinitionId(sea.getActivityDefinitionId());
314                DO.setActivitySetDefinitionId(sea.getActivitySetDefinitionId());
315             }
316             DO.setProcessDefinitionId(sea.getProcessDefinitionId());
317             DO.setPackageId(sea.getPackageId());
318             DO.setCNT(getNextDecId("stateeventaudit"));
319             ((SharkDODSTransaction)ti).store(DO);
320          }
321          if(sea.getActivityId()!=null) {
322             cus.info(LOG_CHANNEL,"StateEventAudit[processId="+sea.getProcessId()+",activityId="+sea.getActivityId()+"] persisted");
323          }
324          else {
325             cus.info(LOG_CHANNEL,"StateEventAudit[processId="+sea.getProcessId()+"] persisted");
326          }
327       }
328       catch (Throwable JavaDoc tr) {
329          cus.error(LOG_CHANNEL,"Persisting of StateEventAudit failed");
330          //tr.printStackTrace();
331
throw new EventAuditException
332             ("Persisting of StateEventAudit failed", tr);
333       }
334    }
335
336    public void persist(CreateProcessEventAuditPersistenceInterface cpea,SharkTransaction ti) throws EventAuditException {
337       try {
338          CreateProcessEventAuditDO DO=CreateProcessEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
339          // when these attributes are persisted - they never change
340
if (!DO.isPersistent()) {
341             DO.setUTCTime(cpea.getUTCTime());
342             DO.oid_setTheType((BigDecimal JavaDoc)_evTypes.get(cpea.getType()));
343             DO.setProcessId(cpea.getProcessId());
344             DO.setProcessName(cpea.getProcessName());
345             DO.setProcessDefinitionId(cpea.getProcessDefinitionId());
346             DO.setProcessDefinitionName(cpea.getProcessDefinitionName());
347             DO.setProcessDefinitionVersion(cpea.getProcessDefinitionVersion());
348             DO.setPackageId(cpea.getPackageId());
349             if (cpea.getPProcessId()!=null) {
350                DO.setPProcessId(cpea.getPProcessId());
351             }
352             if (cpea.getPProcessName()!=null) {
353                DO.setPProcessName(cpea.getPProcessName());
354             }
355             if (cpea.getPActivityId()!=null) {
356                DO.setPActivityId(cpea.getPActivityId());
357             }
358             if (cpea.getPPackageId()!=null) {
359                DO.setPPackageId(cpea.getPPackageId());
360             }
361             if (cpea.getPProcessDefinitionId()!=null) {
362                DO.setPProcessDefinitionId(cpea.getPProcessDefinitionId());
363             }
364             if (cpea.getPActivityDefinitionId()!=null) {
365                DO.setPActivityDefinitionId(cpea.getPActivityDefinitionId());
366                DO.setPActivitySetDefinitionId(cpea.getPActivitySetDefinitionId());
367             }
368             if (cpea.getPProcessDefinitionName()!=null) {
369                DO.setPProcessDefinitionName(cpea.getPProcessDefinitionName());
370             }
371             if (cpea.getPProcessDefinitionVersion()!=null) {
372                DO.setPProcessDefinitionVersion(cpea.getPProcessDefinitionVersion());
373             }
374             DO.setCNT(getNextDecId("createprocesseventaudit"));
375             ((SharkDODSTransaction)ti).store(DO);
376          }
377          cus.info(LOG_CHANNEL,"CreateProcessEventAudit[processId="+cpea.getProcessId()+"] persisted");
378       }
379       catch (Throwable JavaDoc tr) {
380          cus.error(LOG_CHANNEL,"Persisting of CreateProcessEventAudit failed");
381          throw new EventAuditException
382             ("Persisting of CreateProcessEventAudit failed", tr);
383       }
384    }
385
386    protected void persistOldEventAuditDataBLOB (DataEventAuditPersistenceInterface dea,
387                                           DataEventAuditDO deaDO,SharkTransaction ti) throws EventAuditException {
388       try {
389          Map od=dea.getOldData();
390          if (null != od) {
391             Iterator it=od.entrySet().iterator();
392             while (it.hasNext()) {
393                Map.Entry me=(Map.Entry)it.next();
394                String JavaDoc vdId=(String JavaDoc)me.getKey();
395                Object JavaDoc val=me.getValue();
396                OldEventAuditDataDO oedDO=OldEventAuditDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
397                oedDO.setDataEventAudit(deaDO);
398                oedDO.setVariableDefinitionId(vdId);
399
400                boolean isBLOB=false;
401                if (val instanceof Boolean JavaDoc) {
402                   oedDO.setVariableValueBOOL(((Boolean JavaDoc)val).booleanValue());
403                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BOOLEAN);
404                } else if (val instanceof Long JavaDoc) {
405                   oedDO.setVariableValueLONG(((Long JavaDoc)val).longValue());
406                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_LONG);
407                } else if (val instanceof String JavaDoc) {
408                   String JavaDoc sv=(String JavaDoc)val;
409                   if (sv.length()<=max_vchar_size) {
410                      oedDO.setVariableValueVCHAR(sv);
411                      oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_VCHAR);
412                   } else {
413                      isBLOB=true;
414                   }
415                } else if (val instanceof Double JavaDoc) {
416                   oedDO.setVariableValueDBL(((Double JavaDoc)val).doubleValue());
417                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DOUBLE);
418                } else if (val instanceof java.util.Date JavaDoc) {
419                   oedDO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)val).getTime()));
420                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DATE);
421                } else if (val==null) {
422                   short vt=oedDO.getVariableType();
423                   if (vt==DODSEventAuditManager.DB_TYPE_DATE) {
424                      oedDO.setVariableValueDATE(null);
425                   } else if (vt==DODSEventAuditManager.DB_TYPE_VCHAR) {
426                      oedDO.setVariableValueVCHAR(null);
427                   } else {
428                      oedDO.setVariableValue(null);
429                      oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
430                   }
431                } else {
432                   isBLOB=true;
433                }
434
435                if (isBLOB) {
436                   oedDO.setVariableValue(MiscUtilities.serialize(val));
437                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
438                }
439
440                ((SharkDODSTransaction)ti).store(oedDO);
441             }
442          }
443       }
444       catch (Throwable JavaDoc tr) {
445          cus.error(LOG_CHANNEL,"Persisting of OldEventAuditData failed");
446          throw new EventAuditException
447             ("Persisting of OldEventAuditData failed", tr);
448       }
449    }
450
451    protected void persistOldEventAuditDataWOB (DataEventAuditPersistenceInterface dea,
452          DataEventAuditDO deaDO,SharkTransaction ti) throws EventAuditException {
453    
454       try {
455          Map od=dea.getOldData();
456          if (null != od) {
457             Iterator it=od.entrySet().iterator();
458             while (it.hasNext()) {
459                Map.Entry me=(Map.Entry)it.next();
460                String JavaDoc vdId=(String JavaDoc)me.getKey();
461                Object JavaDoc val=me.getValue();
462                OldEventAuditDataWOBDO oedDO=OldEventAuditDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
463                oedDO.setDataEventAudit(deaDO);
464                oedDO.setVariableDefinitionId(vdId);
465
466                boolean isBLOB=false;
467                if (val instanceof Boolean JavaDoc) {
468                   oedDO.setVariableValueBOOL(((Boolean JavaDoc)val).booleanValue());
469                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BOOLEAN);
470                } else if (val instanceof Long JavaDoc) {
471                   oedDO.setVariableValueLONG(((Long JavaDoc)val).longValue());
472                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_LONG);
473                } else if (val instanceof String JavaDoc) {
474                   String JavaDoc sv=(String JavaDoc)val;
475                   if (sv.length()<=max_vchar_size) {
476                      oedDO.setVariableValueVCHAR(sv);
477                      oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_VCHAR);
478                   } else {
479                      isBLOB=true;
480                   }
481                } else if (val instanceof Double JavaDoc) {
482                   oedDO.setVariableValueDBL(((Double JavaDoc)val).doubleValue());
483                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DOUBLE);
484                } else if (val instanceof java.util.Date JavaDoc) {
485                   oedDO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)val).getTime()));
486                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DATE);
487                } else if (val==null) {
488                   short vt=oedDO.getVariableType();
489                   if (vt==DODSEventAuditManager.DB_TYPE_DATE) {
490                      oedDO.setVariableValueDATE(null);
491                   } else if (vt==DODSEventAuditManager.DB_TYPE_VCHAR) {
492                      oedDO.setVariableValueVCHAR(null);
493                   } else {
494                      OldEventAuditDataBLOBDO bDO=OldEventAuditDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
495                      bDO.setOldEventAuditDataWOB(oedDO);
496                      bDO.setVariableValue(null);
497                      oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
498                      ((SharkDODSTransaction)ti).store(bDO);
499                   }
500                } else {
501                   isBLOB=true;
502                }
503
504                if (isBLOB) {
505                   OldEventAuditDataBLOBDO bDO=OldEventAuditDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
506                   bDO.setOldEventAuditDataWOB(oedDO);
507                   bDO.setVariableValue(MiscUtilities.serialize(val));
508                   oedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
509                   ((SharkDODSTransaction)ti).store(bDO);
510                }
511
512                ((SharkDODSTransaction)ti).store(oedDO);
513             }
514          }
515       }
516       catch (Throwable JavaDoc tr) {
517          cus.error(LOG_CHANNEL,"Persisting of OldEventAuditData failed");
518          throw new EventAuditException
519             ("Persisting of OldEventAuditData failed", tr);
520       }
521    }
522    
523    protected void persistNewEventAuditDataBLOB (DataEventAuditPersistenceInterface dea,
524                                           DataEventAuditDO deaDO,SharkTransaction ti) throws EventAuditException {
525       try {
526          Map nd=dea.getNewData();
527          Iterator it=nd.entrySet().iterator();
528          while (it.hasNext()) {
529             Map.Entry me=(Map.Entry)it.next();
530             String JavaDoc vdId=(String JavaDoc)me.getKey();
531             Object JavaDoc val= me.getValue();
532             NewEventAuditDataDO nedDO=NewEventAuditDataDO .createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
533             nedDO.setDataEventAudit(deaDO);
534             nedDO.setVariableDefinitionId(vdId);
535
536             boolean isBLOB=false;
537             if (val instanceof Boolean JavaDoc) {
538                nedDO.setVariableValueBOOL(((Boolean JavaDoc)val).booleanValue());
539                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BOOLEAN);
540             } else if (val instanceof Long JavaDoc) {
541                nedDO.setVariableValueLONG(((Long JavaDoc)val).longValue());
542                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_LONG);
543             } else if (val instanceof String JavaDoc) {
544                String JavaDoc sv=(String JavaDoc)val;
545                if (sv.length()<=max_vchar_size) {
546                   nedDO.setVariableValueVCHAR(sv);
547                   nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_VCHAR);
548                } else {
549                   isBLOB=true;
550                }
551             } else if (val instanceof Double JavaDoc) {
552                nedDO.setVariableValueDBL(((Double JavaDoc)val).doubleValue());
553                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DOUBLE);
554             } else if (val instanceof java.util.Date JavaDoc) {
555                nedDO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)val).getTime()));
556                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DATE);
557             } else if (val==null) {
558                short vt=nedDO.getVariableType();
559                if (vt==DODSEventAuditManager.DB_TYPE_DATE) {
560                   nedDO.setVariableValueDATE(null);
561                } else if (vt==DODSEventAuditManager.DB_TYPE_VCHAR) {
562                   nedDO.setVariableValueVCHAR(null);
563                } else {
564                   nedDO.setVariableValue(null);
565                   nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
566                }
567             } else {
568                isBLOB=true;
569             }
570
571             if (isBLOB) {
572                nedDO.setVariableValue(MiscUtilities.serialize(val));
573                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
574             }
575
576             ((SharkDODSTransaction)ti).store(nedDO);
577          }
578       }
579       catch (Throwable JavaDoc tr) {
580          cus.error(LOG_CHANNEL,"Persisting of NewEventAuditData failed");
581          throw new EventAuditException
582             ("Persisting of NewEventAuditData failed", tr);
583       }
584    }
585
586    protected void persistNewEventAuditDataWOB (DataEventAuditPersistenceInterface dea,
587          DataEventAuditDO deaDO,SharkTransaction ti) throws EventAuditException {
588
589       try {
590          Map nd=dea.getNewData();
591          Iterator it=nd.entrySet().iterator();
592          while (it.hasNext()) {
593             Map.Entry me=(Map.Entry)it.next();
594             String JavaDoc vdId=(String JavaDoc)me.getKey();
595             Object JavaDoc val= me.getValue();
596             NewEventAuditDataWOBDO nedDO=NewEventAuditDataWOBDO .createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
597             nedDO.setDataEventAudit(deaDO);
598             nedDO.setVariableDefinitionId(vdId);
599
600             boolean isBLOB=false;
601             if (val instanceof Boolean JavaDoc) {
602                nedDO.setVariableValueBOOL(((Boolean JavaDoc)val).booleanValue());
603                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BOOLEAN);
604             } else if (val instanceof Long JavaDoc) {
605                nedDO.setVariableValueLONG(((Long JavaDoc)val).longValue());
606                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_LONG);
607             } else if (val instanceof String JavaDoc) {
608                String JavaDoc sv=(String JavaDoc)val;
609                if (sv.length()<=max_vchar_size) {
610                   nedDO.setVariableValueVCHAR(sv);
611                   nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_VCHAR);
612                } else {
613                   isBLOB=true;
614                }
615             } else if (val instanceof Double JavaDoc) {
616                nedDO.setVariableValueDBL(((Double JavaDoc)val).doubleValue());
617                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DOUBLE);
618             } else if (val instanceof java.util.Date JavaDoc) {
619                nedDO.setVariableValueDATE(new java.sql.Timestamp JavaDoc(((java.util.Date JavaDoc)val).getTime()));
620                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_DATE);
621             } else if (val==null) {
622                short vt=nedDO.getVariableType();
623                if (vt==DODSEventAuditManager.DB_TYPE_DATE) {
624                   nedDO.setVariableValueDATE(null);
625                } else if (vt==DODSEventAuditManager.DB_TYPE_VCHAR) {
626                   nedDO.setVariableValueVCHAR(null);
627                } else {
628                   NewEventAuditDataBLOBDO bDO=NewEventAuditDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
629                   bDO.setNewEventAuditDataWOB(nedDO);
630                   bDO.setVariableValue(null);
631
632                   nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
633                   ((SharkDODSTransaction)ti).store(bDO);
634                }
635             } else {
636                isBLOB=true;
637             }
638
639             if (isBLOB) {
640                NewEventAuditDataBLOBDO bDO=NewEventAuditDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
641                bDO.setNewEventAuditDataWOB(nedDO);
642                bDO.setVariableValue(MiscUtilities.serialize(val));
643                nedDO.setVariableType(DODSEventAuditManager.DB_TYPE_BLOB);
644                ((SharkDODSTransaction)ti).store(bDO);
645             }
646
647             ((SharkDODSTransaction)ti).store(nedDO);
648          }
649       }
650       catch (Throwable JavaDoc tr) {
651          cus.error(LOG_CHANNEL,"Persisting of NewEventAuditData failed");
652          throw new EventAuditException
653             ("Persisting of NewEventAuditData failed", tr);
654       }
655    }
656    
657    public boolean restore(AssignmentEventAuditPersistenceInterface aea,SharkTransaction ti) throws EventAuditException {
658       return restore(aea,getPersistedObject(aea,ti),ti);
659    }
660
661    protected boolean restore(
662       AssignmentEventAuditPersistenceInterface engineObj,
663       AssignmentEventAuditDO DO,SharkTransaction ti) throws EventAuditException {
664       if (DO==null) return false;
665
666       try {
667          engineObj.setUTCTime(DO.getUTCTime());
668          engineObj.setType(DO.getTheType().getName());
669          engineObj.setProcessId(DO.getProcessId());
670          engineObj.setActivityId(DO.getActivityId());
671          if (DO.getActivityName()!=null) {
672             engineObj.setActivityName(DO.getActivityName());
673          }
674          engineObj.setProcessName(DO.getProcessName());
675          engineObj.setProcessDefinitionName(DO.getProcessDefinitionName());
676          engineObj.setProcessDefinitionVersion(DO.getProcessDefinitionVersion());
677          engineObj.setActivityDefinitionId(DO.getActivityDefinitionId());
678          engineObj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId());
679          engineObj.setProcessDefinitionId(DO.getProcessDefinitionId());
680          engineObj.setPackageId(DO.getPackageId());
681          engineObj.setNewResourceUsername(DO.getNewResourceUsername());
682          if (DO.getNewResourceName()!=null) {
683             engineObj.setNewResourceName(DO.getNewResourceName());
684          }
685          if (DO.getOldResourceUsername()!=null) {
686             engineObj.setOldResourceUsername(DO.getOldResourceUsername());
687          }
688          if (DO.getOldResourceName()!=null) {
689             engineObj.setOldResourceName(DO.getOldResourceName());
690          }
691          engineObj.setIsAccepted(DO.getIsAccepted());
692          cus.info(LOG_CHANNEL,"AssignmentEventAudit[processId="+DO.getProcessId()+",activityId="+DO.getActivityId()+"] restored");
693       }
694       catch (Throwable JavaDoc tr) {
695          cus.error(LOG_CHANNEL,"Restoring of AssignmentEventAudit failed");
696          throw new EventAuditException
697             ("Restoring of AssignmentEventAudit failed", tr);
698       }
699       return true;
700    }
701
702    public boolean restore(DataEventAuditPersistenceInterface dea,SharkTransaction ti) throws EventAuditException {
703       return restore(dea,getPersistedObject(dea,ti),ti);
704    }
705
706    protected boolean restore(
707       DataEventAuditPersistenceInterface engineObj,DataEventAuditDO DO,SharkTransaction ti) throws EventAuditException {
708       if (DO==null) return false;
709
710       try {
711          engineObj.setUTCTime(DO.getUTCTime());
712          engineObj.setType(DO.getTheType().getName());
713          engineObj.setProcessId(DO.getProcessId());
714          if (DO.getActivityId()!=null) {
715             engineObj.setActivityId(DO.getActivityId());
716          }
717          if (DO.getActivityName()!=null) {
718             engineObj.setActivityName(DO.getActivityName());
719          }
720          engineObj.setProcessName(DO.getProcessName());
721          engineObj.setProcessDefinitionName(DO.getProcessDefinitionName());
722          engineObj.setProcessDefinitionVersion(DO.getProcessDefinitionVersion());
723          if (DO.getActivityDefinitionId()!=null) {
724             engineObj.setActivityDefinitionId(DO.getActivityDefinitionId());
725             engineObj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId());
726          }
727          engineObj.setProcessDefinitionId(DO.getProcessDefinitionId());
728          engineObj.setPackageId(DO.getPackageId());
729          // First, the package and process definition ids must be set, and
730
// then perform following operations
731
if (usingStandardVariableDataModel) {
732             if (persistOldEventAuditData) {
733                restoreOldEventAuditDataBLOB(engineObj,DO,ti);
734             }
735             restoreNewEventAuditDataBLOB(engineObj,DO,ti);
736          } else {
737             if (persistOldEventAuditData) {
738                restoreOldEventAuditDataWOB(engineObj,DO,ti);
739             }
740             restoreNewEventAuditDataWOB(engineObj,DO,ti);
741          }
742          if(DO.getActivityId()!=null) {
743             cus.info(LOG_CHANNEL,"DataEventAudit[processId="+DO.getProcessId()+",activityId="+DO.getActivityId()+"] restored");
744          }
745          else {
746             cus.info(LOG_CHANNEL,"DataEventAudit[processId="+DO.getProcessId()+"] restored");
747          }
748       }
749       catch (Throwable JavaDoc tr) {
750          cus.error(LOG_CHANNEL,"Restoring of DataEventAudit failed");
751          throw new EventAuditException
752             ("Restoring of DataEventAudit failed", tr);
753       }
754       return true;
755    }
756
757    public boolean restore(StateEventAuditPersistenceInterface sea,SharkTransaction ti) throws EventAuditException {
758       return restore(sea,getPersistedObject(sea,ti),ti);
759    }
760
761    protected boolean restore(
762       StateEventAuditPersistenceInterface engineObj,StateEventAuditDO DO,SharkTransaction ti) throws EventAuditException {
763       if (DO==null) return false;
764
765       try {
766          engineObj.setUTCTime(DO.getUTCTime());
767          engineObj.setType(DO.getTheType().getName());
768          engineObj.setProcessId(DO.getProcessId());
769          if (DO.getActivityId()!=null) {
770             engineObj.setActivityId(DO.getActivityId());
771             engineObj.setNewState(DO.getNewActivityState().getName());
772             if (DO.getOldActivityState()!=null) {
773                engineObj.setOldState(DO.getOldActivityState().getName());
774             }
775          }
776          else {
777             engineObj.setNewState(DO.getNewProcessState().getName());
778             if (DO.getOldProcessState()!=null) {
779                engineObj.setOldState(DO.getOldProcessState().getName());
780             }
781          }
782          if (DO.getActivityName()!=null) {
783             engineObj.setActivityName(DO.getActivityName());
784          }
785          engineObj.setProcessName(DO.getProcessName());
786          engineObj.setProcessDefinitionName(DO.getProcessDefinitionName());
787          engineObj.setProcessDefinitionVersion(DO.getProcessDefinitionVersion());
788          if (DO.getActivityDefinitionId()!=null) {
789             engineObj.setActivityDefinitionId(DO.getActivityDefinitionId());
790             engineObj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId());
791          }
792          engineObj.setProcessDefinitionId(DO.getProcessDefinitionId());
793          engineObj.setPackageId(DO.getPackageId());
794          if(DO.getActivityId()!=null) {
795             cus.info(LOG_CHANNEL,"StateEventAudit[processId="+DO.getProcessId()+",activityId="+DO.getActivityId()+"] restored");
796          }
797          else {
798             cus.info(LOG_CHANNEL,"StateEventAudit[processId="+DO.getProcessId()+"] restored");
799          }
800       }
801       catch (Throwable JavaDoc tr) {
802          cus.error(LOG_CHANNEL,"Restoring of StateEventAudit failed");
803          throw new EventAuditException
804             ("Restoring of StateEventAudit failed", tr);
805       }
806       return true;
807    }
808
809    public boolean restore(CreateProcessEventAuditPersistenceInterface cpea,
810                           SharkTransaction ti) throws EventAuditException {
811       return restore(cpea,getPersistedObject(cpea,ti),ti);
812    }
813
814    protected boolean restore(
815       CreateProcessEventAuditPersistenceInterface engineObj,
816       CreateProcessEventAuditDO DO,SharkTransaction ti) throws EventAuditException {
817       if (DO==null) return false;
818
819       try {
820          engineObj.setUTCTime(DO.getUTCTime());
821          engineObj.setType(DO.getTheType().getName());
822          engineObj.setProcessId(DO.getProcessId());
823          engineObj.setProcessName(DO.getProcessName());
824          engineObj.setProcessDefinitionId(DO.getProcessDefinitionId());
825          engineObj.setProcessDefinitionName(DO.getProcessDefinitionName());
826          engineObj.setProcessDefinitionVersion(DO.getProcessDefinitionVersion());
827          engineObj.setPackageId(DO.getPackageId());
828          if (DO.getPProcessId()!=null) {
829             engineObj.setPProcessId(DO.getPProcessId());
830          }
831          if (DO.getPProcessName()!=null) {
832             engineObj.setPProcessName(DO.getPProcessName());
833          }
834          if (DO.getPActivityId()!=null) {
835             engineObj.setPActivityId(DO.getPActivityId());
836          }
837          if (DO.getPPackageId()!=null) {
838             engineObj.setPPackageId(DO.getPPackageId());
839          }
840          if (DO.getPProcessDefinitionId()!=null) {
841             engineObj.setPProcessDefinitionId(DO.getPProcessDefinitionId());
842          }
843          if (DO.getPActivityDefinitionId()!=null) {
844             engineObj.setPActivityDefinitionId(DO.getPActivityDefinitionId());
845             engineObj.setPActivitySetDefinitionId(DO.getPActivitySetDefinitionId());
846          }
847          if (DO.getPProcessDefinitionName()!=null) {
848             engineObj.setPProcessDefinitionName(DO.getPProcessDefinitionName());
849          }
850          if (DO.getPProcessDefinitionVersion()!=null) {
851             engineObj.setPProcessDefinitionVersion(DO.getPProcessDefinitionVersion());
852          }
853          cus.info(LOG_CHANNEL,"CreateProcessEventAudit[processId="+DO.getProcessId()+"] restored");
854       }
855       catch (Throwable JavaDoc tr) {
856          cus.error(LOG_CHANNEL,"Restoring of CreateProcessEventAudit failed");
857          throw new EventAuditException
858             ("Restoring of CreateProcessEventAudit failed", tr);
859       }
860       return true;
861    }
862
863    protected void restoreOldEventAuditDataBLOB (DataEventAuditPersistenceInterface dea,
864                                           DataEventAuditDO deaDO, SharkTransaction ti) throws EventAuditException {
865       if (deaDO==null) return;
866
867       try {
868          Map od=new HashMap();
869          OldEventAuditDataDO[] DOs=deaDO.getOldEventAuditDataDOArray();
870          if (DOs!=null) {
871             BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
872             List list = new ArrayList(Arrays.asList(DOs));
873             for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.OldEventAuditDataDO");
874                  it.hasNext();) {
875                OldEventAuditDataDO o = (OldEventAuditDataDO)it.next();
876                if (dOId.equals(o.oid_getDataEventAudit())) {
877                   int index = list.indexOf(o);
878                   if (-1 == index)
879                      list.add(o);
880                   else {
881                      list.set(index, o);
882                   }
883                }
884             }
885             DOs = new OldEventAuditDataDO[list.size()];
886             DOs = (OldEventAuditDataDO[])list.toArray(DOs);
887             if (DOs!=null) {
888                for (int j=0; j<DOs.length; j++) {
889                   String JavaDoc vdId=DOs[j].getVariableDefinitionId();
890
891
892                   short vtype=DOs[j].getVariableType();
893                   Object JavaDoc val;
894                   switch (vtype) {
895                      case DODSEventAuditManager.DB_TYPE_BOOLEAN :
896                         val=new Boolean JavaDoc(DOs[j].getVariableValueBOOL());
897                         break;
898                      case DODSEventAuditManager.DB_TYPE_LONG:
899                         val=new Long JavaDoc(DOs[j].getVariableValueLONG());
900                         break;
901                      case DODSEventAuditManager.DB_TYPE_DOUBLE:
902                         val=new Double JavaDoc(DOs[j].getVariableValueDBL());
903                         break;
904                      case DODSEventAuditManager.DB_TYPE_VCHAR:
905                         val=DOs[j].getVariableValueVCHAR();
906                         break;
907                      case DODSEventAuditManager.DB_TYPE_DATE:
908                         java.sql.Timestamp JavaDoc d=DOs[j].getVariableValueDATE();
909                         if (d!=null) {
910                            val=new java.util.Date JavaDoc(d.getTime());
911                         } else {
912                            val=null;
913                         }
914                         break;
915                      default:
916                         byte[] v=DOs[j].getVariableValue();
917                         if (v!=null && v.length>0) {
918                            val=MiscUtilities.deserialize(v);
919                         } else {
920                            val=null;
921                         }
922                   }
923
924                   od.put(vdId,val);
925                }
926             }
927          }
928          dea.setOldData(od);
929       }
930       catch (Throwable JavaDoc t) {
931          throw new EventAuditException(t);
932       }
933    }
934
935    protected void restoreOldEventAuditDataWOB (DataEventAuditPersistenceInterface dea,
936          DataEventAuditDO deaDO, SharkTransaction ti) throws EventAuditException {
937       if (deaDO==null) return;
938
939       try {
940          Map od=new HashMap();
941          OldEventAuditDataWOBDO[] DOs=deaDO.getOldEventAuditDataWOBDOArray();
942          if (DOs!=null) {
943             BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
944             List list = new ArrayList(Arrays.asList(DOs));
945             for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.OldEventAuditDataWOBDO");
946                  it.hasNext();) {
947                OldEventAuditDataWOBDO o = (OldEventAuditDataWOBDO)it.next();
948                if (dOId.equals(o.oid_getDataEventAudit())) {
949                   int index = list.indexOf(o);
950                   if (-1 == index)
951                      list.add(o);
952                   else {
953                      list.set(index, o);
954                   }
955                }
956             }
957             DOs = new OldEventAuditDataWOBDO[list.size()];
958             DOs = (OldEventAuditDataWOBDO[])list.toArray(DOs);
959             if (DOs!=null) {
960                for (int j=0; j<DOs.length; j++) {
961                   String JavaDoc vdId=DOs[j].getVariableDefinitionId();
962
963
964                   short vtype=DOs[j].getVariableType();
965                   Object JavaDoc val;
966                   switch (vtype) {
967                      case DODSEventAuditManager.DB_TYPE_BOOLEAN :
968                         val=new Boolean JavaDoc(DOs[j].getVariableValueBOOL());
969                         break;
970                      case DODSEventAuditManager.DB_TYPE_LONG:
971                         val=new Long JavaDoc(DOs[j].getVariableValueLONG());
972                         break;
973                      case DODSEventAuditManager.DB_TYPE_DOUBLE:
974                         val=new Double JavaDoc(DOs[j].getVariableValueDBL());
975                         break;
976                      case DODSEventAuditManager.DB_TYPE_VCHAR:
977                         val=DOs[j].getVariableValueVCHAR();
978                         break;
979                      case DODSEventAuditManager.DB_TYPE_DATE:
980                         java.sql.Timestamp JavaDoc d=DOs[j].getVariableValueDATE();
981                         if (d!=null) {
982                            val=new java.util.Date JavaDoc(d.getTime());
983                         } else {
984                            val=null;
985                         }
986                         break;
987                      default:
988                         byte[] v=DOs[j].getOldEventAuditDataBLOBDO().getVariableValue();
989                         if (v!=null && v.length>0) {
990                            val=MiscUtilities.deserialize(v);
991                         } else {
992                            val=null;
993                         }
994                   }
995
996                   od.put(vdId,val);
997                }
998             }
999          }
1000         dea.setOldData(od);
1001      }
1002      catch (Throwable JavaDoc t) {
1003         throw new EventAuditException(t);
1004      }
1005   }
1006   
1007   protected void restoreNewEventAuditDataBLOB (DataEventAuditPersistenceInterface dea,
1008                                          DataEventAuditDO deaDO, SharkTransaction ti) throws EventAuditException {
1009      if (deaDO==null) return;
1010
1011      try {
1012         Map nd=new HashMap();
1013         NewEventAuditDataDO[] DOs=deaDO.getNewEventAuditDataDOArray();
1014         if (DOs!=null) {
1015            BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
1016            List list = new ArrayList(Arrays.asList(DOs));
1017            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.NewEventAuditDataDO");
1018                 it.hasNext();) {
1019               NewEventAuditDataDO o = (NewEventAuditDataDO)it.next();
1020               if (dOId.equals(o.oid_getDataEventAudit())) {
1021                  int index = list.indexOf(o);
1022                  if (-1 == index)
1023                     list.add(o);
1024                  else {
1025                     list.set(index, o);
1026                  }
1027               }
1028            }
1029            DOs = new NewEventAuditDataDO[list.size()];
1030            DOs = (NewEventAuditDataDO[])list.toArray(DOs);
1031            if (DOs!=null) {
1032               for (int j=0; j<DOs.length; j++) {
1033                  String JavaDoc vdId=DOs[j].getVariableDefinitionId();
1034
1035                  short vtype=DOs[j].getVariableType();
1036                  Object JavaDoc val;
1037                  switch (vtype) {
1038                     case DODSEventAuditManager.DB_TYPE_BOOLEAN :
1039                        val=new Boolean JavaDoc(DOs[j].getVariableValueBOOL());
1040                        break;
1041                     case DODSEventAuditManager.DB_TYPE_LONG:
1042                        val=new Long JavaDoc(DOs[j].getVariableValueLONG());
1043                        break;
1044                     case DODSEventAuditManager.DB_TYPE_DOUBLE:
1045                        val=new Double JavaDoc(DOs[j].getVariableValueDBL());
1046                        break;
1047                     case DODSEventAuditManager.DB_TYPE_VCHAR:
1048                        val=DOs[j].getVariableValueVCHAR();
1049                        break;
1050                     case DODSEventAuditManager.DB_TYPE_DATE:
1051                        java.sql.Timestamp JavaDoc d=DOs[j].getVariableValueDATE();
1052                        if (d!=null) {
1053                           val=new java.util.Date JavaDoc(d.getTime());
1054                        } else {
1055                           val=null;
1056                        }
1057                        break;
1058                     default:
1059                        byte[] v=DOs[j].getVariableValue();
1060                        if (v!=null && v.length>0) {
1061                           val=MiscUtilities.deserialize(v);
1062                        } else {
1063                           val=null;
1064                        }
1065                  }
1066
1067                  nd.put(vdId,val);
1068               }
1069            }
1070         }
1071         dea.setNewData(nd);
1072      }
1073      catch (Throwable JavaDoc t) {
1074         throw new EventAuditException(t);
1075      }
1076   }
1077
1078   protected void restoreNewEventAuditDataWOB (DataEventAuditPersistenceInterface dea,
1079         DataEventAuditDO deaDO, SharkTransaction ti) throws EventAuditException {
1080      if (deaDO==null) return;
1081
1082      try {
1083         Map nd=new HashMap();
1084         NewEventAuditDataWOBDO[] DOs=deaDO.getNewEventAuditDataWOBDOArray();
1085         if (DOs!=null) {
1086            BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
1087            List list = new ArrayList(Arrays.asList(DOs));
1088            for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.NewEventAuditDataWOBDO");
1089                 it.hasNext();) {
1090               NewEventAuditDataWOBDO o = (NewEventAuditDataWOBDO)it.next();
1091               if (dOId.equals(o.oid_getDataEventAudit())) {
1092                  int index = list.indexOf(o);
1093                  if (-1 == index)
1094                     list.add(o);
1095                  else {
1096                     list.set(index, o);
1097                  }
1098               }
1099            }
1100            DOs = new NewEventAuditDataWOBDO[list.size()];
1101            DOs = (NewEventAuditDataWOBDO[])list.toArray(DOs);
1102            if (DOs!=null) {
1103               for (int j=0; j<DOs.length; j++) {
1104                  String JavaDoc vdId=DOs[j].getVariableDefinitionId();
1105
1106                  short vtype=DOs[j].getVariableType();
1107                  Object JavaDoc val;
1108                  switch (vtype) {
1109                     case DODSEventAuditManager.DB_TYPE_BOOLEAN :
1110                        val=new Boolean JavaDoc(DOs[j].getVariableValueBOOL());
1111                        break;
1112                     case DODSEventAuditManager.DB_TYPE_LONG:
1113                        val=new Long JavaDoc(DOs[j].getVariableValueLONG());
1114                        break;
1115                     case DODSEventAuditManager.DB_TYPE_DOUBLE:
1116                        val=new Double JavaDoc(DOs[j].getVariableValueDBL());
1117                        break;
1118                     case DODSEventAuditManager.DB_TYPE_VCHAR:
1119                        val=DOs[j].getVariableValueVCHAR();
1120                        break;
1121                     case DODSEventAuditManager.DB_TYPE_DATE:
1122                        java.sql.Timestamp JavaDoc d=DOs[j].getVariableValueDATE();
1123                        if (d!=null) {
1124                           val=new java.util.Date JavaDoc(d.getTime());
1125                        } else {
1126                           val=null;
1127                        }
1128                        break;
1129                     default:
1130                        byte[] v=DOs[j].getNewEventAuditDataBLOBDO().getVariableValue();
1131                        if (v!=null && v.length>0) {
1132                           val=MiscUtilities.deserialize(v);
1133                        } else {
1134                           val=null;
1135                        }
1136                  }
1137
1138                  nd.put(vdId,val);
1139               }
1140            }
1141         }
1142         dea.setNewData(nd);
1143      }
1144      catch (Throwable JavaDoc t) {
1145         throw new EventAuditException(t);
1146      }
1147   }
1148   
1149   public List restoreProcessHistory (String JavaDoc procId,
1150                                      SharkTransaction ti) throws EventAuditException {
1151      List history=new ArrayList();
1152
1153      CreateProcessEventAuditDO[] createProcessHistoryDOs=
1154         getPersistedCreateProcessEventObjects(procId,ti);
1155      DataEventAuditDO[] dataHistoryDOs=getPersistedDataEventObjects(procId,null,ti);
1156      StateEventAuditDO[] stateHistoryDOs=getPersistedStateEventObjects(procId,null,ti);
1157      if (createProcessHistoryDOs!=null) {
1158         for (int i=0; i<createProcessHistoryDOs.length; i++) {
1159            CreateProcessEventAuditPersistenceInterface a=new DODSCreateProcessEventAudit();
1160            restore(a,createProcessHistoryDOs[i],ti);
1161            history.add(a);
1162         }
1163      }
1164      if (dataHistoryDOs!=null) {
1165         for (int i=0; i<dataHistoryDOs.length; i++) {
1166            DataEventAuditPersistenceInterface d=new DODSDataEventAudit();
1167            restore(d,dataHistoryDOs[i],ti);
1168            history.add(d);
1169         }
1170      }
1171      if (stateHistoryDOs!=null) {
1172         for (int i=0; i<stateHistoryDOs.length; i++) {
1173            StateEventAuditPersistenceInterface s=new DODSStateEventAudit();
1174            restore(s,stateHistoryDOs[i],ti);
1175            history.add(s);
1176         }
1177      }
1178
1179      return history;
1180   }
1181
1182   public List restoreActivityHistory (String JavaDoc procId,String JavaDoc actId,
1183                                       SharkTransaction ti) throws EventAuditException {
1184      List history=new ArrayList();
1185
1186      AssignmentEventAuditDO[] assignmentHistoryDOs=getPersistedAssignmentEventObjects(procId,actId,ti);
1187      DataEventAuditDO[] dataHistoryDOs=getPersistedDataEventObjects(procId,actId,ti);
1188      StateEventAuditDO[] stateHistoryDOs=getPersistedStateEventObjects(procId,actId,ti);
1189      if (assignmentHistoryDOs!=null) {
1190         for (int i=0; i<assignmentHistoryDOs.length; i++) {
1191            AssignmentEventAuditPersistenceInterface a=
1192               new DODSAssignmentEventAudit();
1193            restore(a,assignmentHistoryDOs[i],ti);
1194            history.add(a);
1195         }
1196      }
1197      if (dataHistoryDOs!=null) {
1198         for (int i=0; i<dataHistoryDOs.length; i++) {
1199            DataEventAuditPersistenceInterface d=
1200               new DODSDataEventAudit();
1201            restore(d,dataHistoryDOs[i],ti);
1202            history.add(d);
1203         }
1204      }
1205      if (stateHistoryDOs!=null) {
1206         for (int i=0; i<stateHistoryDOs.length; i++) {
1207            StateEventAuditPersistenceInterface s=
1208               new DODSStateEventAudit();
1209            restore(s,stateHistoryDOs[i],ti);
1210            history.add(s);
1211         }
1212      }
1213
1214      return history;
1215   }
1216
1217   public void delete(AssignmentEventAuditPersistenceInterface aea,SharkTransaction ti) throws EventAuditException {
1218      // NEVER DELETE EVENTS
1219
if (true) return;
1220      try {
1221         AssignmentEventAuditDO DO=getPersistedObject(aea,ti);
1222         ((SharkDODSTransaction)ti).erase(DO);
1223         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1224
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1225

1226         cus.info(LOG_CHANNEL,"AssignmentEventAudit[processId="+aea.getProcessId()+",activityId="+aea.getActivityId()+"] deleted");
1227      } catch (Throwable JavaDoc tr) {
1228         cus.error(LOG_CHANNEL,"Deleting of AssignmentEventAudit failed");
1229         throw new EventAuditException
1230            ("Deleting of AssignmentEventAudit failed", tr);
1231      }
1232   }
1233
1234   public void delete(DataEventAuditPersistenceInterface dea,SharkTransaction ti) throws EventAuditException {
1235      // NEVER DELETE EVENTS
1236
if (true) return;
1237      try {
1238         DataEventAuditDO DO=getPersistedObject(dea,ti);
1239         ((SharkDODSTransaction)ti).erase(DO);
1240         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1241
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1242
if(dea.getActivityId()!=null) {
1243            cus.info(LOG_CHANNEL,"DataEventAudit[processId="+dea.getProcessId()+",activityId="+dea.getActivityId()+"] deleted");
1244         }
1245         else {
1246            cus.info(LOG_CHANNEL,"DataEventAudit[processId="+dea.getProcessId()+"] deleted");
1247         }
1248      }
1249      catch (Throwable JavaDoc tr) {
1250         cus.error(LOG_CHANNEL,"Deleting of DataEventAudit failed");
1251         throw new EventAuditException
1252            ("Deleting of DataEventAudit failed", tr);
1253      }
1254   }
1255
1256   public void delete(StateEventAuditPersistenceInterface sea,SharkTransaction ti) throws EventAuditException {
1257      // NEVER DELETE EVENTS
1258
if (true) return;
1259      try {
1260         StateEventAuditDO DO=getPersistedObject(sea,ti);
1261         ((SharkDODSTransaction)ti).erase(DO);
1262         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1263
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1264
if(sea.getActivityId()!=null) {
1265            cus.info(LOG_CHANNEL,"StateEventAudit[processId="+sea.getProcessId()+",activityId="+sea.getActivityId()+"] deleted");
1266         }
1267         else {
1268            cus.info(LOG_CHANNEL,"StateEventAudit[processId="+sea.getProcessId()+"] deleted");
1269         }
1270      }
1271      catch (Throwable JavaDoc tr) {
1272         cus.error(LOG_CHANNEL,"Deleting of StateEventAudit failed");
1273         throw new EventAuditException
1274            ("Deleting of StateEventAudit failed", tr);
1275      }
1276   }
1277
1278   public void delete(CreateProcessEventAuditPersistenceInterface cpea,SharkTransaction ti) throws EventAuditException {
1279      // NEVER DELETE EVENTS
1280
if (true) return;
1281      try {
1282         CreateProcessEventAuditDO DO=getPersistedObject(cpea,ti);
1283         ((SharkDODSTransaction)ti).erase(DO);
1284         //DO.delete(((SharkDODSTransaction)ti).getDODSTransaction());
1285
//(((SharkDODSTransaction)ti).getDODSTransaction()).write();
1286
cus.info(LOG_CHANNEL,"CreateProcessEventAudit[processId="+cpea.getProcessId()+"] deleted");
1287      }
1288      catch (Throwable JavaDoc tr) {
1289         cus.error(LOG_CHANNEL,"Deleting of CreateProcessEventAudit failed");
1290         throw new EventAuditException
1291            ("Deleting of CreateProcessEventAudit failed", tr);
1292      }
1293   }
1294
1295   protected AssignmentEventAuditDO getPersistedObject (AssignmentEventAuditPersistenceInterface aea,
1296                                                      SharkTransaction ti) throws EventAuditException {
1297      AssignmentEventAuditDO DO=null;
1298
1299      AssignmentEventAuditQuery query = null;
1300      try {
1301         String JavaDoc procId = aea.getProcessId();
1302         String JavaDoc actId = aea.getActivityId();
1303         String JavaDoc utcTime = aea.getUTCTime();
1304         String JavaDoc eType = aea.getType();
1305         String JavaDoc newResUserName = aea.getNewResourceUsername();
1306         String JavaDoc oldResUserName = aea.getOldResourceUsername();
1307
1308         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.AssignmentEventAuditDO");
1309              it.hasNext();) {
1310            DO = (AssignmentEventAuditDO)it.next();
1311
1312            if (procId.equals(DO.getProcessId()) && actId.equals(DO.getActivityId())
1313                && utcTime.equals(DO.getUTCTime()) && eType.equals(DO.getTheType().getName())
1314                && newResUserName.equals(DO.getNewResourceUsername())
1315                && (oldResUserName==null || oldResUserName.equals(DO.getOldResourceName())))
1316               return DO;
1317         }
1318         query=new AssignmentEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1319
1320         //set query
1321
query.setQueryProcessId(procId);
1322         query.setQueryActivityId(actId);
1323         query.setQueryUTCTime(utcTime);
1324         query.setQueryTheType(getPersistedEventTypeObject(eType,false,ti));
1325         query.setQueryNewResourceUsername(newResUserName);
1326         if (oldResUserName!=null) {
1327            query.setQueryOldResourceUsername(oldResUserName);
1328         }
1329         //query.setQueryIsAccepted(aea.getIsAccepted()); // THE QED is complaining if we uncomment this line
1330

1331         // Throw an exception if more than one object is found
1332
query.requireUniqueInstance();
1333
1334         DO = query.getNextDO();
1335         ((SharkDODSTransaction)ti)._read(DO);
1336
1337         if (DO==null) {
1338            DO=AssignmentEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1339         }
1340         return DO;
1341      }
1342      catch (Throwable JavaDoc t) {
1343         throw new EventAuditException(t);
1344      }
1345   }
1346
1347   protected AssignmentEventAuditDO[] getPersistedAssignmentEventObjects (String JavaDoc pId,String JavaDoc aId,
1348                                                                        SharkTransaction ti) throws EventAuditException {
1349      AssignmentEventAuditDO[] DOs=null;
1350
1351      AssignmentEventAuditQuery query = null;
1352      try {
1353         query=new AssignmentEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1354         //set query
1355
query.setQueryProcessId(pId);
1356         query.setQueryActivityId(aId);
1357         DOs = query.getDOArray();
1358         List list = new ArrayList(Arrays.asList(DOs));
1359         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.AssignmentEventAuditDO");
1360              it.hasNext();) {
1361            AssignmentEventAuditDO DO = (AssignmentEventAuditDO)it.next();
1362            if (pId.equals(DO.getProcessId()) && aId.equals(DO.getActivityId())){
1363               int index = list.indexOf(DO);
1364               if (-1 == index)
1365                  list.add(DO);
1366               else {
1367                  list.set(index, DO);
1368               }
1369               //if (!list.contains(DO))
1370
// list.add(o);
1371
}
1372         }
1373         DOs = new AssignmentEventAuditDO[list.size()];
1374         return (AssignmentEventAuditDO[])list.toArray(DOs);
1375         //return DOs;
1376
}
1377      catch (Throwable JavaDoc t) {
1378         throw new EventAuditException(t);
1379      }
1380   }
1381
1382   protected DataEventAuditDO getPersistedObject (DataEventAuditPersistenceInterface dea,
1383                                                SharkTransaction ti) throws EventAuditException {
1384      DataEventAuditDO DO=null;
1385
1386      DataEventAuditQuery query = null;
1387      try {
1388
1389         String JavaDoc procId = dea.getProcessId();
1390         String JavaDoc actId = dea.getActivityId();
1391         String JavaDoc utcTime = dea.getUTCTime();
1392         String JavaDoc eType = dea.getType();
1393
1394         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.DataEventAuditDO");
1395              it.hasNext();) {
1396            DO = (DataEventAuditDO)it.next();
1397
1398            if (procId.equals(DO.getProcessId()) && utcTime.equals(DO.getUTCTime())) {
1399               if (actId != null){
1400                  if (actId.equals(DO.getActivityId())
1401                      && ( ACTIVITY_CONTEXT_CHANGED.equals(DO.getTheType().getName()) || ACTIVITY_RESULT_CHANGED.equals(DO.getTheType().getName())))
1402                     return DO;
1403               }
1404               else {
1405                  if (PROCESS_CONTEXT_CHANGED.equals(DO.getTheType().getName()))
1406                     return DO;
1407               }
1408            }
1409         }
1410         query=new DataEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1411         //set query
1412
query.setQueryProcessId(procId);
1413         if (actId!=null) {
1414            query.setQueryActivityId(actId);
1415            query.openParen();
1416            query.setQueryTheType(getPersistedEventTypeObject(ACTIVITY_CONTEXT_CHANGED,false,ti));
1417            query.or();
1418            query.setQueryTheType(getPersistedEventTypeObject(ACTIVITY_RESULT_CHANGED,false,ti));
1419            query.closeParen();
1420         }
1421         else {
1422            query.setQueryTheType(getPersistedEventTypeObject(PROCESS_CONTEXT_CHANGED,false,ti));
1423         }
1424         query.setQueryUTCTime(utcTime);
1425         //???? query.setQueryTheType(getPersistedEventTypeObject(dea.getType(),false,ti));
1426

1427         // Throw an exception if more than one object is found
1428
query.requireUniqueInstance();
1429
1430         DO = query.getNextDO();
1431         ((SharkDODSTransaction)ti)._read(DO);
1432
1433         if (DO==null) {
1434            DO=DataEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1435         }
1436         return DO;
1437      }
1438      catch (Throwable JavaDoc t) {
1439         throw new EventAuditException(t);
1440      }
1441   }
1442
1443   protected DataEventAuditDO[] getPersistedDataEventObjects (String JavaDoc pId,String JavaDoc aId,
1444                                                            SharkTransaction ti) throws EventAuditException {
1445      DataEventAuditDO[] DOs=null;
1446
1447      DataEventAuditQuery query = null;
1448      try {
1449         query=new DataEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1450         //set query
1451
query.setQueryProcessId(pId);
1452         if (aId!=null) {
1453            query.setQueryActivityId(aId);
1454            query.openParen();
1455            query.setQueryTheType(getPersistedEventTypeObject(ACTIVITY_CONTEXT_CHANGED,false,ti));
1456            query.or();
1457            query.setQueryTheType(getPersistedEventTypeObject(ACTIVITY_RESULT_CHANGED,false,ti));
1458            query.closeParen();
1459         }
1460         else {
1461            query.setQueryTheType(getPersistedEventTypeObject(PROCESS_CONTEXT_CHANGED,false,ti));
1462         }
1463         DOs = query.getDOArray();
1464         List list = new ArrayList(Arrays.asList(DOs));
1465         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.DataEventAuditDO");
1466              it.hasNext();) {
1467            DataEventAuditDO DO = (DataEventAuditDO)it.next();
1468            if (pId.equals(DO.getProcessId())){
1469               if (aId != null){
1470                  if (aId.equals(DO.getActivityId()) && ( ACTIVITY_CONTEXT_CHANGED.equals(DO.getTheType().getName()) || ACTIVITY_RESULT_CHANGED.equals(DO.getTheType().getName()))){
1471                     int index = list.indexOf(DO);
1472                     if (-1 == index)
1473                        list.add(DO);
1474                     else
1475                        list.set(index, DO);
1476                  }
1477               }
1478               else {
1479                  if (PROCESS_CONTEXT_CHANGED.equals(DO.getTheType().getName())){
1480                     int index = list.indexOf(DO);
1481                     if (-1 == index)
1482                        list.add(DO);
1483                     else
1484                        list.set(index, DO);
1485                  }
1486               }
1487               //if (!list.contains(DO))
1488
// list.add(DO);
1489
}
1490         }
1491         DOs = new DataEventAuditDO[list.size()];
1492         return (DataEventAuditDO[])list.toArray(DOs);
1493         //return DOs;
1494
}
1495      catch (Throwable JavaDoc t) {
1496         throw new EventAuditException(t);
1497      }
1498   }
1499
1500   protected StateEventAuditDO getPersistedObject (StateEventAuditPersistenceInterface sea,
1501                                                 SharkTransaction ti) throws EventAuditException {
1502      StateEventAuditDO DO=null;
1503
1504      StateEventAuditQuery query = null;
1505      try {
1506         String JavaDoc procId = sea.getProcessId();
1507         String JavaDoc actId = sea.getActivityId();
1508         String JavaDoc utcTime = sea.getUTCTime();
1509         String JavaDoc eType = sea.getType();
1510         String JavaDoc nState = sea.getNewState();
1511         String JavaDoc oState = sea.getOldState();
1512
1513         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.StateEventAuditDO");
1514              it.hasNext();) {
1515            DO = (StateEventAuditDO)it.next();
1516
1517            if (procId.equals(DO.getProcessId()) && utcTime.equals(DO.getUTCTime())
1518                && eType.equals(DO.getTheType().getName())) {
1519               if (actId != null){
1520                  if (actId.equals(DO.getActivityId()) && nState.equals(DO.getNewActivityState().getName())
1521                      && ((oState == null) || ((DO.getOldActivityState()!= null) && oState.equals(DO.getOldActivityState().getName()))))
1522                     return DO;
1523               }
1524               else {
1525                  if (nState.equals(DO.getNewProcessState().getName())
1526                      && ((oState == null) || ((DO.getOldProcessState()!= null) && oState.equals(DO.getOldProcessState().getName()))))
1527                     return DO;
1528               }
1529            }
1530         }
1531         query=new StateEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1532         //set query
1533
query.setQueryProcessId(procId);
1534         if (actId!=null) {
1535            query.setQueryActivityId(actId);
1536            query.setQueryNewActivityState(getPersistedActivityStateObject(sea.getNewState(),false,ti));
1537            query.setQueryOldActivityState(getPersistedActivityStateObject(sea.getOldState(),false,ti));
1538         } else {
1539            query.setQueryNewProcessState(getPersistedProcessStateObject(sea.getNewState(),false,ti));
1540            query.setQueryOldProcessState(getPersistedProcessStateObject(sea.getOldState(),false,ti));
1541         }
1542         query.setQueryTheType(getPersistedEventTypeObject(eType,false,ti));
1543         query.setQueryUTCTime(utcTime);
1544
1545         // Throw an exception if more than one object is found
1546
query.requireUniqueInstance();
1547
1548         DO = query.getNextDO();
1549         ((SharkDODSTransaction)ti)._read(DO);
1550
1551         if (DO==null) {
1552            DO=StateEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1553         }
1554         return DO;
1555      }
1556      catch (Throwable JavaDoc t) {
1557         throw new EventAuditException(t);
1558      }
1559   }
1560
1561   protected StateEventAuditDO[] getPersistedStateEventObjects (String JavaDoc pId,String JavaDoc aId,
1562                                                              SharkTransaction ti) throws EventAuditException {
1563      StateEventAuditDO[] DOs=null;
1564
1565      StateEventAuditQuery query = null;
1566      try {
1567         query=new StateEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1568
1569         //set query
1570
query.setQueryProcessId(pId);
1571         if (aId!=null) {
1572            query.setQueryActivityId(aId);
1573            query.setQueryTheType(getPersistedEventTypeObject(ACTIVITY_STATE_CHANGED,false,ti));
1574         }
1575         else {
1576            query.setQueryTheType(getPersistedEventTypeObject(PROCESS_STATE_CHANGED,false,ti));
1577         }
1578         DOs = query.getDOArray();
1579         List list = new ArrayList(Arrays.asList(DOs));
1580         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.StateEventAuditDO");
1581              it.hasNext();) {
1582            StateEventAuditDO DO = (StateEventAuditDO)it.next();
1583            if (pId.equals(DO.getProcessId())){
1584               if (aId != null){
1585                  if (aId.equals(DO.getActivityId()) && ACTIVITY_CONTEXT_CHANGED.equals(DO.getTheType().getName())){
1586                     int index = list.indexOf(DO);
1587                     if (-1 == index)
1588                        list.add(DO);
1589                     else
1590                        list.set(index, DO);
1591                  }
1592               }
1593               else {
1594                  if (PROCESS_CONTEXT_CHANGED.equals(DO.getTheType().getName())){
1595                     int index = list.indexOf(DO);
1596                     if (-1 == index)
1597                        list.add(DO);
1598                     else
1599                        list.set(index, DO);
1600                  }
1601               }
1602               //if (!list.contains(DO))
1603
// list.add(DO);
1604
}
1605         }
1606         DOs = new StateEventAuditDO[list.size()];
1607         return (StateEventAuditDO[])list.toArray(DOs);
1608         //return DOs;
1609
}
1610      catch (Throwable JavaDoc t) {
1611         throw new EventAuditException(t);
1612      }
1613   }
1614
1615   protected CreateProcessEventAuditDO getPersistedObject (CreateProcessEventAuditPersistenceInterface cpea,
1616                                                         SharkTransaction ti) throws EventAuditException {
1617      CreateProcessEventAuditDO DO=null;
1618
1619      CreateProcessEventAuditQuery query = null;
1620      try {
1621         String JavaDoc procId = cpea.getProcessId();
1622
1623         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.CreateProcessEventAuditDO");
1624              it.hasNext();) {
1625            DO = (CreateProcessEventAuditDO)it.next();
1626
1627            if (procId.equals(DO.getProcessId())){
1628               return DO;
1629            }
1630         }
1631         query=new CreateProcessEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1632         //set query
1633
query.setQueryProcessId(procId);
1634
1635         // Throw an exception if more than one object is found
1636
query.requireUniqueInstance();
1637
1638         DO = query.getNextDO();
1639         ((SharkDODSTransaction)ti)._read(DO);
1640
1641         if (DO==null) {
1642            DO=CreateProcessEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1643         }
1644         return DO;
1645      }
1646      catch (Throwable JavaDoc t) {
1647         throw new EventAuditException(t);
1648      }
1649   }
1650
1651   protected OldEventAuditDataDO getPersistedOldEventAuditDataObject (
1652      DataEventAuditDO deaDO,String JavaDoc vdId,SharkTransaction ti) throws EventAuditException {
1653      OldEventAuditDataDO DO=null;
1654
1655      OldEventAuditDataQuery query = null;
1656      try {
1657         BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
1658
1659         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.OldEventAuditDataDO");
1660              it.hasNext();) {
1661            DO = (OldEventAuditDataDO)it.next();
1662
1663            if (dOId.equals(DO.oid_getDataEventAudit()) && vdId.equals(DO.getVariableDefinitionId())){
1664               return DO;
1665            }
1666         }
1667         query=new OldEventAuditDataQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1668         //set query
1669
query.setQueryDataEventAudit(deaDO);
1670         query.setQueryVariableDefinitionId(vdId);
1671
1672         // Throw an exception if more than one object is found
1673
query.requireUniqueInstance();
1674
1675         DO = query.getNextDO();
1676         ((SharkDODSTransaction)ti)._read(DO);
1677
1678         if (DO==null) {
1679            DO=OldEventAuditDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1680         }
1681         return DO;
1682
1683      }
1684      catch (Throwable JavaDoc t) {
1685         throw new EventAuditException(t);
1686      }
1687   }
1688
1689   protected NewEventAuditDataDO getPersistedNewEventAuditDataObject (
1690      DataEventAuditDO deaDO,String JavaDoc vdId,SharkTransaction ti) throws EventAuditException {
1691      NewEventAuditDataDO DO=null;
1692
1693      NewEventAuditDataQuery query = null;
1694      try {
1695         BigDecimal JavaDoc dOId = deaDO.get_OId().toBigDecimal();
1696
1697         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.NewEventAuditDataDO");
1698              it.hasNext();) {
1699            DO = (NewEventAuditDataDO)it.next();
1700
1701            if (dOId.equals(DO.oid_getDataEventAudit()) && vdId.equals(DO.getVariableDefinitionId())){
1702               return DO;
1703            }
1704         }
1705         query=new NewEventAuditDataQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1706         //set query
1707
query.setQueryDataEventAudit(deaDO);
1708         query.setQueryVariableDefinitionId(vdId);
1709
1710         // Throw an exception if more than one object is found
1711
query.requireUniqueInstance();
1712
1713         DO = query.getNextDO();
1714         ((SharkDODSTransaction)ti)._read(DO);
1715
1716         if (DO==null) {
1717            DO=NewEventAuditDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1718         }
1719         return DO;
1720      }
1721      catch (Throwable JavaDoc t) {
1722         throw new EventAuditException(t);
1723      }
1724   }
1725
1726   protected CreateProcessEventAuditDO[] getPersistedCreateProcessEventObjects (String JavaDoc pId,
1727                                                                              SharkTransaction ti) throws EventAuditException {
1728
1729      CreateProcessEventAuditDO[] DOs=null;
1730      CreateProcessEventAuditQuery query = null;
1731
1732      try {
1733         query=new CreateProcessEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1734         //set query
1735
query.setQueryProcessId(pId);
1736
1737         DOs = query.getDOArray();
1738         List list = new ArrayList(Arrays.asList(DOs));
1739         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.CreateProcessEventAuditDO");
1740              it.hasNext();) {
1741            CreateProcessEventAuditDO DO = (CreateProcessEventAuditDO)it.next();
1742            if (pId.equals(DO.getProcessId())){
1743               int index = list.indexOf(DO);
1744               if (-1 == index)
1745                  list.add(DO);
1746               else
1747                  list.set(index, DO);
1748            }
1749            //if (!list.contains(DO))
1750
// list.add(DO);
1751
}
1752         DOs = new CreateProcessEventAuditDO[list.size()];
1753         return (CreateProcessEventAuditDO[])list.toArray(DOs);
1754         //return DOs;
1755
}
1756      catch (Throwable JavaDoc t) {
1757         throw new EventAuditException(t);
1758      }
1759   }
1760
1761   protected ProcessStateEventAuditDO getPersistedProcessStateObject (
1762      String JavaDoc value,boolean searchByKeyValue,SharkTransaction ti) throws EventAuditException {
1763      ProcessStateEventAuditDO DO=null;
1764
1765      ProcessStateEventAuditQuery query = null;
1766      try {
1767         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.ProcessStateEventAuditDO");
1768              it.hasNext();) {
1769            DO = (ProcessStateEventAuditDO)it.next();
1770            if (searchByKeyValue){
1771               if (value.equals(DO.getKeyValue())){
1772                  return DO;
1773               }
1774            }
1775            else{
1776               if (value.equals(DO.getName())){
1777                  return DO;
1778               }
1779            }
1780
1781         }
1782         query=new ProcessStateEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1783         //set query
1784
if (searchByKeyValue) {
1785            query.setQueryKeyValue(value);
1786         }
1787         else {
1788            query.setQueryName(value);
1789         }
1790
1791         // Throw an exception if more than one object is found
1792
query.requireUniqueInstance();
1793
1794         DO = query.getNextDO();
1795         ((SharkDODSTransaction)ti)._read(DO);
1796
1797         if (DO==null) {
1798            DO=ProcessStateEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1799         }
1800         return DO;
1801      }
1802      catch (Throwable JavaDoc t) {
1803         throw new EventAuditException(t);
1804      }
1805   }
1806
1807   protected ActivityStateEventAuditDO getPersistedActivityStateObject (
1808      String JavaDoc value,boolean searchByKeyValue,DBTransaction ti) throws EventAuditException {
1809      ActivityStateEventAuditDO DO=null;
1810
1811      ActivityStateEventAuditQuery query = null;
1812      try {
1813         query=new ActivityStateEventAuditQuery(ti);
1814         //set query
1815
if (searchByKeyValue) {
1816            query.setQueryKeyValue(value);
1817         }
1818         else {
1819            query.setQueryName(value);
1820         }
1821
1822         // Throw an exception if more than one object is found
1823
query.requireUniqueInstance();
1824
1825         DO = query.getNextDO();
1826         if (DO==null) {
1827            DO=ActivityStateEventAuditDO.createVirgin(ti);
1828         }
1829         return DO;
1830      }
1831      catch (Throwable JavaDoc t) {
1832         throw new EventAuditException(t);
1833      }
1834   }
1835
1836   protected ActivityStateEventAuditDO getPersistedActivityStateObject (
1837      String JavaDoc value,boolean searchByKeyValue,SharkTransaction ti) throws EventAuditException {
1838      ActivityStateEventAuditDO DO=null;
1839
1840      ActivityStateEventAuditQuery query = null;
1841      try {
1842         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.ActivityStateEventAuditDO");
1843              it.hasNext();) {
1844            DO = (ActivityStateEventAuditDO)it.next();
1845            if (searchByKeyValue){
1846               if (value.equals(DO.getKeyValue())){
1847                  return DO;
1848               }
1849            }
1850            else{
1851               if (value.equals(DO.getName())){
1852                  return DO;
1853               }
1854            }
1855         }
1856         query=new ActivityStateEventAuditQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1857         //set query
1858
if (searchByKeyValue) {
1859            query.setQueryKeyValue(value);
1860         }
1861         else {
1862            query.setQueryName(value);
1863         }
1864
1865         // Throw an exception if more than one object is found
1866
query.requireUniqueInstance();
1867
1868         DO = query.getNextDO();
1869         ((SharkDODSTransaction)ti)._read(DO);
1870
1871         if (DO==null) {
1872            DO=ActivityStateEventAuditDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1873         }
1874         return DO;
1875      }
1876      catch (Throwable JavaDoc t) {
1877         throw new EventAuditException(t);
1878      }
1879   }
1880
1881   protected ProcessStateEventAuditDO getPersistedProcessStateObject (
1882      String JavaDoc value,boolean searchByKeyValue,DBTransaction ti) throws EventAuditException {
1883      ProcessStateEventAuditDO DO=null;
1884
1885      ProcessStateEventAuditQuery query = null;
1886      try {
1887         query=new ProcessStateEventAuditQuery(ti);
1888         //set query
1889
if (searchByKeyValue) {
1890            query.setQueryKeyValue(value);
1891         }
1892         else {
1893            query.setQueryName(value);
1894         }
1895
1896         // Throw an exception if more than one object is found
1897
query.requireUniqueInstance();
1898
1899         DO = query.getNextDO();
1900         if (DO==null) {
1901            DO=ProcessStateEventAuditDO.createVirgin(ti);
1902         }
1903         return DO;
1904      }
1905      catch (Throwable JavaDoc t) {
1906         throw new EventAuditException(t);
1907      }
1908   }
1909
1910   protected EventTypeDO getPersistedEventTypeObject (String JavaDoc value,
1911                                                    boolean searchByKeyValue,SharkTransaction ti) throws EventAuditException {
1912      EventTypeDO DO=null;
1913
1914      EventTypeQuery query = null;
1915      try {
1916         for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.eventaudit.data.EventTypeDO");
1917              it.hasNext();) {
1918            DO = (EventTypeDO)it.next();
1919            if (searchByKeyValue){
1920               if (value.equals(DO.getKeyValue())){
1921                  return DO;
1922               }
1923            }
1924            else{
1925               if (value.equals(DO.getName())){
1926                  return DO;
1927               }
1928            }
1929         }
1930         query=new EventTypeQuery(((SharkDODSTransaction)ti).getDODSTransaction());
1931         //set query
1932
if (searchByKeyValue) {
1933            query.setQueryKeyValue(value);
1934         }
1935         else {
1936            query.setQueryName(value);
1937         }
1938
1939         // Throw an exception if more than one object is found
1940
query.requireUniqueInstance();
1941
1942         DO = query.getNextDO();
1943         ((SharkDODSTransaction)ti)._read(DO);
1944
1945         if (DO==null) {
1946            DO=EventTypeDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction());
1947         }
1948         return DO;
1949      }
1950      catch (Throwable JavaDoc t) {
1951         throw new EventAuditException(t);
1952      }
1953   }
1954
1955   protected EventTypeDO getPersistedEventTypeObject (String JavaDoc value,
1956                                                    boolean searchByKeyValue,DBTransaction ti) throws EventAuditException {
1957      EventTypeDO DO=null;
1958
1959      EventTypeQuery query = null;
1960      try {
1961         query=new EventTypeQuery(ti);
1962         //set query
1963
if (searchByKeyValue) {
1964            query.setQueryKeyValue(value);
1965         }
1966         else {
1967            query.setQueryName(value);
1968         }
1969
1970         // Throw an exception if more than one object is found
1971
query.requireUniqueInstance();
1972
1973         DO = query.getNextDO();
1974
1975         if (DO==null) {
1976            DO=EventTypeDO.createVirgin(ti);
1977         }
1978         return DO;
1979      }
1980      catch (Throwable JavaDoc t) {
1981         throw new EventAuditException(t);
1982      }
1983   }
1984
1985   public AssignmentEventAuditPersistenceInterface createAssignmentEventAudit () {
1986      return new DODSAssignmentEventAudit();
1987   }
1988
1989   public CreateProcessEventAuditPersistenceInterface createCreateProcessEventAudit () {
1990      return new DODSCreateProcessEventAudit();
1991   }
1992
1993   public DataEventAuditPersistenceInterface createDataEventAudit () {
1994      return new DODSDataEventAudit();
1995   }
1996
1997   public StateEventAuditPersistenceInterface createStateEventAudit () {
1998      return new DODSStateEventAudit();
1999   }
2000
2001   public BigDecimal JavaDoc getNextDecId(String JavaDoc idName) throws EventAuditException {
2002      try {
2003         return DODSUtilities.getNext(idName);
2004      } catch (Exception JavaDoc e) {
2005         throw new EventAuditException("Couldn't allocate id");
2006      }
2007   }
2008
2009   public String JavaDoc getNextId(String JavaDoc idName) throws EventAuditException {
2010      return getNextDecId(idName).toString();
2011   }
2012}
2013
2014
Popular Tags