1 Star 11 Fork 5

wind/SimpleDB

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AbstractDbFileIterator.java 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
wind 提交于 2022-01-27 22:33 +08:00 . simple-db-implement
package simpledb.storage;
import simpledb.common.DbException;
import simpledb.transaction.TransactionAbortedException;
import java.util.NoSuchElementException;
/** Helper for implementing DbFileIterators. Handles hasNext()/next() logic. */
public abstract class AbstractDbFileIterator implements DbFileIterator {
public boolean hasNext() throws DbException, TransactionAbortedException {
if (next == null) next = readNext();
return next != null;
}
public Tuple next() throws DbException, TransactionAbortedException,
NoSuchElementException {
if (next == null) {
next = readNext();
if (next == null) throw new NoSuchElementException();
}
Tuple result = next;
next = null;
return result;
}
/** If subclasses override this, they should call super.close(). */
public void close() {
// Ensures that a future call to next() will fail
next = null;
}
/** Reads the next tuple from the underlying source.
@return the next Tuple in the iterator, null if the iteration is finished. */
protected abstract Tuple readNext() throws DbException, TransactionAbortedException;
private Tuple next = null;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/wygandwind/simple-db.git
git@gitee.com:wygandwind/simple-db.git
wygandwind
simple-db
SimpleDB
master

搜索帮助