KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.GlobalXactId
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.sanity.SanityManager;
25
26 import org.apache.derby.iapi.services.io.FormatIdUtil;
27 import org.apache.derby.iapi.services.io.StoredFormatIds;
28 import org.apache.derby.catalog.UUID;
29
30 import org.apache.derby.iapi.store.raw.GlobalTransactionId;
31 import org.apache.derby.iapi.store.access.GlobalXact;
32
33 import org.apache.derby.iapi.util.ByteArray;
34
35 import java.io.ObjectOutput JavaDoc;
36 import java.io.ObjectInput JavaDoc;
37 import java.io.IOException JavaDoc;
38
39 public class GlobalXactId extends GlobalXact implements GlobalTransactionId
40 {
41     /**************************************************************************
42      * Private Fields of the class
43      **************************************************************************
44      */

45
46     /**************************************************************************
47      * Constructors for This class:
48      **************************************************************************
49      */

50     public GlobalXactId(
51                         int format_id,
52                         byte[] global_id,
53                         byte[] branch_id)
54     {
55         this.format_id = format_id;
56         this.global_id = new byte[global_id.length];
57         System.arraycopy(global_id, 0, this.global_id, 0, global_id.length);
58         this.branch_id = new byte[branch_id.length];
59         System.arraycopy(branch_id, 0, this.branch_id, 0, branch_id.length);
60     }
61
62     /**************************************************************************
63      * Public Methods of Formatable interface:
64      **************************************************************************
65      */

66
67     // no-arg constructor, required by Formatable
68
public GlobalXactId()
69     {
70     }
71
72     /**
73         Write this out.
74         @exception IOException error writing to log stream
75     */

76     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
77     {
78         out.writeInt(format_id);
79
80         if (SanityManager.DEBUG)
81         {
82             SanityManager.ASSERT(global_id.length <= 64);
83             SanityManager.ASSERT(global_id != null);
84             SanityManager.ASSERT(branch_id != null);
85         }
86
87         // write length of array followed by the array
88
out.write(global_id.length);
89         if (global_id.length > 0)
90             out.write(global_id);
91
92         // write length of array followed by the array
93
out.write(branch_id.length);
94         if (branch_id.length > 0)
95             out.write(branch_id);
96     }
97
98     /**
99         Read this in
100         @exception IOException error reading from log stream
101         @exception ClassNotFoundException log stream corrupted
102     */

103     public void readExternal(ObjectInput JavaDoc in)
104         throws IOException JavaDoc, ClassNotFoundException JavaDoc
105     {
106         format_id = in.readInt();
107
108         // read global_id in from disk
109
int array_len = in.read();
110
111         if (SanityManager.DEBUG)
112         {
113             SanityManager.ASSERT(array_len >= 0);
114         }
115
116         global_id = new byte[array_len];
117         if (array_len > 0)
118             in.read(global_id);
119
120         // read branch_id in from disk
121
array_len = in.read();
122
123         if (SanityManager.DEBUG)
124         {
125             SanityManager.ASSERT(array_len >= 0);
126         }
127
128         branch_id = new byte[array_len];
129         if (array_len > 0)
130             in.read(branch_id);
131     }
132
133     /**
134         Return my format identifier.
135     */

136     public int getTypeFormatId() {
137         return StoredFormatIds.RAW_STORE_GLOBAL_XACT_ID_NEW;
138     }
139
140     /**************************************************************************
141      * Private/Protected methods of This class:
142      **************************************************************************
143      */

144
145     /**************************************************************************
146      * Public Methods of This class:
147      **************************************************************************
148      */

149     public int getFormat_Id()
150     {
151         return(format_id);
152     }
153
154     public byte[] getGlobalTransactionId()
155     {
156         return(global_id);
157     }
158
159     public byte[] getBranchQualifier()
160     {
161         return(branch_id);
162     }
163 }
164
Popular Tags