📄 setstringrecord.java
字号:
package simpledb.tx.recovery;import simpledb.server.SimpleDB;import simpledb.buffer.*;import simpledb.file.Block;import simpledb.log.BasicLogRecord;class SetStringRecord implements LogRecord { private int txnum, offset; private String val; private Block blk; /** * Creates a new setstring log record. * @param txnum the ID of the specified transaction * @param blk the block containing the value * @param offset the offset of the value in the block * @param val the new value */ public SetStringRecord(int txnum, Block blk, int offset, String val) { this.txnum = txnum; this.blk = blk; this.offset = offset; this.val = val; } /** * Creates a log record by reading five other values from the log. * @param rec the basic log record */ public SetStringRecord(BasicLogRecord rec) { txnum = rec.nextInt(); String filename = rec.nextString(); int blknum = rec.nextInt(); blk = new Block(filename, blknum); offset = rec.nextInt(); val = rec.nextString(); } /** * Writes a setString record to the log. * This log record contains the SETSTRING operator, * followed by the transaction id, the filename, number, * and offset of the modified block, and the previous * string value at that offset. * @return the LSN of the last log value */ public int writeToLog() { Object[] rec = new Object[] {SETSTRING, txnum, blk.fileName(), blk.number(), offset, val}; return logMgr.append(rec); } public int op() { return LogRecord.SETSTRING; } public int txNumber() { return txnum; } public String toString() { return "<SETSTRING " + txnum + " " + blk + " " + offset + " " + val + ">"; } /** * Replaces the specified data value with the value saved in the log record. * The method pins a buffer to the specified block, * calls setString to restore the saved value, * and unpins the buffer. * @see simpledb.tx.recovery.LogRecord#undo(int) */ public void undo(int txnum) { BufferMgr buffMgr = SimpleDB.bufferMgr(); Buffer buff = buffMgr.pin(blk); buff.setString(offset, val, txnum, -1); buffMgr.unpin(buff); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -