本文整理汇总了Java中org.iq80.leveldb.DBIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java DBIterator.hasNext方法的具体用法?Java DBIterator.hasNext怎么用?Java DBIterator.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.iq80.leveldb.DBIterator
的用法示例。
在下文中一共展示了DBIterator.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
}
示例5: 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);
}
示例6: 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);
}
}
示例7: getTimelineDomain
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
private static TimelineDomain getTimelineDomain(DBIterator iterator,
String domainId, byte[] prefix) throws IOException {
// Iterate over all the rows whose key starts with prefix to retrieve the
// domain information.
TimelineDomain domain = new TimelineDomain();
domain.setId(domainId);
boolean noRows = true;
for (; iterator.hasNext(); iterator.next()) {
byte[] key = iterator.peekNext().getKey();
if (!prefixMatches(prefix, prefix.length, key)) {
break;
}
if (noRows) {
noRows = false;
}
byte[] value = iterator.peekNext().getValue();
if (value != null && value.length > 0) {
if (key[prefix.length] == DESCRIPTION_COLUMN[0]) {
domain.setDescription(new String(value, UTF_8));
} else if (key[prefix.length] == OWNER_COLUMN[0]) {
domain.setOwner(new String(value, UTF_8));
} else if (key[prefix.length] == READER_COLUMN[0]) {
domain.setReaders(new String(value, UTF_8));
} else if (key[prefix.length] == WRITER_COLUMN[0]) {
domain.setWriters(new String(value, UTF_8));
} else if (key[prefix.length] == TIMESTAMP_COLUMN[0]) {
domain.setCreatedTime(readReverseOrderedLong(value, 0));
domain.setModifiedTime(readReverseOrderedLong(value, 8));
} else {
LOG.error("Unrecognized domain column: " + key[prefix.length]);
}
}
}
if (noRows) {
return null;
} else {
return domain;
}
}
示例8: getKeys
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public Set<String> getKeys() {
final Set<String> keys = new LinkedHashSet<String>();
// interval task could potentially be running while we are shutting down so check for that
if (!isRunAllowed()) {
return null;
}
DBIterator it = levelDBFile.getDb().iterator();
String keyBuffer;
try {
String prefix = repositoryName + '\0';
for (it.seek(keyBuilder(repositoryName, "")); it.hasNext(); it.next()) {
if (!isRunAllowed()) {
break;
}
keyBuffer = asString(it.peekNext().getKey());
if (!keyBuffer.startsWith(prefix)) {
break;
}
String key = keyBuffer.substring(prefix.length());
LOG.trace("getKey [{}]", key);
keys.add(key);
}
} finally {
// Make sure you close the iterator to avoid resource leaks.
IOHelper.close(it);
}
return Collections.unmodifiableSet(keys);
}
示例9: scan
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public Set<String> scan(CamelContext camelContext) {
final Set<String> answer = new LinkedHashSet<String>();
if (!isRunAllowed()) {
return null;
}
DBIterator it = levelDBFile.getDb().iterator();
String keyBuffer;
try {
String prefix = getRepositoryNameCompleted() + '\0';
for (it.seek(keyBuilder(getRepositoryNameCompleted(), "")); it.hasNext(); it.next()) {
keyBuffer = asString(it.peekNext().getKey());
if (!keyBuffer.startsWith(prefix)) {
break;
}
String exchangeId = keyBuffer.substring(prefix.length());
LOG.trace("Scan exchangeId [{}]", exchangeId);
answer.add(exchangeId);
}
} finally {
// Make sure you close the iterator to avoid resource leaks.
IOHelper.close(it);
}
if (answer.size() == 0) {
LOG.trace("Scanned and found no exchange to recover.");
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Scanned and found {} exchange(s) to recover (note some of them may already be in progress).", answer.size());
}
}
return answer;
}
示例10: getEntityTypes
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@VisibleForTesting
List<String> getEntityTypes() throws IOException {
DBIterator iterator = null;
try {
iterator = getDbIterator(false);
List<String> entityTypes = new ArrayList<String>();
iterator.seek(ENTITY_ENTRY_PREFIX);
while (iterator.hasNext()) {
byte[] key = iterator.peekNext().getKey();
if (key[0] != ENTITY_ENTRY_PREFIX[0]) {
break;
}
KeyParser kp = new KeyParser(key,
ENTITY_ENTRY_PREFIX.length);
String entityType = kp.getNextString();
entityTypes.add(entityType);
byte[] lookupKey = KeyBuilder.newInstance().add(ENTITY_ENTRY_PREFIX)
.add(entityType).getBytesForLookup();
if (lookupKey[lookupKey.length - 1] != 0x0) {
throw new IOException("Found unexpected end byte in lookup key");
}
lookupKey[lookupKey.length - 1] = 0x1;
iterator.seek(lookupKey);
}
return entityTypes;
} finally {
IOUtils.cleanup(LOG, iterator);
}
}
示例11: deleteKeysWithPrefix
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
/**
* Finds all keys in the db that have a given prefix and deletes them on
* the given write batch.
*/
private void deleteKeysWithPrefix(WriteBatch writeBatch, byte[] prefix,
DBIterator iterator) {
for (iterator.seek(prefix); iterator.hasNext(); iterator.next()) {
byte[] key = iterator.peekNext().getKey();
if (!prefixMatches(prefix, prefix.length, key)) {
break;
}
writeBatch.delete(key);
}
}
示例12: getTimelineDomain
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
private static TimelineDomain getTimelineDomain(
DBIterator iterator, String domainId, byte[] prefix) throws IOException {
// Iterate over all the rows whose key starts with prefix to retrieve the
// domain information.
TimelineDomain domain = new TimelineDomain();
domain.setId(domainId);
boolean noRows = true;
for (; iterator.hasNext(); iterator.next()) {
byte[] key = iterator.peekNext().getKey();
if (!prefixMatches(prefix, prefix.length, key)) {
break;
}
if (noRows) {
noRows = false;
}
byte[] value = iterator.peekNext().getValue();
if (value != null && value.length > 0) {
if (key[prefix.length] == DESCRIPTION_COLUMN[0]) {
domain.setDescription(new String(value));
} else if (key[prefix.length] == OWNER_COLUMN[0]) {
domain.setOwner(new String(value));
} else if (key[prefix.length] == READER_COLUMN[0]) {
domain.setReaders(new String(value));
} else if (key[prefix.length] == WRITER_COLUMN[0]) {
domain.setWriters(new String(value));
} else if (key[prefix.length] == TIMESTAMP_COLUMN[0]) {
domain.setCreatedTime(readReverseOrderedLong(value, 0));
domain.setModifiedTime(readReverseOrderedLong(value, 8));
} else {
LOG.error("Unrecognized domain column: " + key[prefix.length]);
}
}
}
if (noRows) {
return null;
} else {
return domain;
}
}
示例13: loadEventStream
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
@Override
public List<Event> loadEventStream(UUID aggregateId) {
checkNotNull(aggregateId);
DBIterator iterator = null;
try {
iterator = eventDatabase.iterator();
iterator.seek(new Key(aggregateId).toBytes());
List<Event> events = new ArrayList<>();
boolean keepMoving = true;
while (keepMoving && iterator.hasNext()) {
Map.Entry<byte[], byte[]> entry = iterator.next();
Key key = Key.deserialize(entry.getKey());
if (!aggregateId.equals(key.id)) {
keepMoving = false;
} else {
events.add(deserializeEvent(entry.getValue(), key.schemaFingerprint));
}
}
return events;
} finally {
if (iterator != null) {
try {
iterator.close();
} catch (IOException e) {
logger.error("Error while closing LevelDB iterator", e);
}
}
}
}
示例14: DatabaseImpl
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public DatabaseImpl(String name) {
// Initialize Database
this.name = name;
Options options = new Options();
options.createIfMissing(true);
options.compressionType(CompressionType.NONE);
try {
logger.debug("Opening database");
File dbLocation = new File(System.getProperty("user.dir") + "/" +
SystemProperties.CONFIG.databaseDir() + "/");
File fileLocation = new File(dbLocation, name);
if(SystemProperties.CONFIG.databaseReset()) {
destroyDB(fileLocation);
}
logger.debug("Initializing new or existing database: '{}'", name);
db = factory.open(fileLocation, options);
// logger.debug("Showing database stats");
// String stats = DATABASE.getProperty("leveldb.stats");
// logger.debug(stats);
if (logger.isTraceEnabled()){
logger.trace("Dump for: {}", fileLocation.toString());
DBIterator iter = db.iterator();
while(iter.hasNext()){
byte[] key = iter.peekNext().getKey();
byte[] value = iter.peekNext().getValue();
logger.trace("key={}, value={}", Hex.toHexString(key), Hex.toHexString(value));
iter.next();
}
}
} catch (IOException ioe) {
logger.error(ioe.getMessage(), ioe);
throw new RuntimeException("Can't initialize database");
}
}
示例15: dumpKeys
import org.iq80.leveldb.DBIterator; //导入方法依赖的package包/类
public List<ByteArrayWrapper> dumpKeys() {
DBIterator iterator = getDb().iterator();
ArrayList<ByteArrayWrapper> keys = new ArrayList<>();
while (iterator.hasNext()) {
ByteArrayWrapper key = new ByteArrayWrapper(iterator.next().getKey());
keys.add(key);
}
Collections.sort((List<ByteArrayWrapper>) keys);
return keys;
}