commit method

  1. @override
  2. @server
Future<int?> commit(
  1. String key,
  2. CommitOp operation
)
override

Creates a new entry with key, operation and adds to the commit log with key - commitId and value - CommitEntry returns the sequence number corresponding to the new commit throws DataStoreException if there is an exception writing to hive box

Implementation

@override
@server
Future<int?> commit(String key, CommitOp operation) async {
  // If key starts with "public:__", it is a public hidden key which gets synced
  // between cloud and local secondary. So increment commitId.
  // If key starts with "public:_" it is a public hidden key but does not get synced.
  // So return -1.
  // The private: and privatekey: are not synced. so return -1.
  // The key that starts with 'local:' are the local keys that do not sync between the
  // client and server. Hence do not add to commit log.
  if (!key.startsWith('public:__') &&
      (key.startsWith(RegExp('private:|privatekey:|public:_|local:')))) {
    return -1;
  }
  int result;
  key = Utf7.decode(key);
  var entry = CommitEntry(
      key, operation, DateTime.now().toUtcMillisecondsPrecision());
  try {
    result = await _commitLogKeyStore.add(entry);
  } on Exception catch (e) {
    throw DataStoreException(
        'Exception adding to commit log:${e.toString()}');
  } on HiveError catch (e) {
    throw DataStoreException(
        'Hive error adding to commit log:${e.toString()}');
  }
  return result;
}