KickJava   Java API By Example, From Geeks To Geeks.

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


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, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.sessions;
23
24 import java.util.*;
25
26 /**
27  * <p>
28  * <b>Purpose</b>: This class holds the record of the changes made to a collection attribute of
29  * an object.
30  * <p>
31  * <b>Description</b>: Collections must be compared to each other and added and removed objects must
32  * be recorded seperately.
33  *
34  * NOTE: This class and its sub class are currently not used within TopLink and should be removed.
35  */

36 public class OrderedCollectionChangeRecord extends ChangeRecord implements oracle.toplink.essentials.changesets.OrderedCollectionChangeRecord {
37     protected Hashtable addObjectList;
38     protected Vector addIndexes;
39     protected int startIndexOfRemove;
40
41     /**
42      * This constructor returns a changeRecord representing the DirectCollection mapping
43      * @param owner prototype.changeset.ObjectChangeSet that ObjectChangeSet that uses this record
44      */

45     public OrderedCollectionChangeRecord(ObjectChangeSet owner) {
46         this.owner = owner;
47         this.startIndexOfRemove = Integer.MAX_VALUE;
48     }
49
50     /**
51      * This method takes a hastable of primitive objects and adds them to the add list.
52      */

53     public void addAdditionChange(Hashtable additions, Vector indexes, UnitOfWorkChangeSet changes, AbstractSession session) {
54         for (Enumeration enumtr = additions.keys(); enumtr.hasMoreElements();) {
55             Object JavaDoc index = enumtr.nextElement();
56             Object JavaDoc object = additions.get(index);
57             Object JavaDoc changeSet = session.getDescriptor(object.getClass()).getObjectBuilder().createObjectChangeSet(object, changes, session);
58             additions.put(index, changeSet);
59         }
60
61         this.addObjectList = additions;
62         this.addIndexes = indexes;
63     }
64
65     /**
66      * This method returns the collection of indexes in which changes were made to this collection.
67      */

68     public Vector getAddIndexes() {
69         if (this.addIndexes == null) {
70             this.addIndexes = new Vector(1);
71         }
72         return addIndexes;
73     }
74
75     /**
76      * This method returns the collection of ChangeSets that were added to the collection.
77      */

78     public Hashtable getAddObjectList() {
79         if (this.addObjectList == null) {
80             this.addObjectList = new Hashtable(1);
81         }
82         return addObjectList;
83     }
84
85     /**
86      * This method returns the index from where objects must be removed from the collection
87      */

88     public int getStartRemoveIndex() {
89         return this.startIndexOfRemove;
90     }
91
92     /**
93      * INTERNAL:
94      * This method will be used to merge one record into another
95      */

96     public void mergeRecord(ChangeRecord mergeFromRecord, UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet) {
97         // NOTE: if this class is ever used then this method will need to be implemented
98
}
99
100     /**
101      * This method sets the index from where objects must be removed from the collection
102      */

103     public void setStartRemoveIndex(int startRemoveIndex) {
104         this.startIndexOfRemove = startRemoveIndex;
105     }
106
107     /**
108      * INTERNAL:
109      * This method will be used to update the objectsChangeSets references
110      */

111     public void updateReferences(UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet) {
112         //if this class is ever used this method will need to be implemented
113
}
114 }
115
Popular Tags