本文整理匯總了Java中org.iq80.leveldb.DB.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java DB.iterator方法的具體用法?Java DB.iterator怎麽用?Java DB.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.iq80.leveldb.DB
的用法示例。
在下文中一共展示了DB.iterator方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: replace
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static <T extends D_Level> void replace(String cluster, Class<T> clazz, List<T> data) 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.seekToFirst();
iterator.forEachRemaining(entry ->{
byte[] key = entry.getKey();
write.delete(key);
});
data.forEach(t->{
write.put(t.key().getBytes(), t.value());
});
db.write(write, new WriteOptions().sync(true));
} finally {
iterator.close();
write.close();
}
}
示例2: last
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> T last(String cluster, Class<T> clazz) throws IOException {
DB db = getDB(path(cluster, clazz));
ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
DBIterator iterator = db.iterator(readOptions);
try {
iterator.seekToLast();
if(!iterator.hasNext()){
return null;
}
Entry<byte[], byte[]> entry = iterator.next();
byte[] v = entry.getValue();
return (T)D_Level.deserialize(clazz, v);
} finally {
iterator.close();
}
}
示例3: getAll
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_Level> List<T> getAll(String cluster, Class<T> clazz)throws IOException {
DB db = getDB(path(cluster, clazz));
ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
DBIterator iterator = db.iterator(readOptions);
List<T> list = new ArrayList<T>();
try {
iterator.seekToFirst();
iterator.forEachRemaining(entry ->{
byte[] v = entry.getValue();
list.add((T)D_Level.deserialize(clazz, v));
});
} finally {
iterator.close();
}
return list;
}
示例4: prevWith
import org.iq80.leveldb.DB; //導入方法依賴的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();
}
}
示例5: deletePrev
import org.iq80.leveldb.DB; //導入方法依賴的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();
}
}
示例6: getEntity
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@Override
public TimelineEntity getEntity(String entityId, String entityType,
EnumSet<Field> fields) throws IOException {
Long revStartTime = getStartTimeLong(entityId, entityType);
if (revStartTime == null) {
return null;
}
byte[] prefix = KeyBuilder.newInstance().add(entityType)
.add(writeReverseOrderedLong(revStartTime)).add(entityId)
.getBytesForLookup();
DBIterator iterator = null;
try {
DB db = entitydb.getDBForStartTime(revStartTime);
if (db == null) {
return null;
}
iterator = db.iterator();
iterator.seek(prefix);
return getEntity(entityId, entityType, revStartTime, fields, iterator,
prefix, prefix.length);
} finally {
IOUtils.cleanup(LOG, iterator);
}
}
示例7: getEntity
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@Override
public TimelineEntity getEntity(String entityId, String entityType,
EnumSet<Field> fields) throws IOException {
Long revStartTime = getStartTimeLong(entityId, entityType);
if (revStartTime == null) {
return null;
}
byte[] prefix = KeyBuilder.newInstance().add(entityType)
.add(writeReverseOrderedLong(revStartTime)).add(entityId)
.getBytesForLookup();
DB db = entitydb.getDBForStartTime(revStartTime);
if (db == null) {
return null;
}
try (DBIterator iterator = db.iterator()) {
iterator.seek(prefix);
return getEntity(entityId, entityType, revStartTime, fields, iterator,
prefix, prefix.length);
}
}
示例8: startWith
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> void startWith(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());
iterator.forEachRemaining(entry ->{
byte[] v = entry.getValue();
action.accept((T)D_Level.deserialize(clazz, v));
});
} finally {
iterator.close();
}
}
示例9: LeveldbIterator
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
/**
* Create an iterator for the specified database
*/
public LeveldbIterator(DB db) {
iter = db.iterator();
}