KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > txn > TxnPrepare


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: TxnPrepare.java,v 1.7 2006/10/30 21:14:27 bostic Exp $
7  */

8
9 package com.sleepycat.je.txn;
10
11 import java.nio.ByteBuffer JavaDoc;
12
13 import javax.transaction.xa.Xid JavaDoc;
14
15 import com.sleepycat.je.log.LogEntryType;
16 import com.sleepycat.je.log.LogReadable;
17 import com.sleepycat.je.log.LogUtils;
18 import com.sleepycat.je.log.LoggableObject;
19 import com.sleepycat.je.utilint.DbLsn;
20
21 /**
22  * This class writes out a transaction prepare record.
23  */

24 public class TxnPrepare extends TxnEnd {
25
26     private Xid JavaDoc xid;
27
28     public TxnPrepare(long id, Xid JavaDoc xid) {
29     /* LastLSN is never used. */
30         super(id, DbLsn.NULL_LSN);
31     this.xid = xid;
32     }
33     
34     /**
35      * For constructing from the log.
36      */

37     public TxnPrepare() {
38     }
39
40     public Xid JavaDoc getXid() {
41     return xid;
42     }
43
44     /*
45      * Log support
46      */

47
48     /**
49      * @see TxnEnd#getLogType
50      */

51     public LogEntryType getLogType() {
52         return LogEntryType.LOG_TXN_PREPARE;
53     }
54
55     protected String JavaDoc getTagName() {
56         return "TxnPrepare";
57     }
58
59     /**
60      * @see LoggableObject#getLogSize
61      */

62     public int getLogSize() {
63         return LogUtils.LONG_BYTES + // id
64
LogUtils.getTimestampLogSize() + // timestamp
65
LogUtils.getXidSize(xid); // Xid
66
}
67
68     /**
69      * @see LoggableObject#writeToLog
70      */

71     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
72         LogUtils.writeLong(logBuffer, id);
73         LogUtils.writeTimestamp(logBuffer, time);
74     LogUtils.writeXid(logBuffer, xid);
75     }
76
77     /**
78      * @see LogReadable#readFromLog
79      */

80     public void readFromLog(ByteBuffer JavaDoc logBuffer, byte entryTypeVersion) {
81         id = LogUtils.readLong(logBuffer);
82         time = LogUtils.readTimestamp(logBuffer);
83     xid = LogUtils.readXid(logBuffer);
84     }
85
86     /**
87      * @see LogReadable#dumpLog
88      */

89     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
90         sb.append("<").append(getTagName());
91         sb.append(" id=\"").append(id);
92     sb.append("\" xid=\"").append(xid);
93         sb.append("\" time=\"").append(time);
94         sb.append("\">");
95         sb.append("</").append(getTagName()).append(">");
96     }
97 }
98
Popular Tags