GNUstep Core Data  0.1
NSManagedObjectContext.h
00001 /* Interface of the NSManagedObjectContext class for the GNUstep
00002    Core Data framework.
00003    Copyright (C) 2005 Free Software Foundation, Inc.
00004 
00005    Written by:  Saso Kiselkov <diablos@manga.sk>
00006    Date: August 2005
00007 
00008    This file is part of the GNUstep Core Data framework.
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Lesser General Public License for more details.
00019 
00020    You should have received a copy of the GNU Lesser General Public
00021    License along with this library; if not, write to the Free
00022    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
00023  */
00024 
00025 #ifndef _NSManagedObjectContext_h_
00026 #define _NSManagedObjectContext_h_
00027 
00028 #import <Foundation/NSObject.h>
00029 #import <Foundation/NSLock.h>
00030 #import <Foundation/NSDate.h>
00031 
00032 @class NSArray, NSString, NSError, NSSet, NSMutableSet;
00033 @class NSUndoManager;
00034 @class NSFetchRequest, NSManagedObject, NSManagedObjectID,
00035   NSPersistentStoreCoordinator;
00036 
00037 extern id NSErrorMergePolicy;
00038 extern id NSMergeByPropertyStoreTrumpMergePolicy;
00039 extern id NSMergeByPropertyObjectTrumpMergePolicy;
00040 extern id NSOverwriteMergePolicy;
00041 extern id NSRollbackMergePolicy;
00042 
00043 @interface NSManagedObjectContext : NSObject <NSCoding, NSLocking>
00044 {
00045   NSRecursiveLock * _lock;
00046 
00047   NSPersistentStoreCoordinator * _storeCoordinator;
00048 
00049   // objects that are registered with the context
00050   NSMutableSet * _registeredObjects;
00051 
00052   // objects inserted into the context since the last save
00053   NSMutableSet * _insertedObjects;
00054   // objects updated since the last save
00055   NSMutableSet * _updatedObjects;
00056   // objects deleted since the last save
00057   NSMutableSet * _deletedObjects;
00058 
00059   BOOL _propagesDeletesAtEventEnd;
00060   BOOL _retainsRegisteredObjects;
00061 
00062   NSUndoManager * _undoManager;
00063   id _mergePolicy;
00064 
00065   NSTimeInterval _stalenessInterval;
00066 }
00067 
00068 // Getting and setting the persistent store coordinator.
00069 - (NSPersistentStoreCoordinator *) persistentStoreCoordinator;
00070 - (void) setPersistentStoreCoordinator:
00071   (NSPersistentStoreCoordinator *) aCoordinator;
00072 
00073 // Undo/redo control.
00074 - (NSUndoManager *) undoManager;
00075 - (void) setUndoManager: (NSUndoManager *) aManager;
00076 - (void) undo;
00077 - (void) redo;
00078 - (void) reset;
00079 - (void) rollback;
00080 - (BOOL) save: (NSError **) anErrorPointer;
00081 - (BOOL) hasChanges;
00082 
00083 // Registering and fetching objects.
00084 - (NSManagedObject *) objectRegisteredForID: (NSManagedObjectID *) anObjectID;
00085 - (NSManagedObject *) objectWithID: (NSManagedObjectID *) anObjectID;
00086 - (NSArray *) executeFetchRequest: (NSFetchRequest *) aRequest
00087                             error: (NSError **) anErrorPointer;
00088 
00089 // Managed object management.
00090 - (void) insertObject: (NSManagedObject *) anObject;
00091 - (void) deleteObject: (NSManagedObject *) anObject;
00092 - (void) assignObject: (id) anObject toPersistentStore: (id) aStore;
00093 - (void) detectConflictsForObject: (NSManagedObject *) anObject;
00094 - (void) refreshObject: (NSManagedObject *) anObject
00095           mergeChanges: (BOOL) mergeChanges;
00096 - (void) processPendingChanges;
00097 - (NSSet *) insertedObjects;
00098 - (NSSet *) updatedObjects;
00099 - (NSSet *) deletedObjects;
00100 - (NSSet *) registeredObjects;
00101 
00102 // Locking (NSLocking protocol).
00103 - (void) lock;
00104 - (void) unlock;
00105 - (BOOL) tryLock;
00106 
00107 // Controlling delete propagation.
00108 - (BOOL) propagatesDeletesAtEndOfEvent;
00109 - (void) setPropagatesDeletesAtEndOfEvent: (BOOL) flag;
00110 
00111 // Controlling whether registered objects are retained.
00112 - (BOOL) retainsRegisteredObjects;
00113 - (void) setRetainsRegisteredObjects: (BOOL) flag;
00114 
00115 // Controlling the staleness interval.
00116 - (NSTimeInterval) stalenessInterval;
00117 - (void) setStalenessInterval: (NSTimeInterval) aTimeInterval;
00118 
00119 // Controlling the merge policy.
00120 - (id) mergePolicy;
00121 - (void) setMergePolicy: (id) aPolicy;
00122 
00123 @end
00124 
00125 // Notifications.
00126 extern NSString * const NSManagedObjectContextObjectsDidChangeNotification;
00127 extern NSString * const NSManagedObjectContextDidSaveNotification;
00128 
00129 extern NSString * const NSInsertedObjectsKey;
00130 extern NSString * const NSUpdatedObjectsKey;
00131 extern NSString * const NSDeletedObjectsKey;
00132 
00133 #endif // _NSManagedObjectContext_h_