KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > sessions > CommitManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.sessions;
23
24 import java.util.*;
25 import oracle.toplink.essentials.mappings.*;
26 import oracle.toplink.essentials.internal.helper.*;
27 import oracle.toplink.essentials.queryframework.*;
28 import oracle.toplink.essentials.exceptions.*;
29 import oracle.toplink.essentials.internal.localization.*;
30 import oracle.toplink.essentials.descriptors.ClassDescriptor;
31
32 /**
33  * This class maintains a commit stack and resolves circular references.
34  */

35 public class CommitManager {
36     protected Vector commitOrder;
37
38     /** Changed the folowing line to work like mergemanager. The commitManager
39      * will now track what has been processed as apposed to removing from the list
40      * objects that have been processed. This must be done to allow for customers
41      * modifying the changesets in events
42      */

43     protected IdentityHashtable processedCommits;
44     protected IdentityHashtable pendingCommits;
45     protected IdentityHashtable preModifyCommits;
46     protected IdentityHashtable postModifyCommits;
47     protected IdentityHashtable completedCommits;
48     protected IdentityHashtable shallowCommits;
49     protected AbstractSession session;
50     protected boolean isActive;
51     protected Hashtable dataModifications;
52     protected Vector objectsToDelete;
53
54     /**
55      * Create the commit manager on the session.
56      * It must be initialized later on after the descriptors have been added.
57      */

58     public CommitManager(AbstractSession session) {
59         this.session = session;
60         this.commitOrder = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
61         this.isActive = false;
62
63         // PERF - move to lazy initialization (3286091)
64
//this.processedCommits = new IdentityHashtable(20);
65
//this.pendingCommits = new IdentityHashtable(20);
66
//this.preModifyCommits = new IdentityHashtable(20);
67
//this.postModifyCommits = new IdentityHashtable(20);
68
//this.completedCommits = new IdentityHashtable(20);
69
//this.shallowCommits = new IdentityHashtable(20);
70
}
71
72     /**
73      * Add the data query to be performed at the end of the commit.
74      * This is done to decrease dependencies and avoid deadlock.
75      */

76     public void addDataModificationEvent(DatabaseMapping mapping, Object JavaDoc[] event) {
77         // For lack of inner class the array is being called an event.
78
if (!getDataModifications().containsKey(mapping)) {
79             getDataModifications().put(mapping, new Vector());
80         }
81
82         ((Vector)getDataModifications().get(mapping)).addElement(event);
83     }
84
85     /**
86      * Deletion are cached until the end.
87      */

88     public void addObjectToDelete(Object JavaDoc objectToDelete) {
89         getObjectsToDelete().addElement(objectToDelete);
90     }
91
92     /**
93      * add the commit of the object to the processed list.
94      */

95     protected void addProcessedCommit(Object JavaDoc domainObject) {
96         getProcessedCommits().put(domainObject, domainObject);
97     }
98
99     /**
100      * Commit all of the objects as a single transaction.
101      * This should commit the object in the correct order to maintain referencial integrity.
102      */

103     public void commitAllObjects(IdentityHashtable domainObjects) throws RuntimeException JavaDoc, DatabaseException, OptimisticLockException {
104         reinitialize();
105         setPendingCommits(domainObjects);
106
107         setIsActive(true);
108         getSession().beginTransaction();
109         try {
110             // The commit order is all of the classes ordered by dependencies, this is done for dealock avoidance.
111
for (Enumeration classesEnum = getCommitOrder().elements();
112                      classesEnum.hasMoreElements();) {
113                 Class JavaDoc theClass = (Class JavaDoc)classesEnum.nextElement();
114
115                 for (Enumeration pendingEnum = getPendingCommits().elements();
116                          pendingEnum.hasMoreElements();) {
117                     Object JavaDoc objectToWrite = pendingEnum.nextElement();
118                     if (objectToWrite.getClass() == theClass) {
119                         removePendingCommit(objectToWrite);// I think removing while enumerating is ok.
120

121                         WriteObjectQuery commitQuery = new WriteObjectQuery();
122                         commitQuery.setObject(objectToWrite);
123                         if (getSession().isUnitOfWork()) {
124                             commitQuery.cascadeOnlyDependentParts();
125                         } else {
126                             commitQuery.cascadeAllParts();// Used in write all objects in session.
127
}
128                         getSession().executeQuery(commitQuery);
129                     }
130                 }
131             }
132
133             for (Enumeration mappingsEnum = getDataModifications().keys(), mappingEventsEnum = getDataModifications().elements();
134                      mappingEventsEnum.hasMoreElements();) {
135                 Vector events = (Vector)mappingEventsEnum.nextElement();
136                 DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement();
137                 for (Enumeration eventsEnum = events.elements(); eventsEnum.hasMoreElements();) {
138                     Object JavaDoc[] event = (Object JavaDoc[])eventsEnum.nextElement();
139                     mapping.performDataModificationEvent(event, getSession());
140                 }
141             }
142
143             Vector objects = getObjectsToDelete();
144             reinitialize();
145             for (Enumeration objectsToDeleteEnum = objects.elements();
146                      objectsToDeleteEnum.hasMoreElements();) {
147                 getSession().deleteObject(objectsToDeleteEnum.nextElement());
148             }
149         } catch (RuntimeException JavaDoc exception) {
150             getSession().rollbackTransaction();
151             throw exception;
152         } finally {
153             reinitialize();
154             setIsActive(false);
155         }
156
157         getSession().commitTransaction();
158     }
159
160     /**
161      * Commit all of the objects as a single transaction.
162      * This should commit the object in the correct order to maintain referencial integrity.
163      */

164     public void commitAllObjectsWithChangeSet(UnitOfWorkChangeSet uowChangeSet) throws RuntimeException JavaDoc, DatabaseException, OptimisticLockException {
165         reinitialize();
166         setIsActive(true);
167         getSession().beginTransaction();
168         try {
169             // PERF: if the number of classes in the project is large this loop can be a perf issue.
170
// If only one class types changed, then avoid loop.
171
if ((uowChangeSet.getObjectChanges().size() + uowChangeSet.getNewObjectChangeSets().size()) <= 1) {
172                 Enumeration classes = uowChangeSet.getNewObjectChangeSets().keys();
173                 if (classes.hasMoreElements()) {
174                     Class JavaDoc theClass = (Class JavaDoc)classes.nextElement();
175                     commitNewObjectsForClassWithChangeSet(uowChangeSet, theClass);
176                 }
177                 Enumeration classNames = uowChangeSet.getObjectChanges().keys();
178                 if (classNames.hasMoreElements()) {
179                     String JavaDoc className = (String JavaDoc)classNames.nextElement();
180                     commitChangedObjectsForClassWithChangeSet(uowChangeSet, className);
181                 }
182             } else {
183                 // The commit order is all of the classes ordered by dependencies, this is done for dealock avoidance.
184
for (Enumeration classesEnum = getCommitOrder().elements();
185                          classesEnum.hasMoreElements();) {
186                     Class JavaDoc theClass = (Class JavaDoc)classesEnum.nextElement();
187                     commitAllObjectsForClassWithChangeSet(uowChangeSet, theClass);
188                 }
189             }
190
191             if (hasDataModifications()) {
192                 // Perform all batched up data modifications, done to avoid dependecies.
193
for (Enumeration mappingsEnum = getDataModifications().keys(), mappingEventsEnum = getDataModifications().elements();
194                          mappingEventsEnum.hasMoreElements();) {
195                     Vector events = (Vector)mappingEventsEnum.nextElement();
196                     DatabaseMapping mapping = (DatabaseMapping)mappingsEnum.nextElement();
197                     for (Enumeration eventsEnum = events.elements(); eventsEnum.hasMoreElements();) {
198                         Object JavaDoc[] event = (Object JavaDoc[])eventsEnum.nextElement();
199                         mapping.performDataModificationEvent(event, getSession());
200                     }
201                 }
202             }
203
204             if (hasObjectsToDelete()) {
205                 Vector objects = getObjectsToDelete();
206                 reinitialize();
207                 for (Enumeration objectsToDeleteEnum = objects.elements();
208                          objectsToDeleteEnum.hasMoreElements();) {
209                     getSession().deleteObject(objectsToDeleteEnum.nextElement());
210                 }
211             }
212         } catch (RuntimeException JavaDoc exception) {
213             getSession().rollbackTransaction();
214             throw exception;
215         } finally {
216             reinitialize();
217             setIsActive(false);
218         }
219
220         getSession().commitTransaction();
221     }
222
223     /**
224      * Commit all of the objects of the class type in the change set.
225      * This allows for the order of the classes to be processed optimally.
226      */

227     protected void commitAllObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class JavaDoc theClass) {
228         // Although new objects should be first, there is an issue that new objects get added to non-new after the insert,
229
// so the object would be written twice.
230
commitChangedObjectsForClassWithChangeSet(uowChangeSet, theClass.getName());
231         commitNewObjectsForClassWithChangeSet(uowChangeSet, theClass);
232     }
233
234     /**
235      * Commit all of the objects of the class type in the change set.
236      * This allows for the order of the classes to be processed optimally.
237      */

238     protected void commitNewObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class JavaDoc theClass) {
239         IdentityHashtable newObjectChangesList = (IdentityHashtable)uowChangeSet.getNewObjectChangeSets().get(theClass);
240         if (newObjectChangesList != null) {// may be no changes for that class type.
241
ClassDescriptor descriptor = getSession().getDescriptor(theClass);
242             for (Enumeration pendingEnum = newObjectChangesList.elements();
243                      pendingEnum.hasMoreElements();) {
244                 ObjectChangeSet changeSetToWrite = (ObjectChangeSet)pendingEnum.nextElement();
245                 Object JavaDoc objectToWrite = changeSetToWrite.getUnitOfWorkClone();
246                 if ((!getProcessedCommits().containsKey(changeSetToWrite)) && (!getProcessedCommits().containsKey(objectToWrite))) {
247                     addProcessedCommit(changeSetToWrite);
248                     InsertObjectQuery commitQuery = new InsertObjectQuery();
249                     commitQuery.setObjectChangeSet(changeSetToWrite);
250                     commitQuery.setObject(objectToWrite);
251                     commitQuery.cascadeOnlyDependentParts();
252                     // removed checking session type to set cascade level
253
// will always be a unitOfWork so we need to cascade dependent parts
254
getSession().executeQuery(commitQuery);
255                 }
256                 ((UnitOfWorkImpl)getSession()).updateChangeTrackersIfRequired(objectToWrite, changeSetToWrite, (UnitOfWorkImpl)getSession(), descriptor);
257
258                 //after the query has executed lets clear the change detection policies
259
//this is important for write changes and non deferred writes support
260
}
261         }
262     }
263
264     /**
265      * Commit changed of the objects of the class type in the change set.
266      * This allows for the order of the classes to be processed optimally.
267      */

268     protected void commitChangedObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, String JavaDoc className) {
269         Hashtable objectChangesList = (Hashtable)uowChangeSet.getObjectChanges().get(className);
270         if (objectChangesList != null) {// may be no changes for that class type.
271
ClassDescriptor descriptor = null;
272             for (Enumeration pendingEnum = objectChangesList.elements();
273                      pendingEnum.hasMoreElements();) {
274                 ObjectChangeSet changeSetToWrite = (ObjectChangeSet)pendingEnum.nextElement();
275                 if (descriptor == null) {
276                     // Need a class to get descriptor, for some evil reason the keys are class name.
277
descriptor = getSession().getDescriptor(changeSetToWrite.getClassType(getSession()));
278                 }
279                 Object JavaDoc objectToWrite = changeSetToWrite.getUnitOfWorkClone();
280                 if ((!getProcessedCommits().containsKey(changeSetToWrite)) && (!getProcessedCommits().containsKey(objectToWrite))) {
281                     addProcessedCommit(changeSetToWrite);
282                     // Commit and resume on failure can cause a new change set to be in existing, so need to check here.
283
WriteObjectQuery commitQuery = null;
284                     if (changeSetToWrite.isNew()) {
285                         commitQuery = new InsertObjectQuery();
286                     } else {
287                         commitQuery = new UpdateObjectQuery();
288                     }
289                     commitQuery.setObjectChangeSet(changeSetToWrite);
290                     commitQuery.setObject(objectToWrite);
291                     commitQuery.cascadeOnlyDependentParts();
292                     // removed checking session type to set cascade level
293
// will always be a unitOfWork so we need to cascade dependent parts
294
getSession().executeQuery(commitQuery);
295                 }
296                 ((UnitOfWorkImpl)getSession()).updateChangeTrackersIfRequired(objectToWrite, changeSetToWrite, (UnitOfWorkImpl)getSession(), descriptor);
297
298                 // after the query has executed lets clear the change detection policies
299
// this is important for write changes and non deferred writes support
300
}
301         }
302     }
303
304     /**
305      * delete all of the objects as a single transaction.
306      * This should delete the object in the correct order to maintain referencial integrity.
307      */

308     public void deleteAllObjects(Vector objectsForDeletion) throws RuntimeException JavaDoc, DatabaseException, OptimisticLockException {
309         setIsActive(true);
310         getSession().beginTransaction();
311
312         try {
313             for (int index = getCommitOrder().size() - 1; index >= 0; index--) {
314                 Class JavaDoc theClass = (Class JavaDoc)getCommitOrder().elementAt(index);
315
316                 for (Enumeration objectsForDeletionEnum = objectsForDeletion.elements();
317                          objectsForDeletionEnum.hasMoreElements();) {
318                     Object JavaDoc objectToDelete = objectsForDeletionEnum.nextElement();
319                     if (objectToDelete.getClass() == theClass) {
320                         DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
321                         deleteQuery.setObject(objectToDelete);
322                         getSession().executeQuery(deleteQuery);
323                     }
324                 }
325             }
326         } catch (RuntimeException JavaDoc exception) {
327             try {
328                 getSession().rollbackTransaction();
329             } catch (Exception JavaDoc ignore) {
330             }
331             throw exception;
332         } finally {
333             setIsActive(false);
334         }
335
336         getSession().commitTransaction();
337     }
338
339     /**
340      * Return the order in which objects should be commited to the database.
341      * This order is based on ownership in the descriptors and is require for referencial integrity.
342      * The commit order is a vector of vectors,
343      * where the first vector is all root level classes, the second is classes owned by roots and so on.
344      */

345     public Vector getCommitOrder() {
346         return commitOrder;
347     }
348
349     /**
350      * Return any objects that have been written during this commit process.
351      */

352     protected IdentityHashtable getCompletedCommits() {
353         if (completedCommits == null) {
354             // 2612538 - the default size of IdentityHashtable (32) is appropriate
355
completedCommits = new IdentityHashtable();
356         }
357         return completedCommits;
358     }
359
360     protected boolean hasDataModifications() {
361         return ((dataModifications != null) && (!dataModifications.isEmpty()));
362     }
363
364     /**
365      * Used to store data querys to be performed at the end of the commit.
366      * This is done to decrease dependencies and avoid deadlock.
367      */

368     protected Hashtable getDataModifications() {
369         if (dataModifications == null) {
370             dataModifications = new Hashtable(10);
371         }
372         return dataModifications;
373     }
374
375     protected boolean hasObjectsToDelete() {
376         return ((objectsToDelete != null) && (!objectsToDelete.isEmpty()));
377     }
378
379     /**
380      * Deletion are cached until the end.
381      */

382     protected Vector getObjectsToDelete() {
383         if (objectsToDelete == null) {
384             objectsToDelete = new Vector(5);
385         }
386         return objectsToDelete;
387     }
388
389     /**
390      * Return any objects that should be written during this commit process.
391      */

392     protected IdentityHashtable getProcessedCommits() {
393         if (processedCommits == null) {
394             // 2612538 - the default size of IdentityHashtable (32) is appropriate
395
processedCommits = new IdentityHashtable();
396         }
397         return processedCommits;
398     }
399
400     /**
401      * Return any objects that should be written during this commit process.
402      */

403     protected IdentityHashtable getPendingCommits() {
404         if (pendingCommits == null) {
405             // 2612538 - the default size of IdentityHashtable (32) is appropriate
406
pendingCommits = new IdentityHashtable();
407         }
408         return pendingCommits;
409     }
410
411     /**
412      * Return any objects that should be written during post modify commit process.
413      * These objects should be order by their ownership constraints to maintain referencial integrity.
414      */

415     protected IdentityHashtable getPostModifyCommits() {
416         if (postModifyCommits == null) {
417             // 2612538 - the default size of IdentityHashtable (32) is appropriate
418
postModifyCommits = new IdentityHashtable();
419         }
420         return postModifyCommits;
421     }
422
423     /**
424      * Return any objects that should be written during pre modify commit process.
425      * These objects should be order by their ownership constraints to maintain referencial integrity.
426      */

427     protected IdentityHashtable getPreModifyCommits() {
428         if (preModifyCommits == null) {
429             // 2612538 - the default size of IdentityHashtable (32) is appropriate
430
preModifyCommits = new IdentityHashtable();
431         }
432         return preModifyCommits;
433     }
434
435     /**
436      * Return the session that this is managing commits for.
437      */

438     protected AbstractSession getSession() {
439         return session;
440     }
441
442     /**
443      * Return any objects that have been shallow comitted during this commit process.
444      */

445     protected IdentityHashtable getShallowCommits() {
446         if (shallowCommits == null) {
447             // 2612538 - the default size of IdentityHashtable (32) is appropriate
448
shallowCommits = new IdentityHashtable();
449         }
450         return shallowCommits;
451     }
452
453     /**
454      * Reset the commit order from the session's descriptors.
455      * This uses the constraint dependencies in the descriptor's mappings,
456      * to decide which descriptors are dependent on which other descriptors.
457      * Multiple computations of the commit order should produce the same ordering.
458      * This is done to improve performance on unit of work writes through decreasing the
459      * stack size, and acts as a deadlock avoidance mechansim.
460      */

461     public void initializeCommitOrder() {
462         Vector descriptors = Helper.buildVectorFromMapElements(getSession().getDescriptors());
463
464         // Must ensure uniqueness, some descriptor my be register twice for interfaces.
465
descriptors = Helper.addAllUniqueToVector(new Vector(descriptors.size()), descriptors);
466         Object JavaDoc[] descriptorsArray = new Object JavaDoc[descriptors.size()];
467         for (int index = 0; index < descriptors.size(); index++) {
468             descriptorsArray[index] = descriptors.elementAt(index);
469         }
470         TOPSort.quicksort(descriptorsArray, new DescriptorCompare());
471         descriptors = new Vector(descriptors.size());
472         for (int index = 0; index < descriptorsArray.length; index++) {
473             descriptors.addElement(descriptorsArray[index]);
474         }
475
476         CommitOrderCalculator calculator = new CommitOrderCalculator(getSession());
477         calculator.addNodes(descriptors);
478         calculator.calculateMappingDependencies();
479         calculator.orderCommits();
480         descriptors = calculator.getOrderedDescriptors();
481
482         calculator = new CommitOrderCalculator(getSession());
483         calculator.addNodes(descriptors);
484         calculator.calculateSpecifiedDependencies();
485         calculator.orderCommits();
486
487         setCommitOrder(calculator.getOrderedClasses());
488     }
489
490     /**
491      * Return if the commit manager is active.
492      */

493     public boolean isActive() {
494         return isActive;
495     }
496
497     /**
498      * Return if the object has been commited.
499      * This should be called by any query that is writing an object,
500      * if true the query should not write the object.
501      */

502     public boolean isCommitCompleted(Object JavaDoc domainObject) {
503         return getCompletedCommits().containsKey(domainObject);
504     }
505
506     /**
507      * Return if the object is being in progress of being post modify commit.
508      * This should be called by any query that is writing an object,
509      * if true the query must force a shallow insert of the object if it is new.
510      */

511     public boolean isCommitInPostModify(Object JavaDoc domainObject) {
512         return getPostModifyCommits().containsKey(domainObject);
513     }
514
515     /**
516      * Return if the object is being in progress of being pre modify commit.
517      * This should be called by any query that is writing an object,
518      * if true the query must force a shallow insert of the object if it is new.
519      */

520     public boolean isCommitInPreModify(Object JavaDoc domainObject) {
521         return getPreModifyCommits().containsKey(domainObject);
522     }
523
524     /**
525      * Return if the object is shallow committed.
526      * This is required to resolve bidirection references.
527      */

528     public boolean isShallowCommitted(Object JavaDoc domainObject) {
529         return getShallowCommits().containsKey(domainObject);
530     }
531
532     /**
533      * Mark the commit of the object as being fully completed.
534      * This should be called by any query that has finished writing an object.
535      */

536     public void markCommitCompleted(Object JavaDoc domainObject) {
537         getPreModifyCommits().remove(domainObject);
538         getPostModifyCommits().remove(domainObject);
539         // If not in a unit of work commit and the commit of this object is done reset the comitt manager
540
if ((!isActive()) && getPostModifyCommits().isEmpty() && getPreModifyCommits().isEmpty()) {
541             reinitialize();
542             return;
543         }
544         getCompletedCommits().put(domainObject, domainObject);// Treat as set.
545
}
546
547     /**
548      * Add an object as being in progress of being commited.
549      * This should be called by any query that is writing an object.
550      */

551     public void markPostModifyCommitInProgress(Object JavaDoc domainObject) {
552         getPreModifyCommits().remove(domainObject);
553         getPostModifyCommits().put(domainObject, domainObject);// Use as set.
554
}
555
556     /**
557      * Add an object as being in progress of being commited.
558      * This should be called by any query that is writing an object.
559      */

560     public void markPreModifyCommitInProgress(Object JavaDoc domainObject) {
561         removePendingCommit(domainObject);
562         addProcessedCommit(domainObject);
563         getPreModifyCommits().put(domainObject, domainObject);// Use as set.
564
}
565
566     /**
567      * Mark the object as shallow committed.
568      * This is required to resolve bidirection references.
569      */

570     public void markShallowCommit(Object JavaDoc domainObject) {
571         getShallowCommits().put(domainObject, domainObject);// Use as set.
572
}
573
574     /**
575      * Reset the commits.
576      * This must be done before a new commit process is begun.
577      */

578     public void reinitialize() {
579         setPendingCommits(null);
580         setProcessedCommits(null);
581         setPreModifyCommits(null);
582         setPostModifyCommits(null);
583         setCompletedCommits(null);
584         setShallowCommits(null);
585         setObjectsToDelete(null);
586         setDataModifications(null);
587     }
588
589     /**
590      * Remove the commit of the object from pending.
591      */

592     protected void removePendingCommit(Object JavaDoc domainObject) {
593         getPendingCommits().remove(domainObject);
594     }
595
596     /**
597      * Set the order in which objects should be commited to the database.
598      * This order is based on ownership in the descriptors and is require for referencial integrity.
599      * The commit order is a vector of vectors,
600      * where the first vector is all root level classes, the second is classes owned by roots and so on.
601      */

602     public void setCommitOrder(Vector commitOrder) {
603         this.commitOrder = commitOrder;
604     }
605
606     /**
607      * Set the objects that have been written during this commit process.
608      */

609     protected void setCompletedCommits(IdentityHashtable completedCommits) {
610         this.completedCommits = completedCommits;
611     }
612
613     /**
614      * Used to store data querys to be performed at the end of the commit.
615      * This is done to decrease dependencies and avoid deadlock.
616      */

617     protected void setDataModifications(Hashtable dataModifications) {
618         this.dataModifications = dataModifications;
619     }
620
621     /**
622      * Set if the commit manager is active.
623      */

624     public void setIsActive(boolean isActive) {
625         this.isActive = isActive;
626     }
627
628     /**
629      * Deletion are cached until the end.
630      */

631     protected void setObjectsToDelete(Vector objectsToDelete) {
632         this.objectsToDelete = objectsToDelete;
633     }
634
635     /**
636      * Set the objects that should be written during this commit process.
637      */

638     protected void setPendingCommits(IdentityHashtable pendingCommits) {
639         this.pendingCommits = pendingCommits;
640     }
641
642     /**
643      * Set the objects that should be written during this commit process.
644      */

645     protected void setProcessedCommits(IdentityHashtable processedCommits) {
646         this.processedCommits = processedCommits;
647     }
648
649     /**
650      * Set any objects that should be written during post modify commit process.
651      * These objects should be order by their ownership constraints to maintain referencial integrity.
652      */

653     protected void setPostModifyCommits(IdentityHashtable postModifyCommits) {
654         this.postModifyCommits = postModifyCommits;
655     }
656
657     /**
658      * Set any objects that should be written during pre modify commit process.
659      * These objects should be order by their ownership constraints to maintain referencial integrity.
660      */

661     protected void setPreModifyCommits(IdentityHashtable preModifyCommits) {
662         this.preModifyCommits = preModifyCommits;
663     }
664
665     /**
666      * Set the session that this is managing commits for.
667      */

668     protected void setSession(AbstractSession session) {
669         this.session = session;
670     }
671
672     /**
673      * Set any objects that have been shallow comitted during this commit process.
674      */

675     protected void setShallowCommits(IdentityHashtable shallowCommits) {
676         this.shallowCommits = shallowCommits;
677     }
678
679     /**
680      * Print the in progress depth.
681      */

682     public String JavaDoc toString() {
683         int size = 0;
684         if (preModifyCommits != null) {
685             size += getPreModifyCommits().size();
686         }
687         if (postModifyCommits != null) {
688             size += getPostModifyCommits().size();
689         }
690         Object JavaDoc[] args = { new Integer JavaDoc(size) };
691         return Helper.getShortClassName(getClass()) + ToStringLocalization.buildMessage("commit_depth", args);
692     }
693 }
694
Popular Tags