KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > partmappersistence > DODSParticipantMappingMgr


1 package org.enhydra.shark.partmappersistence;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.enhydra.dods.DODS;
7 import org.enhydra.shark.api.ParticipantMappingTransaction;
8 import org.enhydra.shark.api.RootException;
9 import org.enhydra.shark.api.TransactionException;
10 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMap;
11 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMappingManager;
12 import org.enhydra.shark.api.internal.working.CallbackUtilities;
13 import org.enhydra.shark.partmappersistence.data.*;
14
15 import com.lutris.appserver.server.sql.DBTransaction;
16
17 /**
18  * Implementation of ParticipantMappingsManager interface
19  * @author Zoran Milakovic
20  */

21 public class DODSParticipantMappingMgr implements ParticipantMappingManager {
22
23 //TODO zoran Ako je processId == "" tretirati ga kao null.
24

25   public static boolean _debug_ = false;
26
27   private static final String JavaDoc DBG_PARAM_NAME = "DODSParticipantMappingMgr.debug";
28
29   public void configure (CallbackUtilities cus) throws RootException {
30      if (null == cus)
31             throw new RootException("Cannot configure without call back impl.");
32          _debug_ = Boolean
33             .valueOf(cus.getProperty(DBG_PARAM_NAME, "false"))
34             .booleanValue();
35   }
36
37    /**
38     * Save new ParticipantMap to database.
39     *
40     * @param trans ParticipantMappingTransaction
41     * @param pm ParticipantMap to save
42     * @return boolean true if everything is ok, false otherwise
43     * @exception RootException RootException will be thrown if error occure.
44     *
45     */

46    public boolean saveParticipantMapping(
47       ParticipantMappingTransaction trans,
48       ParticipantMap pm)
49       throws RootException {
50       boolean retVal = true;
51       if (!checkValidity(pm)) {
52          throw new RootException("Participant mapping [ " + pm + " ] is not valid");
53       }
54       if (doesParticipantMappingExist(trans, pm)) {
55          throw new RootException("Participant mapping already exists");
56       }
57       try {
58          DBTransaction dbTrans = this.getDBTransaction(trans);
59          //if group user
60
if (pm.getIsGroupUser()) {
61             GroupUserProcLevelParticipantDO mappDO =
62                GroupUserProcLevelParticipantDO.createVirgin(dbTrans);
63             GroupUserDO groupDO = this.checkGroups(trans, pm);
64             //process level participant
65
if (pm.getProcessDefinitionId() != null) {
66                ProcLevelParticipantDO procLevPartDO =
67                   this.checkProcLevelParticipant(trans, pm);
68                GroupUserProcLevelParticipantDO gplPart =
69                   GroupUserProcLevelParticipantDO.createVirgin(dbTrans);
70                gplPart.setPARTICIPANTOID(procLevPartDO);
71                gplPart.setUSEROID(groupDO);
72                gplPart.save();
73             }
74             //package level participant
75
else {
76                PackLevelParticipantDO pckgLevPartDO =
77                   this.checkPackLevelParticipant(trans, pm);
78                GroupUserPackLevelParticipantDO gplPart =
79                   GroupUserPackLevelParticipantDO.createVirgin(dbTrans);
80                gplPart.setPARTICIPANTOID(pckgLevPartDO);
81                gplPart.setUSEROID(groupDO);
82                gplPart.save();
83             }
84
85          }
86          //if single user
87
else {
88             UserProcLevelParticipantDO mappDO =
89                UserProcLevelParticipantDO.createVirgin(dbTrans);
90             NormalUserDO userDO = this.checkUsers(trans, pm);
91             if (pm.getProcessDefinitionId() != null) {
92                ProcLevelParticipantDO procLevPartDO =
93                   this.checkProcLevelParticipant(trans, pm);
94                UserProcLevelParticipantDO uplPart =
95                   UserProcLevelParticipantDO.createVirgin(dbTrans);
96                uplPart.setPARTICIPANTOID(procLevPartDO);
97                uplPart.setUSEROID(userDO);
98                uplPart.save();
99             } else {
100                PackLevelParticipantDO pckgLevPartDO =
101                   this.checkPackLevelParticipant(trans, pm);
102                UserPackLevelParticipantDO uplPart =
103                   UserPackLevelParticipantDO.createVirgin(dbTrans);
104                uplPart.setPARTICIPANTOID(pckgLevPartDO);
105                uplPart.setUSEROID(userDO);
106                uplPart.save();
107             }
108          }
109          dbTrans.write();
110       } catch (Exception JavaDoc e) {
111          throw new RootException(e);
112       }
113       return retVal;
114    }
115
116    /**
117     * Delete specified ParticipantMap from
118     * database.
119     *
120     * @param trans ParticipantMappingTransaction
121     * @param pm ParticipantMap to delete
122     * @return boolean true if everything is ok, false otherwise
123     * @exception RootException RootException will be thrown if error occure.
124     *
125     */

126    public boolean deleteParticipantMapping(
127       ParticipantMappingTransaction trans,
128       ParticipantMap pm)
129       throws RootException {
130
131       boolean retVal = true;
132       if (!checkValidity(pm)) {
133          throw new RootException("Participant mapping [ " + pm + " ] is not valid");
134       }
135       try {
136          DBTransaction dbTrans = this.getDBTransaction(trans);
137          String JavaDoc processId = pm.getProcessDefinitionId();
138          boolean isGroup = pm.getIsGroupUser();
139          //process level part.
140
if (processId != null) {
141             //group user
142
if (isGroup) {
143                this.deleteGroupProcLevelPart(pm, dbTrans);
144             }
145             //single user
146
else {
147                this.deleteNormalProcLevelPart(pm, dbTrans);
148             }
149          }
150          //package level part.
151
else {
152             //group user
153
if (isGroup) {
154                this.deleteGroupPackLevelPart(pm, dbTrans);
155             }
156             //single user
157
else {
158                this.deleteNormalPackLevelPart(pm, dbTrans);
159             }
160          }
161          dbTrans.write();
162       } catch (Exception JavaDoc e) {
163          throw new RootException(e);
164       }
165
166       return retVal;
167
168    }
169
170    /**
171     * Check if specified participant map exist in database.
172     *
173     * @param trans ParticipantMappingTransaction
174     * @param pm ParticipantMap to delete
175     * @return boolean true if everything is ok, false otherwise
176     * @exception RootException RootException will be thrown if error occure.
177     *
178     */

179    public boolean doesParticipantMappingExist(
180       ParticipantMappingTransaction trans,
181       ParticipantMap pm)
182       throws RootException {
183       boolean isExist = false;
184       if (!checkValidity(pm)) {
185          throw new RootException("Participant mapping [ " + pm + " ] is not valid");
186       }
187       try {
188          DBTransaction dbTrans = this.getDBTransaction(trans);
189          //if group user
190
if (pm.getIsGroupUser()) {
191             GroupUserProcLevelParticipantDO mappDO =
192                GroupUserProcLevelParticipantDO.createVirgin(dbTrans);
193             GroupUserDO groupDO = this.checkGroups(trans, pm);
194             //process level participant
195
if (pm.getProcessDefinitionId() != null) {
196                ProcLevelParticipantDO procLevPartDO =
197                   this.checkProcLevelParticipant(trans, pm);
198                GroupUserProcLevelParticipantQuery gplPartQuery =
199                   new GroupUserProcLevelParticipantQuery(dbTrans);
200                gplPartQuery.setQueryPARTICIPANTOID(procLevPartDO);
201                gplPartQuery.setQueryUSEROID(groupDO);
202                if (gplPartQuery.getNextDO() != null) {
203                   isExist = true;
204                } else {
205                   this.deleteParticipantMapping(trans,pm);
206                }
207             }
208             //package level participant
209
else {
210                PackLevelParticipantDO pckgLevPartDO =
211                   this.checkPackLevelParticipant(trans, pm);
212                GroupUserPackLevelParticipantQuery gplPartQuery =
213                   new GroupUserPackLevelParticipantQuery(dbTrans);
214                gplPartQuery.setQueryPARTICIPANTOID(pckgLevPartDO);
215                gplPartQuery.setQueryUSEROID(groupDO);
216                if (gplPartQuery.getNextDO() != null) {
217                   isExist = true;
218                } else {
219                   this.deleteParticipantMapping(trans,pm);
220                }
221             }
222          }
223          //if single user
224
else {
225             UserProcLevelParticipantDO mappDO =
226                UserProcLevelParticipantDO.createVirgin(dbTrans);
227             NormalUserDO userDO = this.checkUsers(trans, pm);
228             if (pm.getProcessDefinitionId() != null) {
229                ProcLevelParticipantDO procLevPartDO =
230                   this.checkProcLevelParticipant(trans, pm);
231                UserProcLevelParticipantQuery uplPartQuery =
232                   new UserProcLevelParticipantQuery(dbTrans);
233                uplPartQuery.setQueryPARTICIPANTOID(procLevPartDO);
234                uplPartQuery.setQueryUSEROID(userDO);
235                if (uplPartQuery.getNextDO() != null) {
236                   isExist = true;
237                } else {
238                   this.deleteParticipantMapping(trans,pm);
239                }
240             } else {
241                PackLevelParticipantDO pckgLevPartDO =
242                   this.checkPackLevelParticipant(trans, pm);
243                UserPackLevelParticipantQuery uplPartQuery =
244                   new UserPackLevelParticipantQuery(dbTrans);
245                uplPartQuery.setQueryPARTICIPANTOID(pckgLevPartDO);
246                uplPartQuery.setQueryUSEROID(userDO);
247                if (uplPartQuery.getNextDO() != null) {
248                   isExist = true;
249                } else {
250                   this.deleteParticipantMapping(trans,pm);
251                }
252             }
253          }
254
255       } catch (Exception JavaDoc e) {
256          throw new RootException(e);
257       }
258       return isExist;
259    }
260
261    /**
262     * Gets all ParticipantMappings from database.
263     * @param trans ParticipantMappingTransaction
264     * @return List List with participant mappings.
265     * @exception RootException RootException will be thrown if error occure.
266     *
267     */

268    public List JavaDoc getAllParticipantMappings(ParticipantMappingTransaction trans)
269       throws RootException {
270       List JavaDoc list = new ArrayList JavaDoc();
271       try {
272          DBTransaction dbTrans = this.getDBTransaction(trans);
273          //group users, package level
274
GroupUserPackLevelParticipantQuery gplQuery =
275             new GroupUserPackLevelParticipantQuery(dbTrans);
276          GroupUserPackLevelParticipantDO[] gplDOArray =
277             gplQuery.getDOArray();
278          for (int i = 0; i < gplDOArray.length; i++) {
279             ParticipantMap pm = this.createParticipantMap();
280             pm.setParticipantId(
281                gplDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
282             pm.setPackageId(
283                gplDOArray[i]
284                   .getPARTICIPANTOID()
285                   .getPACKAGEOID()
286                   .getPACKAGE_ID());
287             pm.setUsername(gplDOArray[i].getUSEROID().getUSERNAME());
288             pm.setProcessDefinitionId(null);
289             pm.setIsGroupUser(true);
290             list.add(pm);
291          }
292          //group users, process level
293
GroupUserProcLevelParticipantQuery gprlQuery =
294             new GroupUserProcLevelParticipantQuery(dbTrans);
295          GroupUserProcLevelParticipantDO[] gprlDOArray =
296             gprlQuery.getDOArray();
297          for (int i = 0; i < gprlDOArray.length; i++) {
298             ParticipantMap pm = this.createParticipantMap();
299             pm.setParticipantId(
300                gprlDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
301             pm.setPackageId(
302                gprlDOArray[i]
303                   .getPARTICIPANTOID()
304                   .getPROCESSOID()
305                   .getPACKAGEOID()
306                   .getPACKAGE_ID());
307             pm.setUsername(gprlDOArray[i].getUSEROID().getUSERNAME());
308             pm.setProcessDefinitionId(
309                gprlDOArray[i]
310                   .getPARTICIPANTOID()
311                   .getPROCESSOID()
312                   .getPROCESS_ID());
313             pm.setIsGroupUser(true);
314             list.add(pm);
315          }
316          //single users, package level
317
UserPackLevelParticipantQuery uplQuery =
318             new UserPackLevelParticipantQuery(dbTrans);
319          UserPackLevelParticipantDO[] uplDOArray = uplQuery.getDOArray();
320          for (int i = 0; i < uplDOArray.length; i++) {
321             ParticipantMap pm = this.createParticipantMap();
322             pm.setParticipantId(
323                uplDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
324             pm.setPackageId(
325                uplDOArray[i]
326                   .getPARTICIPANTOID()
327                   .getPACKAGEOID()
328                   .getPACKAGE_ID());
329             pm.setUsername(uplDOArray[i].getUSEROID().getUSERNAME());
330             pm.setProcessDefinitionId(null);
331             pm.setIsGroupUser(false);
332             list.add(pm);
333          }
334          //single users, process level
335
UserProcLevelParticipantQuery uprlQuery =
336             new UserProcLevelParticipantQuery(dbTrans);
337          UserProcLevelParticipantDO[] uprlDOArray = uprlQuery.getDOArray();
338          for (int i = 0; i < uprlDOArray.length; i++) {
339             ParticipantMap pm = this.createParticipantMap();
340             pm.setParticipantId(
341                uprlDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
342             pm.setPackageId(
343                uprlDOArray[i]
344                   .getPARTICIPANTOID()
345                   .getPROCESSOID()
346                   .getPACKAGEOID()
347                   .getPACKAGE_ID());
348             pm.setUsername(uprlDOArray[i].getUSEROID().getUSERNAME());
349             pm.setProcessDefinitionId(
350                uprlDOArray[i]
351                   .getPARTICIPANTOID()
352                   .getPROCESSOID()
353                   .getPROCESS_ID());
354             pm.setIsGroupUser(false);
355             list.add(pm);
356          }
357          //return list with all participant mappings
358
return list;
359       } catch (Exception JavaDoc e) {
360          throw new RootException(e);
361       }
362    }
363
364    /**
365     * Method createParticipantMap create new ParticipantMap object.
366     *
367     * @return a ParticipantMap
368     *
369     */

370    public ParticipantMap createParticipantMap() {
371       return new DODSParticipantMap();
372    }
373
374    /**
375     * Gets all participant mappings for
376     * specified parameters.
377     *
378     * @param trans ParticipantMappingTransaction
379     * @param packageId Package id for this mapping.
380     * @param processDefinitionId Process id for this mapping.
381     * @param participantId Participant id for this mapping.
382     * @return a List List with objects ParticipantMap.
383     * @exception RootException RootException will be thrown if error occure.
384     *
385     */

386    public List JavaDoc getParticipantMappings(
387       ParticipantMappingTransaction trans,
388       String JavaDoc packageId,
389       String JavaDoc processDefinitionId,
390       String JavaDoc participantId)
391       throws RootException {
392       List JavaDoc list = new ArrayList JavaDoc();
393       try {
394          // empty string is same as null
395
if( processDefinitionId != null && processDefinitionId.trim().equals("") )
396             processDefinitionId = null;
397          DBTransaction dbTrans = this.getDBTransaction(trans);
398          if (processDefinitionId == null) {
399             //group users, package level
400
XPDLParticipantPackageQuery pQuery = new XPDLParticipantPackageQuery(dbTrans);
401             pQuery.setQueryPACKAGE_ID(packageId);
402             pQuery.requireUniqueInstance();
403             XPDLParticipantPackageDO pDO = pQuery.getNextDO();
404
405             PackLevelParticipantQuery plpQuery =
406                new PackLevelParticipantQuery(dbTrans);
407             plpQuery.setQueryPARTICIPANT_ID(participantId);
408             plpQuery.setQueryPACKAGEOID(pDO);
409             plpQuery.requireUniqueInstance();
410             PackLevelParticipantDO plpDO = plpQuery.getNextDO();
411
412             GroupUserPackLevelParticipantQuery gplQuery =
413                new GroupUserPackLevelParticipantQuery(dbTrans);
414             gplQuery.setQueryPARTICIPANTOID(plpDO);
415             GroupUserPackLevelParticipantDO[] gplDOArray =
416                gplQuery.getDOArray();
417
418             for (int i = 0; i < gplDOArray.length; i++) {
419                ParticipantMap pm = this.createParticipantMap();
420                pm.setParticipantId(
421                   gplDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
422                pm.setPackageId(
423                   gplDOArray[i]
424                      .getPARTICIPANTOID()
425                      .getPACKAGEOID()
426                      .getPACKAGE_ID());
427                pm.setUsername(gplDOArray[i].getUSEROID().getUSERNAME());
428                pm.setProcessDefinitionId(null);
429                pm.setIsGroupUser(true);
430                list.add(pm);
431             }
432             //single users, package level
433
UserPackLevelParticipantQuery uplQuery =
434                new UserPackLevelParticipantQuery(dbTrans);
435             uplQuery.setQueryPARTICIPANTOID(plpDO);
436             UserPackLevelParticipantDO[] uplDOArray = uplQuery.getDOArray();
437
438             for (int i = 0; i < uplDOArray.length; i++) {
439                ParticipantMap pm = this.createParticipantMap();
440                pm.setParticipantId(
441                   uplDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
442                pm.setPackageId(
443                   uplDOArray[i]
444                      .getPARTICIPANTOID()
445                      .getPACKAGEOID()
446                      .getPACKAGE_ID());
447                pm.setUsername(uplDOArray[i].getUSEROID().getUSERNAME());
448                pm.setProcessDefinitionId(null);
449                pm.setIsGroupUser(false);
450                list.add(pm);
451             }
452          } else {
453             //group users, process level
454
XPDLParticipantProcessQuery pQuery = new XPDLParticipantProcessQuery(dbTrans);
455             pQuery.setQueryPROCESS_ID(processDefinitionId);
456             pQuery.requireUniqueInstance();
457             XPDLParticipantProcessDO pDO = pQuery.getNextDO();
458
459             ProcLevelParticipantQuery plpQuery =
460                new ProcLevelParticipantQuery(dbTrans);
461             plpQuery.setQueryPARTICIPANT_ID(participantId);
462             plpQuery.setQueryPROCESSOID(pDO);
463             plpQuery.requireUniqueInstance();
464             ProcLevelParticipantDO plpDO = plpQuery.getNextDO();
465
466             GroupUserProcLevelParticipantQuery gprlQuery =
467                new GroupUserProcLevelParticipantQuery(dbTrans);
468             gprlQuery.setQueryPARTICIPANTOID(plpDO);
469             GroupUserProcLevelParticipantDO[] gprlDOArray =
470                gprlQuery.getDOArray();
471
472             for (int i = 0; i < gprlDOArray.length; i++) {
473                ParticipantMap pm = this.createParticipantMap();
474                pm.setParticipantId(
475                   gprlDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
476                pm.setPackageId(
477                   gprlDOArray[i]
478                      .getPARTICIPANTOID()
479                      .getPROCESSOID()
480                      .getPACKAGEOID()
481                      .getPACKAGE_ID());
482                pm.setUsername(gprlDOArray[i].getUSEROID().getUSERNAME());
483                pm.setProcessDefinitionId(
484                   gprlDOArray[i]
485                      .getPARTICIPANTOID()
486                      .getPROCESSOID()
487                      .getPROCESS_ID());
488                pm.setIsGroupUser(true);
489                list.add(pm);
490             }
491             //single users, process level
492
UserProcLevelParticipantQuery uprlQuery =
493                new UserProcLevelParticipantQuery(dbTrans);
494             uprlQuery.setQueryPARTICIPANTOID(plpDO);
495             UserProcLevelParticipantDO[] uprlDOArray =
496                uprlQuery.getDOArray();
497             for (int i = 0; i < uprlDOArray.length; i++) {
498                ParticipantMap pm = this.createParticipantMap();
499                pm.setParticipantId(
500                   uprlDOArray[i].getPARTICIPANTOID().getPARTICIPANT_ID());
501                pm.setPackageId(
502                   uprlDOArray[i]
503                      .getPARTICIPANTOID()
504                      .getPROCESSOID()
505                      .getPACKAGEOID()
506                      .getPACKAGE_ID());
507                pm.setUsername(uprlDOArray[i].getUSEROID().getUSERNAME());
508                pm.setProcessDefinitionId(
509                   uprlDOArray[i]
510                      .getPARTICIPANTOID()
511                      .getPROCESSOID()
512                      .getPROCESS_ID());
513                pm.setIsGroupUser(false);
514                list.add(pm);
515             }
516          }
517          //return list with all participant mappings
518
return list;
519       } catch (Exception JavaDoc e) {
520          throw new RootException(e);
521       }
522    }
523
524    /**
525     * Method deleteParticipantMappings delete participant mappings
526     * for specified parameters.
527     *
528     * @param trans ParticipantMappingTransaction
529     * @param packageId Package id
530     * @param processDefinitionId Process id
531     * @param participantId Participant id
532     * @return boolean true if OK, false otherwise
533     * @exception RootException RootException will be thrown if error occure.
534     *
535     */

536    public boolean deleteParticipantMappings(
537       ParticipantMappingTransaction trans,
538       String JavaDoc packageId,
539       String JavaDoc processDefinitionId,
540       String JavaDoc participantId)
541       throws RootException {
542       boolean retVal = true;
543       try {
544          //empty string is same as null
545
if( processDefinitionId != null && processDefinitionId.trim().equals("") )
546           processDefinitionId = null;
547          ParticipantMap pm = this.createParticipantMap();
548          DBTransaction dbTrans = this.getDBTransaction(trans);
549          pm.setPackageId(packageId);
550          pm.setProcessDefinitionId(processDefinitionId);
551          pm.setParticipantId(participantId);
552          //normal users
553
NormalUserQuery nuQuery = new NormalUserQuery(dbTrans);
554          NormalUserDO[] nuDOArr = nuQuery.getDOArray();
555          for (int i = 0; i < nuDOArr.length; i++) {
556             pm.setIsGroupUser(false);
557             pm.setUsername(nuDOArr[i].getUSERNAME());
558             if (processDefinitionId != null) {
559                this.deleteNormalProcLevelPart(pm, dbTrans);
560             } else {
561                this.deleteNormalPackLevelPart(pm, dbTrans);
562             }
563          }
564          //group users
565
GroupUserQuery guQuery = new GroupUserQuery(dbTrans);
566          GroupUserDO[] guDOArr = guQuery.getDOArray();
567          for (int i = 0; i < guDOArr.length; i++) {
568             pm.setIsGroupUser(true);
569             pm.setUsername(guDOArr[i].getUSERNAME());
570             if (processDefinitionId != null) {
571                this.deleteGroupProcLevelPart(pm, dbTrans);
572             } else {
573                this.deleteGroupPackLevelPart(pm, dbTrans);
574             }
575          }
576          dbTrans.write();
577       } catch (Exception JavaDoc e) {
578          throw new RootException(e);
579       }
580       return retVal;
581    }
582
583    /**
584     * Method deleteParticipantMappings delete participant mappings
585     * for specified parameters.
586     *
587     * @param trans ParticipantMappingTransaction
588     * @param username username(s) to delete
589     * @return boolean true if everything is OK, false otherwise
590     * @exception RootException RootException will be thrown if error occure.
591     *
592     */

593    public boolean deleteParticipantMappings(
594       ParticipantMappingTransaction trans,
595       String JavaDoc username)
596       throws RootException {
597       boolean retVal = true;
598       try {
599          DBTransaction dbTrans = this.getDBTransaction(trans);
600          String JavaDoc packageId = null;
601          String JavaDoc processId = null;
602          String JavaDoc participantId = null;
603
604          NormalUserQuery userQuery = new NormalUserQuery(dbTrans);
605          userQuery.setQueryUSERNAME(username);
606          userQuery.requireUniqueInstance();
607          NormalUserDO userDO = userQuery.getNextDO();
608
609          //process level part.
610
UserProcLevelParticipantQuery uplpQuery =
611             new UserProcLevelParticipantQuery(dbTrans);
612          uplpQuery.setQueryUSEROID(userDO);
613          UserProcLevelParticipantDO[] uplpDOArray = uplpQuery.getDOArray();
614          for (int i = 0; i < uplpDOArray.length; i++) {
615             XPDLParticipantProcessDO procDO =
616                uplpDOArray[i].getPARTICIPANTOID().getPROCESSOID();
617             uplpDOArray[i].delete();
618             dbTrans.write();
619             this.deleteProcLevParticipant(
620                uplpDOArray[i].getPARTICIPANTOID(),
621                dbTrans);
622             dbTrans.write();
623             //process
624
this.deleteProcess(procDO, dbTrans);
625             XPDLParticipantPackageDO pckDO = procDO.getPACKAGEOID();
626             this.deletePackage(pckDO, dbTrans);
627          }
628
629          //package level part.
630
UserPackLevelParticipantQuery upclpQuery =
631             new UserPackLevelParticipantQuery(dbTrans);
632          upclpQuery.setQueryUSEROID(userDO);
633          UserPackLevelParticipantDO[] upclpDOArray = upclpQuery.getDOArray();
634          for (int i = 0; i < upclpDOArray.length; i++) {
635             upclpDOArray[i].delete();
636             dbTrans.write();
637             this.deletePackLevParticipant(
638                upclpDOArray[i].getPARTICIPANTOID(),
639                dbTrans);
640             XPDLParticipantPackageDO pckDO =
641                upclpDOArray[i].getPARTICIPANTOID().getPACKAGEOID();
642             this.deletePackage(pckDO, dbTrans);
643          }
644          if (userDO != null)
645             this.deleteNormalUser(userDO, dbTrans);
646          //group user
647
GroupUserQuery groupQuery = new GroupUserQuery(dbTrans);
648          groupQuery.requireUniqueInstance();
649          groupQuery.setQueryUSERNAME(username);
650          GroupUserDO groupDO = groupQuery.getNextDO();
651
652          //process level part.
653
GroupUserProcLevelParticipantQuery gplpQuery =
654             new GroupUserProcLevelParticipantQuery(dbTrans);
655          gplpQuery.setQueryUSEROID(groupDO);
656          GroupUserProcLevelParticipantDO[] gplpDOArray =
657             gplpQuery.getDOArray();
658          for (int i = 0; i < gplpDOArray.length; i++) {
659             XPDLParticipantProcessDO procDO =
660                gplpDOArray[i].getPARTICIPANTOID().getPROCESSOID();
661             gplpDOArray[i].delete();
662             dbTrans.write();
663             this.deleteProcLevParticipant(
664                gplpDOArray[i].getPARTICIPANTOID(),
665                dbTrans);
666             dbTrans.write();
667             //process
668
this.deleteProcess(procDO, dbTrans);
669             XPDLParticipantPackageDO pckDO = procDO.getPACKAGEOID();
670             this.deletePackage(pckDO, dbTrans);
671          }
672
673          //package level part.
674
GroupUserPackLevelParticipantQuery gpclpQuery =
675             new GroupUserPackLevelParticipantQuery(dbTrans);
676          gpclpQuery.setQueryUSEROID(groupDO);
677          GroupUserPackLevelParticipantDO[] gpclpDOArray =
678             gpclpQuery.getDOArray();
679          for (int i = 0; i < gpclpDOArray.length; i++) {
680             gpclpDOArray[i].delete();
681             dbTrans.write();
682             this.deletePackLevParticipant(
683                gpclpDOArray[i].getPARTICIPANTOID(),
684                dbTrans);
685             XPDLParticipantPackageDO pckDO =
686                gpclpDOArray[i].getPARTICIPANTOID().getPACKAGEOID();
687             this.deletePackage(pckDO, dbTrans);
688          }
689          if (groupDO != null)
690             this.deleteGroupUser(groupDO, dbTrans);
691
692       } catch (Exception JavaDoc e) {
693          e.printStackTrace();
694          throw new RootException(e);
695       }
696       return retVal;
697    }
698
699    /**
700     * Method getDBTransaction create DODS DBTransaction from ParticipantMappingTransaction.
701     * @param t ParticipantMappingTransaction
702     * @return DBTransaction
703     *
704     */

705    private DBTransaction getDBTransaction(ParticipantMappingTransaction t) throws Exception JavaDoc {
706       try {
707          if (t instanceof DODSParticipantMappingTransaction)
708             return ((DODSParticipantMappingTransaction) t).getDODSTransaction();
709       } catch (Exception JavaDoc e) {
710          throw e;
711       }
712       //error
713
return null;
714    }
715
716    public boolean checkValidity(ParticipantMap pm) {
717       if (pm == null
718          || pm.getPackageId() == null
719          || pm.getPackageId().trim().equals("")
720          || pm.getParticipantId() == null
721          || pm.getParticipantId().trim().equals("")
722          || pm.getUsername() == null
723          || pm.getUsername().trim().equals("")) {
724          return false;
725       } else {
726          return true;
727       }
728    }
729
730    private XPDLParticipantPackageDO checkPackage(ParticipantMappingTransaction trans, ParticipantMap pm)
731       throws RootException {
732
733       try {
734          DBTransaction dbTrans = this.getDBTransaction(trans);
735          //package
736
XPDLParticipantPackageQuery pckgQuery = new XPDLParticipantPackageQuery(dbTrans);
737          XPDLParticipantPackageDO pckgDO = null;
738
739          pckgQuery.setQueryPACKAGE_ID(pm.getPackageId());
740          pckgQuery.requireUniqueInstance();
741          pckgDO = pckgQuery.getNextDO();
742          if (pckgDO == null) {
743             //insert new package
744
pckgDO = XPDLParticipantPackageDO.createVirgin(dbTrans);
745             pckgDO.setPACKAGE_ID(pm.getPackageId());
746             pckgDO.save();
747             dbTrans.write();
748          }
749          return pckgDO;
750       } catch (Exception JavaDoc e) {
751          throw new RootException(e);
752       }
753    }
754
755    private XPDLParticipantProcessDO checkProcess(ParticipantMappingTransaction trans, ParticipantMap pm)
756       throws RootException {
757       try {
758          DBTransaction dbTrans = this.getDBTransaction(trans);
759          //process and package
760
XPDLParticipantProcessQuery procQuery = new XPDLParticipantProcessQuery(dbTrans);
761          XPDLParticipantProcessDO processDO = null;
762          XPDLParticipantPackageQuery pckgQuery = new XPDLParticipantPackageQuery(dbTrans);
763          XPDLParticipantPackageDO pckgDO = null;
764
765          String JavaDoc processID = pm.getProcessDefinitionId();
766          String JavaDoc packageID = pm.getPackageId();
767          if (processID != null) {
768             pckgQuery.setQueryPACKAGE_ID(pm.getPackageId());
769             pckgQuery.requireUniqueInstance();
770             pckgDO = pckgQuery.getNextDO();
771             if (pckgDO == null) {
772                //insert new package
773
pckgDO = XPDLParticipantPackageDO.createVirgin(dbTrans);
774                pckgDO.setPACKAGE_ID(pm.getPackageId());
775                pckgDO.save();
776             }
777
778             procQuery.setQueryPROCESS_ID(processID);
779             procQuery.setQueryPACKAGEOID(pckgDO);
780             procQuery.requireUniqueInstance();
781             processDO = procQuery.getNextDO();
782             if (processDO == null) {
783                //insert new process
784
processDO = XPDLParticipantProcessDO.createVirgin(dbTrans);
785                processDO.setPROCESS_ID(pm.getProcessDefinitionId());
786
787                processDO.setPACKAGEOID(pckgDO);
788                processDO.save();
789                dbTrans.write();
790             }
791          }
792          return processDO;
793       } catch (Exception JavaDoc e) {
794          throw new RootException(e);
795       }
796    }
797
798    private ProcLevelParticipantDO checkProcLevelParticipant(
799       ParticipantMappingTransaction trans,
800       ParticipantMap pm)
801       throws RootException {
802       try {
803          DBTransaction dbTrans = this.getDBTransaction(trans);
804          //participants
805
ProcLevelParticipantQuery procLevPartQuery =
806             new ProcLevelParticipantQuery(dbTrans);
807          ProcLevelParticipantDO procLevPartDO = null;
808          XPDLParticipantProcessDO procDO = this.checkProcess(trans, pm);
809
810          procLevPartQuery.setQueryPARTICIPANT_ID(pm.getParticipantId());
811          procLevPartQuery.setQueryPROCESSOID(procDO);
812          procLevPartQuery.requireUniqueInstance();
813          procLevPartDO = procLevPartQuery.getNextDO();
814          if (procLevPartDO == null) {
815             procLevPartDO = ProcLevelParticipantDO.createVirgin(dbTrans);
816             procLevPartDO.setPARTICIPANT_ID(pm.getParticipantId());
817             procLevPartDO.setPROCESSOID(procDO);
818             procLevPartDO.save();
819             dbTrans.write();
820          }
821          return procLevPartDO;
822       } catch (Exception JavaDoc e) {
823          throw new RootException(e);
824       }
825    }
826
827    private PackLevelParticipantDO checkPackLevelParticipant(
828       ParticipantMappingTransaction trans,
829       ParticipantMap pm)
830       throws RootException {
831       try {
832          DBTransaction dbTrans = this.getDBTransaction(trans);
833          //participants
834
PackLevelParticipantQuery packLevPartQuery =
835             new PackLevelParticipantQuery(dbTrans);
836          PackLevelParticipantDO packLevPartDO = null;
837          XPDLParticipantPackageDO packDO = this.checkPackage(trans, pm);
838
839          packLevPartQuery.setQueryPARTICIPANT_ID(pm.getParticipantId());
840          packLevPartQuery.setQueryPACKAGEOID(packDO);
841          packLevPartQuery.requireUniqueInstance();
842          packLevPartDO = packLevPartQuery.getNextDO();
843          if (packLevPartDO == null) {
844             packLevPartDO = PackLevelParticipantDO.createVirgin(dbTrans);
845             packLevPartDO.setPARTICIPANT_ID(pm.getParticipantId());
846             packLevPartDO.setPACKAGEOID(packDO);
847             packLevPartDO.save();
848             dbTrans.write();
849          }
850          return packLevPartDO;
851       } catch (Exception JavaDoc e) {
852          throw new RootException(e);
853       }
854    }
855
856    private NormalUserDO checkUsers(
857       ParticipantMappingTransaction trans,
858       ParticipantMap pm)
859       throws RootException {
860       try {
861          DBTransaction dbTrans = this.getDBTransaction(trans);
862          //participants
863
NormalUserQuery userQuery = new NormalUserQuery(dbTrans);
864          NormalUserDO userDO = null;
865
866          userQuery.setQueryUSERNAME(pm.getUsername());
867          userQuery.requireUniqueInstance();
868          userDO = userQuery.getNextDO();
869          if (userDO == null) {
870             userDO = NormalUserDO.createVirgin(dbTrans);
871             userDO.setUSERNAME(pm.getUsername());
872             userDO.save();
873             dbTrans.write();
874          }
875          return userDO;
876       } catch (Exception JavaDoc e) {
877          throw new RootException(e);
878       }
879    }
880
881    private GroupUserDO checkGroups(
882       ParticipantMappingTransaction trans,
883       ParticipantMap pm)
884       throws RootException {
885       try {
886          DBTransaction dbTrans = this.getDBTransaction(trans);
887
888          GroupUserQuery groupQuery = new GroupUserQuery(dbTrans);
889          GroupUserDO groupDO = null;
890
891          groupQuery.setQueryUSERNAME(pm.getUsername());
892          groupQuery.requireUniqueInstance();
893          groupDO = groupQuery.getNextDO();
894          if (groupDO == null) {
895             groupDO = GroupUserDO.createVirgin(dbTrans);
896             groupDO.setUSERNAME(pm.getUsername());
897             groupDO.save();
898             dbTrans.write();
899          }
900          return groupDO;
901       } catch (Exception JavaDoc e) {
902          throw new RootException(e);
903       }
904    }
905
906    private void deleteProcLevParticipant(
907       ProcLevelParticipantDO plpDO,
908       DBTransaction dbTrans)
909       throws RootException {
910       try {
911          //proc level participant
912
if( plpDO == null )
913             return;
914          GroupUserProcLevelParticipantQuery gulQuery =
915             new GroupUserProcLevelParticipantQuery(dbTrans);
916          gulQuery.setQueryPARTICIPANTOID(plpDO);
917
918          UserProcLevelParticipantQuery ulQuery =
919             new UserProcLevelParticipantQuery(dbTrans);
920          ulQuery.setQueryPARTICIPANTOID(plpDO);
921
922          if (gulQuery.getDOArray().length == 0
923             && ulQuery.getDOArray().length == 0)
924             plpDO.delete();
925          dbTrans.write();
926       } catch (Exception JavaDoc e) {
927          throw new RootException(e);
928       }
929    }
930
931    private void deletePackLevParticipant(
932       PackLevelParticipantDO plpDO,
933       DBTransaction dbTrans)
934       throws RootException {
935       try {
936          //pack level participant
937
if( plpDO == null )
938             return;
939          GroupUserPackLevelParticipantQuery gulQuery =
940             new GroupUserPackLevelParticipantQuery(dbTrans);
941          gulQuery.setQueryPARTICIPANTOID(plpDO);
942          UserPackLevelParticipantQuery ulQuery =
943             new UserPackLevelParticipantQuery(dbTrans);
944          ulQuery.setQueryPARTICIPANTOID(plpDO);
945          UserPackLevelParticipantDO[] ulDOArr = ulQuery.getDOArray();
946          if (gulQuery.getDOArray().length == 0 && ulDOArr.length == 0)
947             plpDO.delete();
948          dbTrans.write();
949       } catch (Exception JavaDoc e) {
950          throw new RootException(e);
951       }
952    }
953
954    private void deleteNormalUser(NormalUserDO userDO, DBTransaction dbTrans)
955       throws RootException {
956       try {
957          if( userDO == null )
958             return;
959          UserProcLevelParticipantQuery uprlQuery =
960             new UserProcLevelParticipantQuery(dbTrans);
961          uprlQuery.setQueryUSEROID(userDO);
962          UserPackLevelParticipantQuery upclQuery =
963             new UserPackLevelParticipantQuery(dbTrans);
964          upclQuery.setQueryUSEROID(userDO);
965          if (uprlQuery.getDOArray().length == 0
966             && upclQuery.getDOArray().length == 0) {
967             userDO.delete();
968          }
969          dbTrans.write();
970       } catch (Exception JavaDoc e) {
971          throw new RootException(e);
972       }
973    }
974
975    private void deleteGroupUser(GroupUserDO userDO, DBTransaction dbTrans)
976       throws RootException {
977       try {
978          if( userDO == null )
979             return;
980          GroupUserProcLevelParticipantQuery uprlQuery =
981             new GroupUserProcLevelParticipantQuery(dbTrans);
982          uprlQuery.setQueryUSEROID(userDO);
983          GroupUserPackLevelParticipantQuery upclQuery =
984             new GroupUserPackLevelParticipantQuery(dbTrans);
985          upclQuery.setQueryUSEROID(userDO);
986          if (uprlQuery.getDOArray().length == 0
987             && upclQuery.getDOArray().length == 0) {
988             userDO.delete();
989          }
990          dbTrans.write();
991       } catch (Exception JavaDoc e) {
992          throw new RootException(e);
993       }
994    }
995
996    private void deleteProcess(XPDLParticipantProcessDO procDO, DBTransaction dbTrans)
997       throws RootException {
998       try {
999          //process
1000
if( procDO == null )
1001            return;
1002         ProcLevelParticipantQuery plpQuery =
1003            new ProcLevelParticipantQuery(dbTrans);
1004         plpQuery.setQueryPROCESSOID(procDO);
1005         ProcLevelParticipantDO[] plpDOArr = plpQuery.getDOArray();
1006         if (plpDOArr.length == 0)
1007            procDO.delete();
1008         dbTrans.write();
1009      } catch (Exception JavaDoc e) {
1010         throw new RootException(e);
1011      }
1012   }
1013
1014   private void deletePackage(XPDLParticipantPackageDO pckDO, DBTransaction dbTrans)
1015      throws RootException {
1016      try {
1017         //package
1018
if( pckDO == null )
1019            return;
1020         XPDLParticipantProcessQuery pQuery = new XPDLParticipantProcessQuery(dbTrans);
1021         pQuery.setQueryPACKAGEOID(pckDO);
1022         PackLevelParticipantQuery pcLQuery =
1023            new PackLevelParticipantQuery(dbTrans);
1024         pcLQuery.setQueryPACKAGEOID(pckDO);
1025         if (pQuery.getDOArray().length == 0
1026            && pcLQuery.getDOArray().length == 0)
1027            pckDO.delete();
1028         dbTrans.write();
1029      } catch (Exception JavaDoc e) {
1030         throw new RootException(e);
1031      }
1032   }
1033   private void deleteGroupProcLevelPart(
1034      ParticipantMap pm,
1035      DBTransaction dbTrans)
1036      throws RootException {
1037      try {
1038         String JavaDoc username = pm.getUsername();
1039         String JavaDoc packageId = pm.getPackageId();
1040         String JavaDoc processId = pm.getProcessDefinitionId();
1041         String JavaDoc participantId = pm.getParticipantId();
1042
1043         GroupUserQuery gQuery = null;
1044         GroupUserDO gDO = null;
1045         if (username != null && !username.trim().equals("")) {
1046            gQuery = new GroupUserQuery(dbTrans);
1047            gQuery.setQueryUSERNAME(username);
1048            gQuery.requireUniqueInstance();
1049            gDO = gQuery.getNextDO();
1050         }
1051
1052         XPDLParticipantPackageQuery pckQuery = new XPDLParticipantPackageQuery(dbTrans);
1053         pckQuery.setQueryPACKAGE_ID(packageId);
1054         pckQuery.requireUniqueInstance();
1055         XPDLParticipantPackageDO pckDO = pckQuery.getNextDO();
1056
1057         XPDLParticipantProcessQuery pQuery = new XPDLParticipantProcessQuery(dbTrans);
1058         pQuery.setQueryPROCESS_ID(processId);
1059         pQuery.setQueryPACKAGEOID(pckDO);
1060         pQuery.requireUniqueInstance();
1061         XPDLParticipantProcessDO procDO = pQuery.getNextDO();
1062
1063         ProcLevelParticipantQuery plpQuery =
1064            new ProcLevelParticipantQuery(dbTrans);
1065         plpQuery.setQueryPARTICIPANT_ID(participantId);
1066         plpQuery.setQueryPROCESSOID(procDO);
1067         plpQuery.requireUniqueInstance();
1068         ProcLevelParticipantDO plpDO = plpQuery.getNextDO();
1069
1070         GroupUserProcLevelParticipantQuery gulQuery =
1071            new GroupUserProcLevelParticipantQuery(dbTrans);
1072         if (gDO != null)
1073            gulQuery.setQueryUSEROID(gDO);
1074         gulQuery.setQueryPARTICIPANTOID(plpDO);
1075         GroupUserProcLevelParticipantDO[] gulDOArr = gulQuery.getDOArray();
1076         for (int i = 0; i < gulDOArr.length; i++) {
1077            gulDOArr[i].delete();
1078         }
1079         dbTrans.write();
1080         //delete unnecessairly data
1081
//proc level participant
1082
this.deleteProcLevParticipant(plpDO, dbTrans);
1083         //process
1084
this.deleteProcess(procDO, dbTrans);
1085         //package
1086
this.deletePackage(pckDO, dbTrans);
1087         //group user
1088
if (gDO != null)
1089            this.deleteGroupUser(gDO, dbTrans);
1090      } catch (Exception JavaDoc e) {
1091         throw new RootException(e);
1092      }
1093   }
1094
1095   private void deleteNormalProcLevelPart(
1096      ParticipantMap pm,
1097      DBTransaction dbTrans)
1098      throws RootException {
1099      try {
1100         String JavaDoc username = pm.getUsername();
1101         String JavaDoc packageId = pm.getPackageId();
1102         String JavaDoc processId = pm.getProcessDefinitionId();
1103         String JavaDoc participantId = pm.getParticipantId();
1104
1105         NormalUserQuery gQuery = null;
1106         NormalUserDO gDO = null;
1107         if (username != null && !username.trim().equals("")) {
1108            gQuery = new NormalUserQuery(dbTrans);
1109            gQuery.setQueryUSERNAME(username);
1110            gQuery.requireUniqueInstance();
1111            gDO = gQuery.getNextDO();
1112         }
1113
1114         XPDLParticipantPackageQuery pckQuery = new XPDLParticipantPackageQuery(dbTrans);
1115         pckQuery.setQueryPACKAGE_ID(packageId);
1116         pckQuery.requireUniqueInstance();
1117         XPDLParticipantPackageDO pckDO = pckQuery.getNextDO();
1118
1119         XPDLParticipantProcessQuery pQuery = new XPDLParticipantProcessQuery(dbTrans);
1120         pQuery.setQueryPROCESS_ID(processId);
1121         pQuery.setQueryPACKAGEOID(pckDO);
1122         pQuery.requireUniqueInstance();
1123         XPDLParticipantProcessDO procDO = pQuery.getNextDO();
1124
1125         ProcLevelParticipantQuery plpQuery =
1126            new ProcLevelParticipantQuery(dbTrans);
1127         plpQuery.setQueryPARTICIPANT_ID(participantId);
1128         plpQuery.setQueryPROCESSOID(procDO);
1129         plpQuery.requireUniqueInstance();
1130         ProcLevelParticipantDO plpDO = plpQuery.getNextDO();
1131
1132         UserProcLevelParticipantQuery gulQuery =
1133            new UserProcLevelParticipantQuery(dbTrans);
1134         if (gDO != null)
1135            gulQuery.setQueryUSEROID(gDO);
1136         gulQuery.setQueryPARTICIPANTOID(plpDO);
1137         UserProcLevelParticipantDO[] gulDOArr = gulQuery.getDOArray();
1138         for (int i = 0; i < gulDOArr.length; i++) {
1139            gulDOArr[i].delete();
1140         }
1141         dbTrans.write();
1142         //delete unnecessairly data
1143
//proc level participant
1144
this.deleteProcLevParticipant(plpDO, dbTrans);
1145         //process
1146
this.deleteProcess(procDO, dbTrans);
1147         //package
1148
this.deletePackage(pckDO, dbTrans);
1149         //single user
1150
if (gDO != null)
1151            this.deleteNormalUser(gDO, dbTrans);
1152      } catch (Exception JavaDoc e) {
1153         e.printStackTrace();
1154         throw new RootException(e);
1155      }
1156   }
1157
1158   private void deleteGroupPackLevelPart(
1159      ParticipantMap pm,
1160      DBTransaction dbTrans)
1161      throws RootException {
1162      try {
1163         String JavaDoc username = pm.getUsername();
1164         String JavaDoc packageId = pm.getPackageId();
1165         String JavaDoc participantId = pm.getParticipantId();
1166
1167         GroupUserQuery gQuery = null;
1168         GroupUserDO gDO = null;
1169         if (username != null && !username.trim().equals("")) {
1170            gQuery = new GroupUserQuery(dbTrans);
1171            gQuery.setQueryUSERNAME(username);
1172            gQuery.requireUniqueInstance();
1173            gDO = gQuery.getNextDO();
1174         }
1175
1176         XPDLParticipantPackageQuery pckQuery = new XPDLParticipantPackageQuery(dbTrans);
1177         pckQuery.setQueryPACKAGE_ID(packageId);
1178         pckQuery.requireUniqueInstance();
1179         XPDLParticipantPackageDO pckDO = pckQuery.getNextDO();
1180
1181         PackLevelParticipantQuery plpQuery =
1182            new PackLevelParticipantQuery(dbTrans);
1183         plpQuery.setQueryPARTICIPANT_ID(participantId);
1184         plpQuery.setQueryPACKAGEOID(pckDO);
1185         plpQuery.requireUniqueInstance();
1186         PackLevelParticipantDO plpDO = plpQuery.getNextDO();
1187
1188         GroupUserPackLevelParticipantQuery gulQuery =
1189            new GroupUserPackLevelParticipantQuery(dbTrans);
1190         if (gDO != null)
1191            gulQuery.setQueryUSEROID(gDO);
1192         gulQuery.setQueryPARTICIPANTOID(plpDO);
1193         GroupUserPackLevelParticipantDO[] gulDOArr = gulQuery.getDOArray();
1194         for (int i = 0; i < gulDOArr.length; i++) {
1195            gulDOArr[i].delete();
1196         }
1197         dbTrans.write();
1198         //delete unnecessairly data
1199
//pack level participant
1200
this.deletePackLevParticipant(plpDO, dbTrans);
1201         //package
1202
this.deletePackage(pckDO, dbTrans);
1203         //group user
1204
if (gDO != null)
1205            this.deleteGroupUser(gDO, dbTrans);
1206      } catch (Exception JavaDoc e) {
1207         e.printStackTrace();
1208         throw new RootException(e);
1209      }
1210   }
1211
1212   private void deleteNormalPackLevelPart(
1213      ParticipantMap pm,
1214      DBTransaction dbTrans)
1215      throws RootException {
1216      try {
1217         String JavaDoc username = pm.getUsername();
1218         String JavaDoc packageId = pm.getPackageId();
1219         String JavaDoc participantId = pm.getParticipantId();
1220
1221         NormalUserQuery gQuery = null;
1222         NormalUserDO gDO = null;
1223         if (username != null && !username.trim().equals("")) {
1224            gQuery = new NormalUserQuery(dbTrans);
1225            gQuery.setQueryUSERNAME(username);
1226            gQuery.requireUniqueInstance();
1227            gDO = gQuery.getNextDO();
1228         }
1229
1230         XPDLParticipantPackageQuery pckQuery = new XPDLParticipantPackageQuery(dbTrans);
1231         pckQuery.setQueryPACKAGE_ID(packageId);
1232         pckQuery.requireUniqueInstance();
1233         XPDLParticipantPackageDO pckDO = pckQuery.getNextDO();
1234
1235         PackLevelParticipantQuery plpQuery =
1236            new PackLevelParticipantQuery(dbTrans);
1237         plpQuery.setQueryPARTICIPANT_ID(participantId);
1238         plpQuery.setQueryPACKAGEOID(pckDO);
1239         plpQuery.requireUniqueInstance();
1240         PackLevelParticipantDO plpDO = plpQuery.getNextDO();
1241
1242         UserPackLevelParticipantQuery gulQuery =
1243            new UserPackLevelParticipantQuery(dbTrans);
1244         if (gDO != null)
1245            gulQuery.setQueryUSEROID(gDO);
1246         gulQuery.setQueryPARTICIPANTOID(plpDO);
1247         UserPackLevelParticipantDO[] gulDOArr = gulQuery.getDOArray();
1248         for (int i = 0; i < gulDOArr.length; i++) {
1249            gulDOArr[i].delete();
1250         }
1251         dbTrans.write();
1252         //delete unnecessairly data
1253
//pack level participant
1254
this.deletePackLevParticipant(plpDO, dbTrans);
1255         //package
1256
this.deletePackage(pckDO, dbTrans);
1257         //single user
1258
if (gDO != null)
1259            this.deleteNormalUser(gDO, dbTrans);
1260      } catch (Exception JavaDoc e) {
1261         throw new RootException(e);
1262      }
1263   }
1264
1265   public ParticipantMappingTransaction getParticipantMappingTransaction() throws TransactionException {
1266          try {
1267            return new DODSParticipantMappingTransaction(DODS.getDatabaseManager().createTransaction());
1268          } catch (Exception JavaDoc ex) {
1269            throw new TransactionException(ex);
1270          }
1271   }
1272}
1273
Popular Tags