1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.raw.xact.GlobalXactId |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.store.raw.xact; |
22 | |
23 | import org.apache.derby.iapi.services.sanity.SanityManager; |
24 | |
25 | import org.apache.derby.iapi.services.io.FormatIdUtil; |
26 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
27 | import org.apache.derby.catalog.UUID; |
28 | |
29 | import org.apache.derby.iapi.store.raw.GlobalTransactionId; |
30 | import org.apache.derby.iapi.store.access.GlobalXact; |
31 | |
32 | import org.apache.derby.iapi.util.ByteArray; |
33 | |
34 | import java.io.ObjectOutput; |
35 | import java.io.ObjectInput; |
36 | import java.io.IOException; |
37 | |
38 | public class GlobalXactId extends GlobalXact implements GlobalTransactionId |
39 | { |
40 | /************************************************************************** |
41 | * Private Fields of the class |
42 | ************************************************************************** |
43 | */ |
44 | |
45 | /************************************************************************** |
46 | * Constructors for This class: |
47 | ************************************************************************** |
48 | */ |
49 | public GlobalXactId( |
50 | int format_id, |
51 | byte[] global_id, |
52 | byte[] branch_id) |
53 | { |
54 | this.format_id = format_id; |
55 | this.global_id = new byte[global_id.length]; |
56 | System.arraycopy(global_id, 0, this.global_id, 0, global_id.length); |
57 | this.branch_id = new byte[branch_id.length]; |
58 | System.arraycopy(branch_id, 0, this.branch_id, 0, branch_id.length); |
59 | } |
60 | |
61 | /************************************************************************** |
62 | * Public Methods of Formatable interface: |
63 | ************************************************************************** |
64 | */ |
65 | |
66 | // no-arg constructor, required by Formatable |
67 | public GlobalXactId() |
68 | { |
69 | } |
70 | |
71 | /** |
72 | Write this out. |
73 | @exception IOException error writing to log stream |
74 | */ |
75 | public void writeExternal(ObjectOutput out) throws IOException |
76 | { |
77 | out.writeInt(format_id); |
78 | |
79 | if (SanityManager.DEBUG) |
80 | { |
81 | SanityManager.ASSERT(global_id.length <= 64); |
82 | SanityManager.ASSERT(global_id != null); |
83 | SanityManager.ASSERT(branch_id != null); |
84 | } |
85 | |
86 | // write length of array followed by the array |
87 | out.write(global_id.length); |
88 | if (global_id.length > 0) |
89 | out.write(global_id); |
90 | |
91 | // write length of array followed by the array |
92 | out.write(branch_id.length); |
93 | if (branch_id.length > 0) |
94 | out.write(branch_id); |
95 | } |
96 | |
97 | /** |
98 | Read this in |
99 | @exception IOException error reading from log stream |
100 | @exception ClassNotFoundException log stream corrupted |
101 | */ |
102 | public void readExternal(ObjectInput in) |
103 | throws IOException, ClassNotFoundException |
104 | { |
105 | format_id = in.readInt(); |
106 | |
107 | // read global_id in from disk |
108 | int array_len = in.read(); |
109 | |
110 | if (SanityManager.DEBUG) |
111 | { |
112 | SanityManager.ASSERT(array_len >= 0); |
113 | } |
114 | |
115 | global_id = new byte[array_len]; |
116 | if (array_len > 0) |
117 | in.read(global_id); |
118 | |
119 | // read branch_id in from disk |
120 | array_len = in.read(); |
121 | |
122 | if (SanityManager.DEBUG) |
123 | { |
124 | SanityManager.ASSERT(array_len >= 0); |
125 | } |
126 | |
127 | branch_id = new byte[array_len]; |
128 | if (array_len > 0) |
129 | in.read(branch_id); |
130 | } |
131 | |
132 | /** |
133 | Return my format identifier. |
134 | */ |
135 | public int getTypeFormatId() { |
136 | return StoredFormatIds.RAW_STORE_GLOBAL_XACT_ID_NEW; |
137 | } |
138 | |
139 | /************************************************************************** |
140 | * Private/Protected methods of This class: |
141 | ************************************************************************** |
142 | */ |
143 | |
144 | /************************************************************************** |
145 | * Public Methods of This class: |
146 | ************************************************************************** |
147 | */ |
148 | public int getFormat_Id() |
149 | { |
150 | return(format_id); |
151 | } |
152 | |
153 | public byte[] getGlobalTransactionId() |
154 | { |
155 | return(global_id); |
156 | } |
157 | |
158 | public byte[] getBranchQualifier() |
159 | { |
160 | return(branch_id); |
161 | } |
162 | } |