当前位置: 首页>>代码示例>>Java>>正文


Java DBIterator类代码示例

本文整理汇总了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();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:21,代码来源:LevelTable.java

示例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();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例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;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例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();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:17,代码来源:LevelTable.java

示例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();
	}
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:18,代码来源:LevelTable.java

示例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);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:27,代码来源:RollingLevelDBTimelineStore.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:LevelDBAggregationRepository.java

示例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);
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:23,代码来源:LeveldbTimelineStore.java

示例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);
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:23,代码来源:RollingLevelDBTimelineStore.java

示例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;
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:SimbaLevelDB.java

示例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();
	}
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:19,代码来源:SimbaLevelDB.java

示例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);
}
 
开发者ID:SimbaService,项目名称:Simba,代码行数:22,代码来源:SimbaLevelDB.java

示例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);
	}
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:25,代码来源:DainLevelDBStore.java

示例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();
}
 
开发者ID:ethereumj,项目名称:ethereumj,代码行数:19,代码来源:AccountsListWindow.java

示例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;
}
 
开发者ID:shadders,项目名称:JavaBitcoin,代码行数:28,代码来源:BlockStoreLdb.java


注:本文中的org.iq80.leveldb.DBIterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。