001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.xact.GlobalXactId
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.raw.xact;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.services.io.FormatIdUtil;
027: import org.apache.derby.iapi.services.io.StoredFormatIds;
028: import org.apache.derby.catalog.UUID;
029:
030: import org.apache.derby.iapi.store.raw.GlobalTransactionId;
031: import org.apache.derby.iapi.store.access.GlobalXact;
032:
033: import org.apache.derby.iapi.util.ByteArray;
034:
035: import java.io.ObjectOutput;
036: import java.io.ObjectInput;
037: import java.io.IOException;
038:
039: public class GlobalXactId extends GlobalXact implements
040: GlobalTransactionId {
041: /**************************************************************************
042: * Private Fields of the class
043: **************************************************************************
044: */
045:
046: /**************************************************************************
047: * Constructors for This class:
048: **************************************************************************
049: */
050: public GlobalXactId(int format_id, byte[] global_id,
051: byte[] branch_id) {
052: this .format_id = format_id;
053: this .global_id = new byte[global_id.length];
054: System.arraycopy(global_id, 0, this .global_id, 0,
055: global_id.length);
056: this .branch_id = new byte[branch_id.length];
057: System.arraycopy(branch_id, 0, this .branch_id, 0,
058: branch_id.length);
059: }
060:
061: /**************************************************************************
062: * Public Methods of Formatable interface:
063: **************************************************************************
064: */
065:
066: // no-arg constructor, required by Formatable
067: public GlobalXactId() {
068: }
069:
070: /**
071: Write this out.
072: @exception IOException error writing to log stream
073: */
074: public void writeExternal(ObjectOutput out) throws IOException {
075: out.writeInt(format_id);
076:
077: if (SanityManager.DEBUG) {
078: SanityManager.ASSERT(global_id.length <= 64);
079: SanityManager.ASSERT(global_id != null);
080: SanityManager.ASSERT(branch_id != null);
081: }
082:
083: // write length of array followed by the array
084: out.write(global_id.length);
085: if (global_id.length > 0)
086: out.write(global_id);
087:
088: // write length of array followed by the array
089: out.write(branch_id.length);
090: if (branch_id.length > 0)
091: out.write(branch_id);
092: }
093:
094: /**
095: Read this in
096: @exception IOException error reading from log stream
097: @exception ClassNotFoundException log stream corrupted
098: */
099: public void readExternal(ObjectInput in) throws IOException,
100: ClassNotFoundException {
101: format_id = in.readInt();
102:
103: // read global_id in from disk
104: int array_len = in.read();
105:
106: if (SanityManager.DEBUG) {
107: SanityManager.ASSERT(array_len >= 0);
108: }
109:
110: global_id = new byte[array_len];
111: if (array_len > 0)
112: in.read(global_id);
113:
114: // read branch_id in from disk
115: array_len = in.read();
116:
117: if (SanityManager.DEBUG) {
118: SanityManager.ASSERT(array_len >= 0);
119: }
120:
121: branch_id = new byte[array_len];
122: if (array_len > 0)
123: in.read(branch_id);
124: }
125:
126: /**
127: Return my format identifier.
128: */
129: public int getTypeFormatId() {
130: return StoredFormatIds.RAW_STORE_GLOBAL_XACT_ID_NEW;
131: }
132:
133: /**************************************************************************
134: * Private/Protected methods of This class:
135: **************************************************************************
136: */
137:
138: /**************************************************************************
139: * Public Methods of This class:
140: **************************************************************************
141: */
142: public int getFormat_Id() {
143: return (format_id);
144: }
145:
146: public byte[] getGlobalTransactionId() {
147: return (global_id);
148: }
149:
150: public byte[] getBranchQualifier() {
151: return (branch_id);
152: }
153: }
|