本文整理汇总了Java中org.iq80.leveldb.WriteOptions类的典型用法代码示例。如果您正苦于以下问题:Java WriteOptions类的具体用法?Java WriteOptions怎么用?Java WriteOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteOptions类属于org.iq80.leveldb包,在下文中一共展示了WriteOptions类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replace
import org.iq80.leveldb.WriteOptions; //导入依赖的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.WriteOptions; //导入依赖的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.WriteOptions; //导入依赖的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: checkStartTimeInDb
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
/**
* Checks db for start time and returns it if it exists. If it doesn't
* exist, writes the suggested start time (if it is not null). This is
* only called when the start time is not found in the cache,
* so it adds it back into the cache if it is found. Should only be called
* when a lock has been obtained on the entity.
*/
private StartAndInsertTime checkStartTimeInDb(EntityIdentifier entity,
Long suggestedStartTime) throws IOException {
StartAndInsertTime startAndInsertTime = null;
// create lookup key for start time
byte[] b = createStartTimeLookupKey(entity.getId(), entity.getType());
// retrieve value for key
byte[] v = db.get(b);
if (v == null) {
// start time doesn't exist in db
if (suggestedStartTime == null) {
return null;
}
startAndInsertTime = new StartAndInsertTime(suggestedStartTime,
System.currentTimeMillis());
// write suggested start time
v = new byte[16];
writeReverseOrderedLong(suggestedStartTime, v, 0);
writeReverseOrderedLong(startAndInsertTime.insertTime, v, 8);
WriteOptions writeOptions = new WriteOptions();
writeOptions.sync(true);
db.put(b, v, writeOptions);
} else {
// found start time in db, so ignore suggested start time
startAndInsertTime = new StartAndInsertTime(readReverseOrderedLong(v, 0),
readReverseOrderedLong(v, 8));
}
startTimeWriteCache.put(entity, startAndInsertTime);
startTimeReadCache.put(entity, startAndInsertTime.startTime);
return startAndInsertTime;
}
示例5: store
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
@Override
public Future<Variable> store(final Variable variable)
{
checkNotNull(variable, "variable is null");
checkState(!closed.get(), "already closed");
checkState(variable instanceof JVariable, "can not process native variable, use JVariable");
final JVariable v = (JVariable) variable;
return executor.submit(new Callable<Variable>() {
@Override
public Variable call() throws Exception
{
final WriteOptions writeOptions = new WriteOptions();
writeOptions.sync(true);
final String internedName = v.getName().intern();
synchronized (internedName) {
final JVariable current = load(internedName);
if (current == null || current.getUuid().equals(v.getUuid())) {
final JVariable update = new JVariable(internedName, v.value());
final WriteBatch writeBatch = db.createWriteBatch();
writeBatch.delete(bytes(internedName));
writeBatch.put(bytes(internedName), update.getEntry().toByteArray());
db.write(writeBatch, writeOptions);
return update;
}
else {
return null;
}
}
}
});
}
示例6: expunge
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
@Override
public Future<Boolean> expunge(final Variable variable)
{
checkNotNull(variable, "variable is null");
checkState(!closed.get(), "already closed");
checkState(variable instanceof JVariable, "can not process native variable, use JVariable");
final JVariable v = (JVariable) variable;
return executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception
{
final WriteOptions writeOptions = new WriteOptions();
writeOptions.sync(true);
final String internedName = v.getName().intern();
synchronized (internedName) {
final JVariable current = load(internedName);
if (current != null && current.getUuid().equals(v.getUuid())) {
db.delete(bytes(internedName));
return Boolean.TRUE;
}
else {
return Boolean.FALSE;
}
}
}
});
}
示例7: deleteSpentTxOutputs
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
/**
* Deletes spent transaction outputs that are older than the maximum transaction age
*
* @throws BlockStoreException Unable to delete spent transaction outputs
*/
@Override
public void deleteSpentTxOutputs() throws BlockStoreException {
long ageLimit = chainTime - MAX_TX_AGE;
int txPurged = 0;
List<byte[]> purgeList = new LinkedList<>();
synchronized(lock) {
try {
//
// Delete spent transaction outputs
//
log.info("Deleting spent transaction outputs");
try (DBIterator it = dbTxSpent.iterator()) {
it.seekToFirst();
while (it.hasNext()) {
Entry<byte[], byte[]> dbEntry = it.next();
long timeSpent = getLong(dbEntry.getValue());
if (timeSpent < ageLimit) {
purgeList.add(dbEntry.getKey());
txPurged++;
}
}
}
WriteOptions options = new WriteOptions();
options.sync(false);
for (int i=0; i<purgeList.size(); i++) {
dbTxSpent.delete(purgeList.get(i), options);
dbTxOutputs.delete(purgeList.get(i), options);
}
log.info(String.format("%,d spent transaction outputs deleted", txPurged));
} catch (DBException | IOException exc) {
log.error("Unable to remove spent transactions", exc);
throw new BlockStoreException("Unable to remove spent transactions");
}
}
}
示例8: getWriteOptions
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
public WriteOptions getWriteOptions() {
WriteOptions options = new WriteOptions();
options.sync(sync);
return options;
}
示例9: delete
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
@Override
public Snapshot delete(byte[] arg0, WriteOptions arg1)
throws DBException {
// TODO Auto-generated method stub
return null;
}
示例10: put
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
@Override
public Snapshot put(byte[] arg0, byte[] arg1, WriteOptions arg2)
throws DBException {
// TODO Auto-generated method stub
return null;
}
示例11: write
import org.iq80.leveldb.WriteOptions; //导入依赖的package包/类
@Override
public Snapshot write(WriteBatch arg0, WriteOptions arg1)
throws DBException {
// TODO Auto-generated method stub
return null;
}