use of io.nuls.db.service.BatchOperation in project nuls by nuls-io.
the class LocalUtxoStorageServiceImpl method batchSaveAndDeleteUTXO.
@Override
public Result batchSaveAndDeleteUTXO(List<Entry<byte[], byte[]>> utxosToSave, List<byte[]> utxosToDelete) {
BatchOperation batch = dbService.createWriteBatch(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_COINDATA);
for (byte[] key : utxosToDelete) {
batch.delete(key);
}
for (Entry<byte[], byte[]> entry : utxosToSave) {
batch.put(entry.getKey(), entry.getValue());
}
Result batchResult = batch.executeBatch();
if (batchResult.isFailed()) {
return batchResult;
}
Result result = Result.getSuccess().setData(new Integer(utxosToSave.size() + utxosToDelete.size()));
if (result.isSuccess() && cacheMap != null) {
for (Entry<byte[], byte[]> entry : utxosToSave) {
cacheMap.put(new String(entry.getKey()), entry);
}
for (byte[] key : utxosToDelete) {
cacheMap.remove(new String(key));
}
}
return result;
}
use of io.nuls.db.service.BatchOperation in project nuls by nuls-io.
the class LevelDbDataSource method updateBatchInternal.
private void updateBatchInternal(Map<byte[], byte[]> rows) {
BatchOperation batchOperation = dbService.createWriteBatch(AREA);
for (Map.Entry<byte[], byte[]> entry : rows.entrySet()) {
if (entry.getValue() == null) {
batchOperation.delete(entry.getKey());
} else {
batchOperation.put(entry.getKey(), entry.getValue());
}
}
batchOperation.executeBatch();
}
Aggregations