add internal utilities to force checkpoint operations on SQLite

This commit is contained in:
John Rommel Estropia
2017-07-01 16:45:11 +09:00
parent 809aa4ff96
commit 3096cb784c
3 changed files with 26 additions and 0 deletions

View File

@@ -86,6 +86,11 @@ public final class LegacySQLiteStore: LocalStorage {
public var localStorageOptions: LocalStorageOptions
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
fatalError()
}
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
fatalError()

View File

@@ -205,6 +205,22 @@ public final class SQLiteStore: LocalStorage {
return storeOptions
}
/**
Called by the `DataStack` to perform checkpoint operations on the storage. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE to force a checkpoint.
*/
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in
try coordinator.addPersistentStore(
ofType: type(of: self).storeType,
configurationName: self.configuration,
at: fileURL,
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
)
}
}
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
*/

View File

@@ -141,6 +141,11 @@ public protocol LocalStorage: StorageInterface {
*/
func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]?
/**
Called by the `DataStack` to perform checkpoint operations on the storage. (SQLite stores for example, can convert the database's WAL journaling mode to DELETE to force a checkpoint)
*/
func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
*/