本文整理汇总了Java中org.iq80.leveldb.DBIterator.hasPrev方法的典型用法代码示例。如果您正苦于以下问题:Java DBIterator.hasPrev方法的具体用法?Java DBIterator.hasPrev怎么用?Java DBIterator.hasPrev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.iq80.leveldb.DBIterator
的用法示例。
在下文中一共展示了DBIterator.hasPrev方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prevWith
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> void prevWith(String cluster, Class<T> clazz, Long start, Consumer<T> action) throws IOException {
DB db = getDB(path(cluster, clazz));
ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
DBIterator iterator = db.iterator(readOptions);
try {
iterator.seek((start + "").getBytes());
while(iterator.hasPrev()){
Entry<byte[], byte[]> entry = iterator.prev();
byte[] v = entry.getValue();
action.accept((T)D_Level.deserialize(clazz, v));
}
} finally {
iterator.close();
}
}
示例2: deletePrev
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public static <T extends D_TimeLine> void deletePrev(String cluster, Class<T> clazz, Long start) throws IOException {
DB db = getDB(path(cluster, clazz));
ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
DBIterator iterator = db.iterator(readOptions);
WriteBatch write = db.createWriteBatch();
try {
iterator.seek((start + "").getBytes());
while(iterator.hasPrev()){
byte[] key = iterator.prev().getKey();
write.delete(key);
}
db.write(write, new WriteOptions().sync(true));
} finally {
iterator.close();
write.close();
}
}
示例3: rangeReverse
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public TableIterator<H, R, V> rangeReverse(final H hashKey) {
final DBIterator iterator = db.iterator();
final Function<CheckKeysRequest, Boolean> checkKeys = new Function<CheckKeysRequest, Boolean>() {
@Override
public Boolean apply(CheckKeysRequest input) {
return Util.compareKeys(hashKeyComparator, null,
input.getKeyBytesFrom(), input.getPeekKey()) == 0;
}
};
final byte[] keyBytesFrom = Util.combine(hashKeySerde, rangeKeySerde,
hashKey, null);
TableIterator<H, R, V> emptyIterator = reverseSeekToLast(hashKey, null,
null, keyBytesFrom, null, iterator, checkKeys);
if (emptyIterator != null) {
return emptyIterator;
}
return new AutoClosingTableIterator<H, R, V>(
new TableIterator<H, R, V>() {
private boolean fixFirst = true;;
@Override
public boolean hasNext() {
if (useFixFirst()) {
return true;
}
return iterator.hasPrev()
&& checkKeys.apply(new CheckKeysRequest(
hashKey, null, null, keyBytesFrom,
null, iterator.peekPrev()));
}
private boolean useFixFirst() {
if (fixFirst && iterator.hasNext()) {
final Entry<byte[], byte[]> peekNext = iterator
.peekNext();
if (peekNext != null) {
if (checkKeys.apply(new CheckKeysRequest(
hashKey, null, null, keyBytesFrom,
null, peekNext))) {
return true;
} else {
fixFirst = false;
}
}
}
return false;
}
@Override
public TableRow<H, R, V> next() {
if (useFixFirst()) {
fixFirst = false;
return new RawTableRow<H, R, V>(
iterator.peekNext(), hashKeySerde,
rangeKeySerde, valueSerde);
}
return new RawTableRow<H, R, V>(iterator.prev(),
hashKeySerde, rangeKeySerde, valueSerde);
}
@Override
public void remove() {
if (useFixFirst()) {
throw new UnsupportedOperationException(
"Not possible on first result for now...");
}
iterator.remove();
}
@Override
public void close() {
try {
iterator.close();
} catch (final Exception e) {
throw new DbException(e);
}
}
});
}