01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: TxnPrepare.java,v 1.8.2.3 2008/01/07 15:14:17 cwl Exp $
07: */
08:
09: package com.sleepycat.je.txn;
10:
11: import java.nio.ByteBuffer;
12:
13: import javax.transaction.xa.Xid;
14:
15: import com.sleepycat.je.log.LogUtils;
16: import com.sleepycat.je.log.Loggable;
17: import com.sleepycat.je.utilint.DbLsn;
18:
19: /**
20: * This class writes out a transaction prepare record.
21: */
22: public class TxnPrepare extends TxnEnd implements Loggable {
23:
24: private Xid xid;
25:
26: public TxnPrepare(long id, Xid xid) {
27: /* LastLSN is never used. */
28: super (id, DbLsn.NULL_LSN);
29: this .xid = xid;
30: }
31:
32: /**
33: * For constructing from the log.
34: */
35: public TxnPrepare() {
36: }
37:
38: public Xid getXid() {
39: return xid;
40: }
41:
42: /*
43: * Log support
44: */
45:
46: protected String getTagName() {
47: return "TxnPrepare";
48: }
49:
50: /**
51: * @see Loggable#getLogSize
52: */
53: public int getLogSize() {
54: return LogUtils.LONG_BYTES + // id
55: LogUtils.getTimestampLogSize() + // timestamp
56: LogUtils.getXidSize(xid); // Xid
57: }
58:
59: /**
60: * @see Loggable#writeToLog
61: */
62: public void writeToLog(ByteBuffer logBuffer) {
63: LogUtils.writeLong(logBuffer, id);
64: LogUtils.writeTimestamp(logBuffer, time);
65: LogUtils.writeXid(logBuffer, xid);
66: }
67:
68: /**
69: * @see Loggable#readFromLog
70: */
71: public void readFromLog(ByteBuffer logBuffer, byte entryTypeVersion) {
72: id = LogUtils.readLong(logBuffer);
73: time = LogUtils.readTimestamp(logBuffer);
74: xid = LogUtils.readXid(logBuffer);
75: }
76:
77: /**
78: * @see Loggable#dumpLog
79: */
80: public void dumpLog(StringBuffer sb, boolean verbose) {
81: sb.append("<").append(getTagName());
82: sb.append(" id=\"").append(id);
83: sb.append("\" xid=\"").append(xid);
84: sb.append("\" time=\"").append(time);
85: sb.append("\">");
86: sb.append("</").append(getTagName()).append(">");
87: }
88: }
|