KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

23 public abstract class TxnEnd
24     implements LoggableObject, LogReadable {
25
26     protected long id;
27     protected Timestamp JavaDoc time;
28     private long lastLsn;
29
30     TxnEnd(long id, long lastLsn) {
31         this.id = id;
32         time = new Timestamp JavaDoc(System.currentTimeMillis());
33         this.lastLsn = lastLsn;
34     }
35     
36     /**
37      * For constructing from the log
38      */

39     public TxnEnd() {
40         lastLsn = DbLsn.NULL_LSN;
41     }
42
43     /*
44      * Accessors.
45      */

46     public long getId() {
47         return id;
48     }
49
50     long getLastLsn() {
51         return lastLsn;
52     }
53
54     protected abstract String JavaDoc getTagName();
55
56     /*
57      * Log support for writing.
58      */

59
60     /**
61      * @see LoggableObject#getLogType
62      */

63     public abstract LogEntryType getLogType();
64
65     /**
66      * @see LoggableObject#marshallOutsideWriteLatch
67      * Can be marshalled outside the log write latch.
68      */

69     public boolean marshallOutsideWriteLatch() {
70         return true;
71     }
72
73     /**
74      * @see LoggableObject#countAsObsoleteWhenLogged
75      */

76     public boolean countAsObsoleteWhenLogged() {
77         return false;
78     }
79
80     /**
81      * @see LoggableObject#postLogWork
82      */

83     public void postLogWork(long justLoggedLsn) {
84     }
85
86     /**
87      * @see LoggableObject#getLogSize
88      */

89     public int getLogSize() {
90         return LogUtils.LONG_BYTES +
91             LogUtils.getTimestampLogSize() +
92             LogUtils.getLongLogSize(); // lastLsn
93
}
94
95     /**
96      * @see LoggableObject#writeToLog
97      */

98     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
99         LogUtils.writeLong(logBuffer, id);
100         LogUtils.writeTimestamp(logBuffer, time);
101         LogUtils.writeLong(logBuffer, lastLsn);
102     }
103
104     /**
105      * @see LogReadable#readFromLog
106      */

107     public void readFromLog(ByteBuffer JavaDoc logBuffer, byte entryTypeVersion) {
108         id = LogUtils.readLong(logBuffer);
109         time = LogUtils.readTimestamp(logBuffer);
110         lastLsn = LogUtils.readLong(logBuffer);
111     }
112
113     /**
114      * @see LogReadable#dumpLog
115      */

116     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
117         sb.append("<").append(getTagName());
118         sb.append(" id=\"").append(id);
119         sb.append("\" time=\"").append(time);
120         sb.append("\">");
121     sb.append(DbLsn.toString(lastLsn));
122         sb.append("</").append(getTagName()).append(">");
123     }
124
125     /**
126      * @see LogReadable#logEntryIsTransactional
127      */

128     public boolean logEntryIsTransactional() {
129     return true;
130     }
131
132     /**
133      * @see LogReadable#getTransactionId
134      */

135     public long getTransactionId() {
136     return id;
137     }
138 }
139
Popular Tags