// // RKManagedObjectStore.h // RestKit // // Created by Blake Watters on 9/22/09. // Copyright (c) 2009-2012 RestKit. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import #import "RKEntityMapping.h" #import "RKManagedObjectCaching.h" @class RKManagedObjectStore; /** * Notifications */ extern NSString * const RKManagedObjectStoreDidFailSaveNotification; /////////////////////////////////////////////////////////////////// @protocol RKManagedObjectStoreDelegate @optional - (void)managedObjectStore:(RKManagedObjectStore *)objectStore didFailToCreatePersistentStoreCoordinatorWithError:(NSError *)error; - (void)managedObjectStore:(RKManagedObjectStore *)objectStore didFailToDeletePersistentStore:(NSString *)pathToStoreFile error:(NSError *)error; - (void)managedObjectStore:(RKManagedObjectStore *)objectStore didFailToCopySeedDatabase:(NSString *)seedDatabase error:(NSError *)error; - (void)managedObjectStore:(RKManagedObjectStore *)objectStore didFailToSaveContext:(NSManagedObjectContext *)context error:(NSError *)error exception:(NSException *)exception; @end /////////////////////////////////////////////////////////////////// @interface RKManagedObjectStore : NSObject ///----------------------------------------------------------------------------- /// @name Accessing the Default Object Store ///----------------------------------------------------------------------------- + (RKManagedObjectStore *)defaultStore; + (void)setDefaultStore:(RKManagedObjectStore *)managedObjectStore; ///----------------------------------------------------------------------------- /// @name Deleting Store Files ///----------------------------------------------------------------------------- /** Deletes the SQLite file backing an RKManagedObjectStore instance at a given path. @param path The complete path to the store file to delete. */ + (void)deleteStoreAtPath:(NSString *)path; /** Deletes the SQLite file backing an RKManagedObjectStore instance with a given filename within the application data directory. @param filename The name of the file within the application data directory backing a managed object store. */ + (void)deleteStoreInApplicationDataDirectoryWithFilename:(NSString *)filename; ///----------------------------------------------------------------------------- /// @name Initializing an Object Store ///----------------------------------------------------------------------------- /** * Initialize a new managed object store with a SQLite database with the filename specified */ + (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename; /** * Initialize a new managed object store backed by a SQLite database with the specified filename. * If a seed database name is provided and no existing database is found, initialize the store by * copying the seed database from the main bundle. If the managed object model provided is nil, * all models will be merged from the main bundle for you. */ + (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate; /** * Initialize a new managed object store backed by a SQLite database with the specified filename, * in the specified directory. If no directory is specified, will use the app's Documents * directory. If a seed database name is provided and no existing database is found, initialize * the store by copying the seed database from the main bundle. If the managed object model * provided is nil, all models will be merged from the main bundle for you. */ + (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)directory usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate; ///----------------------------------------------------------------------------- /// @name Retrieving Details about the Object Store ///----------------------------------------------------------------------------- // The filename of the database backing this object store @property (nonatomic, readonly) NSString *storeFilename; // The full path to the database backing this object store @property (nonatomic, readonly) NSString *pathToStoreFile; // Core Data @property (nonatomic, readonly) NSManagedObjectModel *managedObjectModel; @property (nonatomic, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; ///----------------------------------------------------------------------------- /// @name Configuring Delegate and Default Cache Strategy ///----------------------------------------------------------------------------- // The delegate for this object store @property (nonatomic, assign) id delegate; /** */ @property (nonatomic, retain) id cacheStrategy; ///----------------------------------------------------------------------------- /// @name Retrieving Managed Object Contexts ///----------------------------------------------------------------------------- @property (nonatomic, retain, readonly) NSManagedObjectContext *primaryManagedObjectContext; @property (nonatomic, retain, readonly) NSManagedObjectContext *mainQueueManagedObjectContext; - (NSManagedObjectContext *)newChildManagedObjectContextWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType; ///----------------------------------------------------------------------------- /// @name Working with the Primary Managed Object Context ///----------------------------------------------------------------------------- /** * Save the current contents of the managed object store */ - (BOOL)save:(NSError **)error; // TODO: Do we want this? /** * This deletes and recreates the managed object context and * persistent store, effectively clearing all data */ - (void)deletePersistentStoreUsingSeedDatabaseName:(NSString *)seedFile; - (void)deletePersistentStore; @end @interface RKManagedObjectStore (Deprecations) + (RKManagedObjectStore *)defaultObjectStore DEPRECATED_ATTRIBUTE; + (void)setDefaultObjectStore:(RKManagedObjectStore *)objectStore DEPRECATED_ATTRIBUTE; - (id)initWithStoreFilename:(NSString *)storeFilename DEPRECATED_ATTRIBUTE; - (NSManagedObjectContext *)newManagedObjectContext DEPRECATED_ATTRIBUTE; - (NSManagedObjectContext *)managedObjectContextForCurrentThread DEPRECATED_ATTRIBUTE; - (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID DEPRECATED_ATTRIBUTE; - (NSArray *)objectsWithIDs:(NSArray *)objectIDs DEPRECATED_ATTRIBUTE; @end