class UndoLog {

    private int logId;
    private UndoLogRecord first;// 指向最早加进来的，执行commit时从first开始遍历
    private UndoLogRecord last; // 总是指向新增加的，执行rollback时从first开始遍历

    public int getLogId() {
        return logId;
    }

    public UndoLogRecord getFirst() {
        return first;
    }

    public int size() {
        return logId;
    }

    public boolean isEmpty() {
        return logId == 0;
    }

    public boolean isNotEmpty() {
        return logId != 0;
    }

    public UndoLogRecord add(StorageMap<?, ?> map, Object key, Object oldValue,
            TransactionalValue newTV) {
        UndoLogRecord r = new UndoLogRecord(map, key, oldValue, newTV);
        if (first == null) {
            first = last = r;
        } else {
            last.next = r;
            r.prev = last;
            last = r;
        }
        logId++;
        return r;
    }

    private UndoLogRecord removeLast() {
        UndoLogRecord r = last;
        if (last != null) {
            if (last.prev != null)
                last.prev.next = null;
            last = last.prev;
            if (last == null) {
                first = null;
            }
            --logId;
        }
        return r;
    }

    public void commit(AOTransactionEngine te) {<FILL_FUNCTION_BODY>}

    public void rollbackTo(AOTransactionEngine te, int toLogId) {
        while (logId > toLogId) {
            UndoLogRecord r = removeLast();
            r.rollback(te);
        }
    }

    // 将当前一系列的事务操作日志转换成单条RedoLogRecord
    public DataBuffer toRedoLogRecordBuffer(AOTransactionEngine te, DataBufferFactory dbFactory) {
        DataBuffer buffer = dbFactory.create();
        toRedoLogRecordBuffer(te, buffer);
        buffer.getAndFlipBuffer();
        return buffer;
    }

    public void toRedoLogRecordBuffer(AOTransactionEngine te, DataBuffer buffer) {
        UndoLogRecord r = first;
        while (r != null) {
            r.writeForRedo(buffer, te);
            r = r.next;
        }
    }
}

        UndoLogRecord r = first;
        while (r != null) {
            r.commit(te);
            r = r.next;
        }
    
<no_super_class>