KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > tx > ServerTransactionImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.objectserver.tx;
6
7 import com.tc.net.protocol.tcm.ChannelID;
8 import com.tc.object.dmi.DmiDescriptor;
9 import com.tc.object.dna.api.DNA;
10 import com.tc.object.dna.impl.ObjectStringSerializer;
11 import com.tc.object.lockmanager.api.LockID;
12 import com.tc.object.tx.ServerTransactionID;
13 import com.tc.object.tx.TransactionID;
14 import com.tc.object.tx.TxnBatchID;
15 import com.tc.object.tx.TxnType;
16 import com.tc.util.SequenceID;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 /**
27  * Represents an atomic change to the states of objects on the server
28  *
29  * @author steve
30  */

31 public class ServerTransactionImpl implements ServerTransaction {
32   private final ServerTransactionID serverTxID;
33   private final SequenceID seqID;
34   private final List JavaDoc changes;
35   private final LockID[] lockIDs;
36   private final TransactionID txID;
37   private final Map JavaDoc newRoots;
38   private final ChannelID channelID;
39   private final TxnType transactionType;
40   private final ObjectStringSerializer serializer;
41   private final Collection JavaDoc notifies;
42   private final DmiDescriptor[] dmis;
43   private final Collection JavaDoc objectIDs;
44   private final Set JavaDoc newObjectIDs;
45   private final TxnBatchID batchID;
46   private final boolean passive;
47
48   // for tests
49
public ServerTransactionImpl(TxnBatchID batchID, TransactionID txID, SequenceID sequenceID, LockID[] lockIDs,
50                                ChannelID channelID, List JavaDoc dnas, ObjectStringSerializer serializer, Map JavaDoc newRoots,
51                                TxnType transactionType, Collection JavaDoc notifies, DmiDescriptor[] dmis) {
52
53     this(batchID, txID, sequenceID, lockIDs, channelID, dnas, serializer, newRoots, transactionType, notifies, dmis,
54          false);
55   }
56
57   public ServerTransactionImpl(TxnBatchID batchID, TransactionID txID, SequenceID sequenceID, LockID[] lockIDs,
58                                ChannelID channelID, List JavaDoc dnas, ObjectStringSerializer serializer, Map JavaDoc newRoots,
59                                TxnType transactionType, Collection JavaDoc notifies, DmiDescriptor[] dmis, boolean passive) {
60     this.batchID = batchID;
61     this.txID = txID;
62     this.seqID = sequenceID;
63     this.lockIDs = lockIDs;
64     this.newRoots = newRoots;
65     this.channelID = channelID;
66     this.passive = passive;
67     this.serverTxID = new ServerTransactionID(channelID, txID);
68     this.transactionType = transactionType;
69     this.notifies = notifies;
70     this.dmis = dmis;
71     this.changes = dnas;
72     this.serializer = serializer;
73     List JavaDoc ids = new ArrayList JavaDoc(changes.size());
74     HashSet JavaDoc newIDs = new HashSet JavaDoc(changes.size());
75     for (Iterator JavaDoc i = changes.iterator(); i.hasNext();) {
76       DNA dna = (DNA) i.next();
77       ids.add(dna.getObjectID());
78       if (!dna.isDelta()) {
79         newIDs.add(dna.getObjectID());
80       }
81     }
82     this.objectIDs = ids;
83     this.newObjectIDs = newIDs;
84   }
85
86   public ObjectStringSerializer getSerializer() {
87     return serializer;
88   }
89
90   public LockID[] getLockIDs() {
91     return lockIDs;
92   }
93
94   public ChannelID getChannelID() {
95     return channelID;
96   }
97
98   public TransactionID getTransactionID() {
99     return txID;
100   }
101
102   public SequenceID getClientSequenceID() {
103     return seqID;
104   }
105
106   public List JavaDoc getChanges() {
107     return changes;
108   }
109
110   public Map JavaDoc getNewRoots() {
111     return newRoots;
112   }
113
114   public TxnType getTransactionType() {
115     return transactionType;
116   }
117
118   public Collection JavaDoc getObjectIDs() {
119     return this.objectIDs;
120   }
121
122   public Set JavaDoc getNewObjectIDs() {
123     return this.newObjectIDs;
124   }
125
126   public Collection JavaDoc addNotifiesTo(List JavaDoc list) {
127     list.addAll(notifies);
128     return list;
129   }
130
131   public DmiDescriptor[] getDmiDescriptors() {
132     return dmis;
133   }
134
135   public String JavaDoc toString() {
136     return "ServerTransaction[" + seqID + " , " + txID + "," + channelID + "," + transactionType + "] = { changes = "
137            + changes.size() + ", notifies = " + notifies.size() + ", newRoots = " + newRoots.size() + "}";
138   }
139
140   public ServerTransactionID getServerTransactionID() {
141     return serverTxID;
142   }
143
144   public TxnBatchID getBatchID() {
145     return batchID;
146   }
147
148   public boolean isPassive() {
149     return passive;
150   }
151 }
152
Popular Tags