KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This change record records the changes for AggregateCollectionMapping.
28  */

29 public class AggregateCollectionChangeRecord extends ChangeRecord implements oracle.toplink.essentials.changesets.AggregateCollectionChangeRecord {
30     protected Vector changedValues;
31
32     /**
33      * This default constructor referenced internally by SDK XML project
34      */

35     public AggregateCollectionChangeRecord() {
36         super();
37     }
38
39     /**
40      * This constructor returns an ChangeRecord representing an AggregateMapping.
41      * @param owner oracle.toplink.essentials.internal.sessions.ObjectChangeSet represents the Object Change Set that uses this record
42      */

43     public AggregateCollectionChangeRecord(ObjectChangeSet owner) {
44         super();
45         this.owner = owner;
46     }
47
48     /**
49      * ADVANCED:
50      * Return the values representing the changed AggregateCollection.
51      * @return prototype.changeset.ObjectChanges
52      */

53     public Vector getChangedValues() {
54         if (changedValues == null) {
55             changedValues = new Vector(2);
56         }
57         return changedValues;
58     }
59
60     /**
61      * INTERNAL:
62      * This method will be used to merge one record into another
63      */

64     public void mergeRecord(ChangeRecord mergeFromRecord, UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet) {
65         this.setChangedValues(((AggregateCollectionChangeRecord)mergeFromRecord).getChangedValues());
66
67         //an aggregate collection changerecord contains a copy of the entire collection, not just the changes
68
//so there in no need to merge it, just replace it.
69
for (int index = 0; index < this.getChangedValues().size(); ++index) {
70             ((ObjectChangeSet)this.getChangedValues().get(index)).updateReferences(mergeToChangeSet, mergeFromChangeSet);
71             ;
72         }
73     }
74
75     /**
76      * INTERNAL:
77      * Set the changed values
78      * @param newValue prototype.changeset.ObjectChanges
79      */

80     public void setChangedValues(Vector newValues) {
81         changedValues = newValues;
82     }
83
84     /**
85      * INTERNAL:
86      * This method will be used to update the objectsChangeSets references
87      * If this is an aggregate change set then there is no need to update the
88      * reference as the ChangeSet has no identity outside of this record
89      * Check to see if it exists here already to prevent us from creating a little
90      * extra garbage.
91      */

92     public void updateReferences(UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet) {
93         for (int index = 0; index < this.getChangedValues().size(); ++index) {
94             ObjectChangeSet mergedChangeSet = (ObjectChangeSet)this.getChangedValues().get(index);
95             Object JavaDoc localObject = mergeToChangeSet.getUOWCloneForObjectChangeSet(mergedChangeSet);
96             if (localObject == null) {
97                 mergeToChangeSet.addObjectChangeSetForIdentity(mergedChangeSet, mergeFromChangeSet.getUOWCloneForObjectChangeSet(mergedChangeSet));
98             }
99         }
100     }
101 }
102
Popular Tags