本文整理汇总了Java中org.iq80.leveldb.DBIterator类的典型用法代码示例。如果您正苦于以下问题:Java DBIterator类的具体用法?Java DBIterator怎么用?Java DBIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DBIterator类属于org.iq80.leveldb包,在下文中一共展示了DBIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replace
import org.iq80.leveldb.DBIterator; //导入依赖的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.DBIterator; //导入依赖的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.DBIterator; //导入依赖的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.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();
}
}
示例5: 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();
}
}
示例6: getEntity
import org.iq80.leveldb.DBIterator; //导入依赖的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: size
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
private int size(final String repositoryName) {
DBIterator it = levelDBFile.getDb().iterator();
String prefix = repositoryName + '\0';
int count = 0;
try {
for (it.seek(keyBuilder(repositoryName, "")); it.hasNext(); it.next()) {
if (!asString(it.peekNext().getKey()).startsWith(prefix)) {
break;
}
count++;
}
} finally {
// Make sure you close the iterator to avoid resource leaks.
IOHelper.close(it);
}
LOG.debug("Size of repository [{}] -> {}", repositoryName, count);
return count;
}
示例8: getEntity
import org.iq80.leveldb.DBIterator; //导入依赖的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(ENTITY_ENTRY_PREFIX)
.add(entityType).add(writeReverseOrderedLong(revStartTime))
.add(entityId).getBytesForLookup();
DBIterator iterator = null;
try {
iterator = db.iterator();
iterator.seek(prefix);
return getEntity(entityId, entityType, revStartTime, fields, iterator,
prefix, prefix.length);
} finally {
IOUtils.cleanup(LOG, iterator);
}
}
示例9: getEntity
import org.iq80.leveldb.DBIterator; //导入依赖的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);
}
}
示例10: getNumChunks
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
public static int getNumChunks(long obj_id) {
int num = 0;
DBIterator iterator = db.iterator();
// TODO: chunk for obj_id may not start with 0!
String key = Long.toString(obj_id) + ",0";
try {
for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
if (!(asString(iterator.peekNext().getKey()).startsWith(Long
.toString(obj_id) + ",")))
break;
num++;
}
iterator.close();
} catch (IOException e) {
e.printStackTrace();
}
return num;
}
示例11: setObjectDirty
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
public static void setObjectDirty(long obj_id) {
int chunk_num = 0;
DBIterator iterator = db.iterator();
String key = Long.toString(obj_id) + "," + Integer.toString(chunk_num);
try {
for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
if (!(asString(iterator.peekNext().getKey()).startsWith(Long
.toString(obj_id) + ",")))
break;
SimbaChunkList.addDirtyChunk(obj_id, chunk_num);
chunk_num++;
}
iterator.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: deleteObject
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
public static void deleteObject(long obj_id, int startChunk) {
String key = Long.toString(obj_id) + "," + Integer.toString(startChunk);
DBIterator iterator = db.iterator();
try {
for (iterator.seek(bytes(key)); iterator.hasNext(); iterator.next()) {
if (!(asString(iterator.peekNext().getKey()).startsWith(Long
.toString(obj_id) + ",")))
break;
Log.d(TAG, "DELETE <" + asString(iterator.peekNext().getKey())
+ ">");
db.delete(iterator.peekNext().getKey());
}
iterator.close();
} catch (IOException e) {
e.printStackTrace();
}
// delete object from dirtyChunkList
SimbaChunkList.removeDirtyChunks(obj_id);
}
示例13: doScan
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("resource")
@Override
protected void doScan(byte[] beginKey, byte[] endKey,
IKeyValueCallback callback, boolean includeValue)
throws StorageException {
DBIterator iterator = null;
try {
iterator = database.iterator();
iterator.seek(beginKey);
while (iterator.hasNext()) {
Entry<byte[], byte[]> keyValue = iterator.next();
if (ByteArrayUtils.isLess(endKey, keyValue.getKey(), true)) {
return;
}
callback.callback(keyValue.getKey(), keyValue.getValue());
}
} catch (DBException e) {
throw new StorageException(e);
} finally {
FileSystemUtils.close(iterator);
}
}
示例14: loadAccounts
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
private void loadAccounts() {
new Thread(){
@Override
public void run(){
DBIterator i = WorldManager.getInstance().getRepository().getAccountsIterator();
while(i.hasNext()) {
DataClass dc = new DataClass();
dc.address = i.next().getKey();
AccountState state = WorldManager.getInstance().getRepository().getAccountState(dc.address);
dc.accountState = state;
adapter.addDataPiece(dc);
}
}
}.start();
}
示例15: getAlerts
import org.iq80.leveldb.DBIterator; //导入依赖的package包/类
/**
* Returns a list of all alerts in the database
*
* @return List of all alerts
* @throws BlockStoreException Unable to get alerts from database
*/
@Override
public List<Alert> getAlerts() throws BlockStoreException {
List<Alert> alerts = new LinkedList<>();
try {
try (DBIterator it = dbAlert.iterator()) {
it.seekToFirst();
while (it.hasNext()) {
Entry<byte[], byte[]> dbEntry = it.next();
byte[] entryData = dbEntry.getValue();
AlertEntry alertEntry = new AlertEntry(entryData);
Alert alert = new Alert(alertEntry.getPayload(), alertEntry.getSignature());
alert.setCancel(alertEntry.isCanceled());
alerts.add(alert);
}
}
} catch (DBException | IOException exc) {
log.error("Unable to get alerts from database", exc);
throw new BlockStoreException("Unable to get alerts from database");
}
return alerts;
}