Path: blob/main/SignalServiceKit/Storage/TSYapDatabaseObject.h
1 views
//1// Copyright 2017 Signal Messenger, LLC2// SPDX-License-Identifier: AGPL-3.0-only3//45@import Foundation;67NS_ASSUME_NONNULL_BEGIN89@class DBWriteTransaction;10@class SDSDatabaseStorage;1112@protocol SDSRecordDelegate1314- (void)updateRowId:(int64_t)rowId;1516@end1718#pragma mark -1920// TODO: Rename and/or merge with BaseModel.21@interface TSYapDatabaseObject : NSObject <SDSRecordDelegate>2223+ (NSString *)generateUniqueId;2425/**26* The unique identifier of the stored object27*/28@property (nonatomic, readonly) NSString *uniqueId;2930// This property should only ever be accesssed within a GRDB write transaction.31@property (atomic, readonly, nullable) NSNumber *grdbId;3233- (instancetype)init;3435/**36* Initializes a new database object with a unique identifier37*38* @param uniqueId Key used for the key-value store39*40* @return Initialized object41*/42- (instancetype)initWithUniqueId:(NSString *)uniqueId NS_DESIGNATED_INITIALIZER;4344- (instancetype)initWithGrdbId:(int64_t)grdbId uniqueId:(NSString *)uniqueId NS_DESIGNATED_INITIALIZER;4546- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;4748/// Encode the grdbId and uniqueId.49- (void)encodeIdsWithCoder:(NSCoder *)coder;5051/// Creates a copy and assigns the grdbId and uniqueId.52- (id)copyAndAssignIdsWithZone:(nullable NSZone *)zone;5354// These methods should only ever be called within a GRDB write transaction.55- (void)clearRowId;56// This method is used to facilitate a database object replacement. See:57// OWSRecoverableDecryptionPlaceholder.58- (void)replaceRowId:(int64_t)rowId uniqueId:(NSString *)uniqueId;5960#pragma mark -6162// GRDB TODO: As a perf optimization, we could only call these63// methods for certain kinds of models which we could64// detect at compile time.65@property (nonatomic, readonly) BOOL shouldBeSaved;6667#pragma mark - Data Store Write Hooks6869- (void)anyWillInsertWithTransaction:(DBWriteTransaction *)transaction;70- (void)anyDidInsertWithTransaction:(DBWriteTransaction *)transaction;71- (void)anyWillUpdateWithTransaction:(DBWriteTransaction *)transaction;72- (void)anyDidUpdateWithTransaction:(DBWriteTransaction *)transaction;73- (void)anyWillRemoveWithTransaction:(DBWriteTransaction *)transaction;74- (void)anyDidRemoveWithTransaction:(DBWriteTransaction *)transaction;7576@end7778NS_ASSUME_NONNULL_END798081