001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: TxnEnd.java,v 1.33.2.3 2008/01/07 15:14:17 cwl Exp $
007: */
008:
009: package com.sleepycat.je.txn;
010:
011: import java.nio.ByteBuffer;
012: import java.sql.Timestamp;
013:
014: import com.sleepycat.je.log.LogUtils;
015: import com.sleepycat.je.log.Loggable;
016: import com.sleepycat.je.utilint.DbLsn;
017:
018: /**
019: * This class writes out a transaction commit or transaction end record.
020: */
021: public abstract class TxnEnd implements Loggable {
022:
023: protected long id;
024: protected Timestamp time;
025: private long lastLsn;
026:
027: TxnEnd(long id, long lastLsn) {
028: this .id = id;
029: time = new Timestamp(System.currentTimeMillis());
030: this .lastLsn = lastLsn;
031: }
032:
033: /**
034: * For constructing from the log
035: */
036: public TxnEnd() {
037: lastLsn = DbLsn.NULL_LSN;
038: }
039:
040: /*
041: * Accessors.
042: */
043: public long getId() {
044: return id;
045: }
046:
047: long getLastLsn() {
048: return lastLsn;
049: }
050:
051: protected abstract String getTagName();
052:
053: /*
054: * Log support for writing.
055: */
056:
057: /**
058: * @see Loggable#getLogSize
059: */
060: public int getLogSize() {
061: return LogUtils.LONG_BYTES + LogUtils.getTimestampLogSize()
062: + LogUtils.getLongLogSize(); // lastLsn
063: }
064:
065: /**
066: * @see Loggable#writeToLog
067: */
068: public void writeToLog(ByteBuffer logBuffer) {
069: LogUtils.writeLong(logBuffer, id);
070: LogUtils.writeTimestamp(logBuffer, time);
071: LogUtils.writeLong(logBuffer, lastLsn);
072: }
073:
074: /**
075: * @see Loggable#readFromLog
076: */
077: public void readFromLog(ByteBuffer logBuffer, byte entryTypeVersion) {
078: id = LogUtils.readLong(logBuffer);
079: time = LogUtils.readTimestamp(logBuffer);
080: lastLsn = LogUtils.readLong(logBuffer);
081: }
082:
083: /**
084: * @see Loggable#dumpLog
085: */
086: public void dumpLog(StringBuffer sb, boolean verbose) {
087: sb.append("<").append(getTagName());
088: sb.append(" id=\"").append(id);
089: sb.append("\" time=\"").append(time);
090: sb.append("\">");
091: sb.append(DbLsn.toString(lastLsn));
092: sb.append("</").append(getTagName()).append(">");
093: }
094:
095: /**
096: * @see Loggable#getTransactionId
097: */
098: public long getTransactionId() {
099: return id;
100: }
101: }
|