本文整理匯總了Java中org.iq80.leveldb.DB.createWriteBatch方法的典型用法代碼示例。如果您正苦於以下問題:Java DB.createWriteBatch方法的具體用法?Java DB.createWriteBatch怎麽用?Java DB.createWriteBatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.iq80.leveldb.DB
的用法示例。
在下文中一共展示了DB.createWriteBatch方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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();
}
}
示例3: put
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static <T extends D_Level> void put(String cluster, Class<T> clazz, List<T> data) throws IOException {
DB db = getDB(path(cluster, clazz));
WriteBatch bitch = db.createWriteBatch();
try {
for (T t : data) {
bitch.put(t.key().getBytes(), t.value());
}
db.write(bitch, new WriteOptions().sync(true));
} finally {
bitch.close();
}
}
示例4: EzLevelDbBatch
import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public EzLevelDbBatch(DB db, Serde<H> hashKeySerde, Serde<R> rangeKeySerde,
Serde<V> valueSerde) {
this.db = db;
this.writeBatch = db.createWriteBatch();
this.hashKeySerde = hashKeySerde;
this.rangeKeySerde = rangeKeySerde;
this.valueSerde = valueSerde;
}