OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[kcd/KCD.git] / KCD / ResourceHistoryDataStore.swift
index 3c9c23d..afbd510 100644 (file)
@@ -7,52 +7,23 @@
 //
 
 import Cocoa
+import Doutaku
 
-extension CoreDataIntormation {
-    static let resourceHistory = CoreDataIntormation(
-        modelName: "ResourceHistory",
-        storeFileName: "ResourceHistory.storedata",
-        storeOptions:[NSMigratePersistentStoresAutomaticallyOption: true,
-                      NSInferMappingModelAutomaticallyOption: true],
-        storeType: NSSQLiteStoreType,
-        deleteAndRetry: false
-    )
-}
-extension CoreDataCore {
-    static let resourceHistory = CoreDataCore(.resourceHistory)
-}
-extension Entity {
-    static let resource = Entity(name: "Resource")
-}
-
-class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
-    static var `default` = ResourceHistoryDataStore(type: .reader)
-    class func oneTimeEditor() -> ResourceHistoryDataStore {
-        return ResourceHistoryDataStore(type: .editor)
-    }
+final class ResourceHistoryDataStore: CoreDataManager {
+    
+    static let core = CoreDataCore(CoreDataConfiguration("ResourceHistory"))
+    
+    static let `default` = ResourceHistoryDataStore(type: .reader)
     
     required init(type: CoreDataManagerType) {
-        managedObjectContext =
-            type == .reader ? core.parentManagedObjectContext
-                : core.editorManagedObjectContext()
+        
+        context = ResourceHistoryDataStore.context(for: type)
     }
+    
     deinit {
-        saveActionCore()
+        
+        save(errorHandler: presentOnMainThread)
     }
     
-    let core = CoreDataCore.resourceHistory
-    var managedObjectContext: NSManagedObjectContext
-}
-
-extension ResourceHistoryDataStore {
-    func resources(in minites: [Int], older: Date) -> [KCResource] {
-        let p = NSPredicate(format: "minute IN %@ AND date < %@", minites, older as NSDate)
-        guard let a = try? objects(with: .resource, predicate: p),
-            let resources = a as? [KCResource]
-            else { return [] }
-        return resources
-    }
-    func cerateResource() -> KCResource? {
-        return insertNewObject(for: .resource) as? KCResource
-    }
+    let context: NSManagedObjectContext
 }