DatabaseManager.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import <Foundation/Foundation.h>
  21. #import <CoreData/CoreData.h>
  22. #import "DatabaseContext.h"
  23. @interface DatabaseManager : NSObject
  24. @property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  25. @property (strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  26. @property (readonly) NSError *storeError;
  27. + (instancetype)dbManager;
  28. /**
  29. Get database context for the application.
  30. @param forBackgroundProcess YES means it will be create a private context
  31. */
  32. - (DatabaseContext *)getDatabaseContext:(BOOL)forBackgroundProcess;
  33. + (NSURL *)storeUrl;
  34. + (BOOL)storeExists;
  35. - (BOOL)storeRequiresMigration;
  36. - (BOOL)storeRequiresImport;
  37. - (NSError *)storeError;
  38. - (BOOL)canMigrateDB;
  39. - (void)doMigrateDB;
  40. - (void)copyImportedDatabase;
  41. - (void)eraseDB;
  42. - (BOOL)shouldUpdateProtection;
  43. - (void)updateProtection;
  44. - (void)disableBackupForDatabaseDirectory:(BOOL)disable;
  45. - (void)refreshDirtyObjectIDs:(NSDictionary *)changes intoContext:(NSManagedObjectContext *)context;
  46. - (void)refreshDirtyObjects;
  47. - (void)addDirtyObject:(NSManagedObject *)object;
  48. /**
  49. Replace database and external data with version in applicationDocuments/ThreemaDataOldVersion, for testing database migration.
  50. */
  51. - (BOOL)copyOldVersionOfDatabase;
  52. @end