Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Storage/TSYapDatabaseObject.h
1 views
1
//
2
// Copyright 2017 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
@import Foundation;
7
8
NS_ASSUME_NONNULL_BEGIN
9
10
@class DBWriteTransaction;
11
@class SDSDatabaseStorage;
12
13
@protocol SDSRecordDelegate
14
15
- (void)updateRowId:(int64_t)rowId;
16
17
@end
18
19
#pragma mark -
20
21
// TODO: Rename and/or merge with BaseModel.
22
@interface TSYapDatabaseObject : NSObject <SDSRecordDelegate>
23
24
+ (NSString *)generateUniqueId;
25
26
/**
27
* The unique identifier of the stored object
28
*/
29
@property (nonatomic, readonly) NSString *uniqueId;
30
31
// This property should only ever be accesssed within a GRDB write transaction.
32
@property (atomic, readonly, nullable) NSNumber *grdbId;
33
34
- (instancetype)init;
35
36
/**
37
* Initializes a new database object with a unique identifier
38
*
39
* @param uniqueId Key used for the key-value store
40
*
41
* @return Initialized object
42
*/
43
- (instancetype)initWithUniqueId:(NSString *)uniqueId NS_DESIGNATED_INITIALIZER;
44
45
- (instancetype)initWithGrdbId:(int64_t)grdbId uniqueId:(NSString *)uniqueId NS_DESIGNATED_INITIALIZER;
46
47
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
48
49
/// Encode the grdbId and uniqueId.
50
- (void)encodeIdsWithCoder:(NSCoder *)coder;
51
52
/// Creates a copy and assigns the grdbId and uniqueId.
53
- (id)copyAndAssignIdsWithZone:(nullable NSZone *)zone;
54
55
// These methods should only ever be called within a GRDB write transaction.
56
- (void)clearRowId;
57
// This method is used to facilitate a database object replacement. See:
58
// OWSRecoverableDecryptionPlaceholder.
59
- (void)replaceRowId:(int64_t)rowId uniqueId:(NSString *)uniqueId;
60
61
#pragma mark -
62
63
// GRDB TODO: As a perf optimization, we could only call these
64
// methods for certain kinds of models which we could
65
// detect at compile time.
66
@property (nonatomic, readonly) BOOL shouldBeSaved;
67
68
#pragma mark - Data Store Write Hooks
69
70
- (void)anyWillInsertWithTransaction:(DBWriteTransaction *)transaction;
71
- (void)anyDidInsertWithTransaction:(DBWriteTransaction *)transaction;
72
- (void)anyWillUpdateWithTransaction:(DBWriteTransaction *)transaction;
73
- (void)anyDidUpdateWithTransaction:(DBWriteTransaction *)transaction;
74
- (void)anyWillRemoveWithTransaction:(DBWriteTransaction *)transaction;
75
- (void)anyDidRemoveWithTransaction:(DBWriteTransaction *)transaction;
76
77
@end
78
79
NS_ASSUME_NONNULL_END
80
81