putMeta method
Updates the metadata for key without touching its value.
Returns the commit-log sequence number assigned to this
write, or null if no sequence number was produced.
Implementation
@override
Future<int?> putMeta(String key, AtMetaData? metadata) async {
key = key.toLowerCase();
try {
String hive_key = HiveKeyStoreHelper.prepareKey(key);
AtData? existingData;
if (await exists(key)) {
existingData = await get(key);
}
// putMeta is intended to updates only the metadata of a key.
// So, fetch the value from the existing key and set the same value.
AtData newData = existingData ?? AtData();
newData.metaData = AtMetadataBuilder(
newAtMetaData: metadata!,
existingMetaData: existingData?.metaData,
atSign: atSign)
.build();
await getBox().put(hive_key, newData);
_updateMetadataCache(key, newData.metaData);
// `_commitLog` is null on a commit-log-free keystore — the write
// still succeeds, it just produces no sequence number.
var result = await _commitLog?.commit(hive_key, CommitOp.UPDATE_META);
_changesController
.add(existingData == null ? KeyAdded(key) : KeyUpdated(key));
return result;
} on HiveError catch (error) {
logger.severe('HiveAtKeyValueStore get error: $error');
await _restartHiveBox(error);
throw DataStoreException(error.message);
}
}