KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > xact > BeginXact


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.BeginXact
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.raw.xact;
23
24 import org.apache.derby.iapi.services.io.FormatIdUtil;
25 import org.apache.derby.iapi.services.io.StoredFormatIds;
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.store.raw.Transaction;
29 import org.apache.derby.iapi.store.raw.Loggable;
30 import org.apache.derby.iapi.store.raw.GlobalTransactionId;
31
32 import org.apache.derby.iapi.store.raw.log.LogInstant;
33 import org.apache.derby.iapi.store.raw.xact.RawTransaction;
34
35 import org.apache.derby.iapi.util.ByteArray;
36
37 import java.io.OutputStream JavaDoc;
38 import java.io.InputStream JavaDoc;
39 import java.io.ObjectOutput JavaDoc;
40 import java.io.ObjectInput JavaDoc;
41 import java.io.IOException JavaDoc;
42 import org.apache.derby.iapi.services.io.LimitObjectInput;
43
44 /**
45     This operation indicates the beginning of a transaction.
46     @see Loggable
47 */

48
49 public class BeginXact implements Loggable {
50
51     protected int transactionStatus;
52     protected GlobalTransactionId xactId;
53
54
55     public BeginXact(GlobalTransactionId xid, int s)
56     {
57         xactId = xid;
58         transactionStatus = s;
59     }
60
61     /*
62      * Formatable methods
63      */

64     public BeginXact()
65     { super() ; }
66
67     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
68     {
69         out.writeInt(transactionStatus);
70         out.writeObject(xactId);
71     }
72
73     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
74     {
75         transactionStatus = in.readInt();
76         xactId = (GlobalTransactionId)in.readObject();
77     }
78
79     /**
80         Return my format identifier.
81     */

82     public int getTypeFormatId() {
83         return StoredFormatIds.LOGOP_BEGIN_XACT;
84     }
85
86     /**
87         Loggable methods
88         @see Loggable
89     */

90
91     /**
92         Apply the change indicated by this operation and optional data.
93
94         @param xact the Transaction
95         @param instant the log instant of this operation
96         @param in optional data
97
98     */

99     public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)
100     {
101         RawTransaction rt = (RawTransaction)xact;
102
103         // If we are not doing fake logging for in memory database
104
if (instant != null)
105         {
106             rt.setFirstLogInstant(instant);
107
108             // need to do this here rather than in the transaction object for
109
// recovery.
110
rt.addUpdateTransaction(transactionStatus);
111         }
112     }
113
114     /**
115         the default for prepared log is always null for all the operations
116         that don't have optionalData. If an operation has optional data,
117         the operation need to prepare the optional data for this method.
118
119         BeginXact has no optional data to write out
120
121         @see ObjectOutput
122     */

123     public ByteArray getPreparedLog()
124     {
125         return (ByteArray) null;
126     }
127
128     /**
129         Always redo a BeginXact.
130
131         @param xact The transaction trying to redo this operation
132         @return true if operation needs redoing, false if not.
133     */

134     public boolean needsRedo(Transaction xact)
135     {
136         return true; // always redo this
137
}
138
139
140     /**
141         BeginXact has no resource to release
142     */

143     public void releaseResource(Transaction xact)
144     {}
145
146
147     /**
148         BeginXact is both a FIRST and a RAWSTORE log record
149     */

150     public int group()
151     {
152         int group = Loggable.FIRST | Loggable.RAWSTORE;
153         return group;
154     }
155
156     /**
157       DEBUG: Print self.
158     */

159     public String JavaDoc toString()
160     {
161         if (SanityManager.DEBUG)
162             return "BeginXact " + xactId + " transactionStatus " + Integer.toHexString(transactionStatus);
163         else
164             return null;
165
166     }
167
168     /**
169         BeginXact method
170     */

171     public GlobalTransactionId getGlobalId()
172     {
173         return xactId;
174     }
175
176
177 }
178
179
Popular Tags