|
15 | 15 | */ |
16 | 16 | @interface NSManagedObjectContext (ActiveRecord) |
17 | 17 |
|
18 | | -+ (NSManagedObjectContext *)defaultContext; |
19 | | -+ (void)setDefaultContext:(NSManagedObjectContext *)context; |
20 | | -+ (NSManagedObjectContext *)contextForCurrentThread; |
| 18 | ++ (NSManagedObjectContext *)contextForMainThread; |
| 19 | ++ (NSManagedObjectContext *)contextForBackgroundThread; |
21 | 20 |
|
22 | 21 | @end |
23 | 22 |
|
|
27 | 26 | */ |
28 | 27 | @interface NSManagedObject (ActiveRecord) |
29 | 28 |
|
30 | | -/** |
31 | | - * The NSEntityDescription for the Subclass |
32 | | - * defaults to the subclass className, may be overridden |
33 | | - */ |
34 | | -+ (NSEntityDescription*)MR_entity; |
35 | | - |
36 | | -/** |
37 | | - * Returns an initialized NSFetchRequest for the entity, with no predicate |
38 | | - */ |
39 | | -+ (NSFetchRequest*)MR_fetchRequest; |
40 | | - |
41 | 29 | /** |
42 | 30 | * Fetches all objects from the persistent store identified by the fetchRequest |
43 | 31 | */ |
44 | | -+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest; |
| 32 | ++ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest inContext:(NSManagedObjectContext*)context; |
45 | 33 |
|
46 | 34 | /** |
47 | 35 | * Retrieves the number of objects that would be retrieved by the fetchRequest, |
48 | 36 | * if executed |
49 | 37 | */ |
50 | | -+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest; |
51 | | - |
52 | | -/** |
53 | | - * Fetches all objects from the persistent store via a set of fetch requests and |
54 | | - * returns all results in a single array. |
55 | | - */ |
56 | | -+ (NSArray*)objectsWithFetchRequests:(NSArray*)fetchRequests; |
| 38 | ++ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest inContext:(NSManagedObjectContext*)context; |
57 | 39 |
|
58 | 40 | /** |
59 | 41 | * Fetches the first object identified by the fetch request. A limit of one will be |
60 | 42 | * applied to the fetch request before dispatching. |
61 | 43 | */ |
62 | | -+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest; |
| 44 | ++ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest inContext:(NSManagedObjectContext*)context; |
63 | 45 |
|
64 | 46 | /** |
65 | 47 | * Fetches all objects from the persistent store by constructing a fetch request and |
66 | 48 | * applying the predicate supplied. A short-cut for doing filtered searches on the objects |
67 | 49 | * of this class under management. |
68 | 50 | */ |
69 | | -+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate; |
| 51 | ++ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate inContext:(NSManagedObjectContext*)context; |
70 | 52 |
|
71 | 53 | /** |
72 | 54 | * Fetches the first object matching a predicate from the persistent store. A fetch request |
73 | 55 | * will be constructed for you and a fetch limit of 1 will be applied. |
74 | 56 | */ |
75 | | -+ (id)objectWithPredicate:(NSPredicate*)predicate; |
| 57 | ++ (id)objectWithPredicate:(NSPredicate*)predicate inContext:(NSManagedObjectContext*)context; |
76 | 58 |
|
77 | 59 | /** |
78 | 60 | * Fetches all managed objects of this class from the persistent store as an array |
79 | 61 | */ |
80 | | -+ (NSArray*)allObjects; |
| 62 | ++ (NSArray*)allObjectsInContext:(NSManagedObjectContext*)context; |
81 | 63 |
|
82 | 64 | /** |
83 | 65 | * Returns a count of all managed objects of this class in the persistent store. On |
84 | 66 | * error, will populate the error argument |
85 | 67 | */ |
86 | | -+ (NSUInteger)count:(NSError**)error; |
87 | | - |
88 | | -/** |
89 | | - * Returns a count of all managed objects of this class in the persistent store. Deprecated |
90 | | - * use the error form above |
91 | | - * |
92 | | - * @deprecated |
93 | | - */ |
94 | | -+ (NSUInteger)count DEPRECATED_ATTRIBUTE; |
| 68 | ++ (NSUInteger)countInContext:(NSManagedObjectContext*)context error:(NSError**)error; |
95 | 69 |
|
96 | 70 | /** |
97 | 71 | * Creates a new managed object and inserts it into the managedObjectContext. |
98 | 72 | */ |
99 | | -+ (id)object; |
| 73 | ++ (id)objectInContext:(NSManagedObjectContext *)context; |
100 | 74 |
|
101 | 75 | /** |
102 | 76 | * Returns YES when an object has not been saved to the managed object context yet |
103 | 77 | */ |
104 | 78 | - (BOOL)isNew; |
105 | 79 |
|
106 | | -/** |
107 | | - Finds the instance of the receiver's entity with the given value for the primary key attribute |
108 | | - in the managed object context for the current thread. |
109 | | -
|
110 | | - @param primaryKeyValue The value for the receiving entity's primary key attribute. |
111 | | - @return The object with the primary key attribute equal to the given value or nil. |
112 | | - */ |
113 | | -+ (id)findByPrimaryKey:(id)primaryKeyValue; |
114 | | - |
115 | 80 | /** |
116 | 81 | Finds the instance of the receiver's entity with the given value for the primary key attribute in |
117 | 82 | the given managed object context. |
|
124 | 89 |
|
125 | 90 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
126 | 91 |
|
127 | | -+ (NSManagedObjectContext*)currentContext; |
128 | | - |
129 | 92 | + (void)handleErrors:(NSError *)error; |
130 | 93 |
|
131 | | -+ (NSArray *)executeFetchRequest:(NSFetchRequest *)request; |
132 | 94 | + (NSArray *)executeFetchRequest:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context; |
133 | | -+ (NSFetchRequest *)createFetchRequest; |
134 | 95 | + (NSFetchRequest *)createFetchRequestInContext:(NSManagedObjectContext *)context; |
135 | | -+ (NSEntityDescription *)entityDescription; |
136 | 96 | + (NSEntityDescription *)entityDescriptionInContext:(NSManagedObjectContext *)context; |
137 | | -+ (NSArray *)propertiesNamed:(NSArray *)properties; |
138 | 97 |
|
139 | | -+ (id)createEntity; |
140 | 98 | + (id)createInContext:(NSManagedObjectContext *)context; |
141 | | -- (BOOL)deleteEntity; |
142 | 99 | - (BOOL)deleteInContext:(NSManagedObjectContext *)context; |
143 | 100 |
|
144 | | -+ (BOOL)truncateAll; |
145 | 101 | + (BOOL)truncateAllInContext:(NSManagedObjectContext *)context; |
146 | 102 |
|
147 | 103 | + (NSArray *)ascendingSortDescriptors:(id)attributesToSortBy, ...; |
148 | 104 | + (NSArray *)descendingSortDescriptors:(id)attributesToSortyBy, ...; |
149 | 105 |
|
150 | | -+ (NSNumber *)numberOfEntities; |
151 | 106 | + (NSNumber *)numberOfEntitiesWithContext:(NSManagedObjectContext *)context; |
152 | | -+ (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm; |
153 | 107 | + (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
154 | 108 |
|
155 | | -+ (BOOL) hasAtLeastOneEntity; |
156 | 109 | + (BOOL) hasAtLeastOneEntityInContext:(NSManagedObjectContext *)context; |
157 | 110 |
|
158 | | -+ (NSFetchRequest *)requestAll; |
159 | 111 | + (NSFetchRequest *)requestAllInContext:(NSManagedObjectContext *)context; |
160 | | -+ (NSFetchRequest *)requestAllWhere:(NSString *)property isEqualTo:(id)value; |
161 | 112 | + (NSFetchRequest *)requestAllWhere:(NSString *)property isEqualTo:(id)value inContext:(NSManagedObjectContext *)context; |
162 | | -+ (NSFetchRequest *)requestFirstWithPredicate:(NSPredicate *)searchTerm; |
163 | 113 | + (NSFetchRequest *)requestFirstWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
164 | | -+ (NSFetchRequest *)requestFirstByAttribute:(NSString *)attribute withValue:(id)searchValue; |
165 | 114 | + (NSFetchRequest *)requestFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context; |
166 | | -+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending; |
167 | 115 | + (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; |
168 | | -+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm; |
169 | 116 | + (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
170 | 117 |
|
171 | | -+ (NSArray *)findAll; |
172 | 118 | + (NSArray *)findAllInContext:(NSManagedObjectContext *)context; |
173 | | -+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending; |
174 | 119 | + (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; |
175 | | -+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm; |
176 | 120 | + (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
177 | | -+ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm; |
178 | 121 | + (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
179 | 122 |
|
180 | | -+ (NSNumber *)maxValueFor:(NSString *)property; |
181 | | -+ (id) objectWithMinValueFor:(NSString *)property; |
182 | | -+ (id) objectWithMinValueFor:(NSString *)property inContext:(NSManagedObjectContext *)context; |
183 | | - |
184 | | -+ (id)findFirst; |
185 | 123 | + (id)findFirstInContext:(NSManagedObjectContext *)context; |
186 | | -+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm; |
187 | 124 | + (id)findFirstWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context; |
188 | | -+ (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending; |
189 | 125 | + (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; |
190 | | -+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes; |
191 | 126 | + (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes inContext:(NSManagedObjectContext *)context; |
192 | | -+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending andRetrieveAttributes:(id)attributes, ...; |
193 | 127 | + (id)findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context andRetrieveAttributes:(id)attributes, ...; |
194 | 128 |
|
195 | | -+ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue; |
196 | 129 | + (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context; |
197 | | -+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue; |
198 | 130 | + (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context; |
199 | | -+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending; |
200 | 131 | + (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; |
201 | 132 |
|
202 | 133 | #if TARGET_OS_IPHONE |
203 | 134 |
|
204 | | -+ (NSFetchedResultsController *)fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath; |
205 | 135 | + (NSFetchedResultsController *)fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath inContext:(NSManagedObjectContext *)context; |
206 | 136 |
|
207 | | -+ (NSFetchedResultsController *)fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group; |
208 | 137 | + (NSFetchedResultsController *)fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group inContext:(NSManagedObjectContext *)context; |
209 | 138 |
|
210 | | -+ (NSFetchedResultsController *)fetchRequestAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending; |
211 | 139 | + (NSFetchedResultsController *)fetchRequestAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; |
212 | 140 |
|
213 | 141 | #endif |
|
0 commit comments