1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.control;
20
21 import java.util.List;
22 import java.util.Map;
23
24 import net.wotonomy.foundation.NSArray;
25
26 /***
27 * EOObjectStore defines an object repository that tracks
28 * object creations, deletions, and updates made by
29 * EOEditingContexts. <br><br>
30 *
31 * A concrete implementation would probably write these
32 * changes to some kind of persistent storage, like a
33 * database. <br><br>
34 *
35 * EOEditingContext is itself a subclass of EOObjectStore
36 * that requires an EOObjectStore parent for committing
37 * its changes. This means that EOEditingContexts can
38 * use other EOEditingContexts as their parent, but there
39 * still must exist an EOObjectStore as the root of the
40 * editing graph.
41 *
42 * @author michael@mpowers.net
43 * @author $Author: cgruber $
44 * @version $Revision: 894 $
45 */
46 public abstract class EOObjectStore
47 {
48 /***
49 * Key for the user info of ObjectsChangedInStoreNotifications.
50 * The key should retrieve an array of deleted EOGlobalIDs.
51 */
52 public static final String DeletedKey = "deleted";
53
54 /***
55 * Key for the user info of ObjectsChangedInStoreNotifications.
56 * The key should retrieve an array of inserted EOGlobalIDs.
57 */
58 public static final String InsertedKey = "inserted";
59
60 /***
61 * Key for the user info of ObjectsChangedInStoreNotifications.
62 * The key should retrieve an array of updated EOGlobalIDs.
63 * EOEditingContexts should refault their copies of these objects.
64 */
65 public static final String UpdatedKey = "updated";
66
67 /***
68 * Key for the user info of ObjectsChangedInStoreNotification.
69 * The key should retrieve an array of EOGlobalIDs.
70 */
71 public static final String InvalidatedKey = "invalidated";
72
73 /***
74 * Key for the NSNotification posted when this object store
75 * is asked to invalidate all objects. Object of the notification
76 * will be this object store, and user info will contain the
77 * InvalidatedKey.
78 */
79 public static final String
80 InvalidatedAllObjectsInStoreNotification =
81 "EOInvalidatedAllObjectsInStoreNotification";
82
83 /***
84 * Key for the NSNotification posted when this object store
85 * is changed. Object of the notification will be this object
86 * store, and user info will contain InsertedKey, UpdatedKey,
87 * DeletedKey, and InvalidatedKey.
88 */
89 public static final String
90 ObjectsChangedInStoreNotification =
91 "EOObjectsChangedInStoreNotification";
92
93 /***
94 * Default constructor is responsible for initializing
95 * internal state.
96 */
97 public EOObjectStore ()
98 {
99 }
100
101 /***
102 * Called by editing contexts when they no longer
103 * need to track the specified id. You will not need
104 * to call this method, but you use use it for a hint
105 * that the specified global id is not in use by that
106 * child editing context.
107 */
108 public void editingContextDidForgetObjectWithGlobalID (
109 EOEditingContext aContext,
110 EOGlobalID aGlobalID )
111 {
112 }
113
114 /***
115 * Returns a List of objects associated with the object
116 * with the specified id for the specified property
117 * relationship, or may return a placeholder array that
118 * will defer the fetch until accessed (an array fault).
119 * All objects must be registered the specified editing context.
120 * The specified relationship key must produce a result of
121 * type Collection for the source object or an exception is thrown.
122 */
123 public abstract NSArray arrayFaultWithSourceGlobalID (
124 EOGlobalID aGlobalID,
125 String aRelationship,
126 EOEditingContext aContext );
127
128 /***
129 * Returns the object for the specified id.
130 * The returned object may be a fault.
131 * The object will be registered in the
132 * specified editing context.
133 */
134 public abstract
135 EOGlobalID aGlobalID,
136 EOEditingContext aContext );
137
138 /***
139 * Returns a fault representing an object of
140 * the specified entity type with values from
141 * the specified dictionary. The fault should
142 * belong to the specified editing context.
143 */
144 public abstract
145 Map aDictionary,
146 String anEntityName,
147 EOEditingContext aContext );
148
149 /***
150 * Given a newly instantiated object, this method
151 * initializes its properties to values appropriate
152 * for the specified id. The object should already
153 * belong to the specified editing context.
154 * This method is called to populate faults.
155 */
156 public abstract void initializeObject (
157
158 EOGlobalID aGlobalID,
159 EOEditingContext aContext );
160
161 /***
162 * Remove all values from all objects in memory,
163 * turning them into faults, and posts an NSNotification
164 * that all objects have been invalidated.
165 * The notification should be named with the string
166 * constant InvalidatedAllObjectsInStoreNotification
167 * with this object store as the object and no user info.
168 */
169 public abstract void invalidateAllObjects ();
170
171 /***
172 * Removes values with the specified ids from memory,
173 * turning them into faults, and posts a notification
174 * that those objects have been invalidated.
175 * The notification should be named with the string
176 * constant ObjectsChangedInStoreNotification
177 * with this object store as the object and user info
178 * containing a key named InvalidateKey that returns
179 * a List of the EOGlobalIDs of the invalidated objects.
180 */
181 public abstract void invalidateObjectsWithGlobalIDs (
182 List aList );
183
184 /***
185 * Returns whether the object corresponding to the
186 * specified id is locked. The concept of object
187 * locking is implementation-specific.
188 */
189 public abstract boolean isObjectLockedWithGlobalID (
190 EOGlobalID aGlobalID,
191 EOEditingContext aContext );
192
193 /***
194 * Locks the object corresponding to the
195 * specified id is locked. The concept of object
196 * locking is implementation-specific.
197 * The lock may be released when objects are
198 * invalidated or commited, but this behavior
199 * is not required.
200 */
201 public abstract void lockObjectWithGlobalID (
202 EOGlobalID aGlobalID,
203 EOEditingContext aContext );
204
205 /***
206 * Returns a List of objects associated with the object
207 * with the specified id for the specified property
208 * relationship. This method may not return an array fault
209 * because array faults call this method to fetch on demand.
210 * All objects must be registered the specified editing context.
211 * The specified relationship key must produce a result of
212 * type Collection for the source object or an exception is thrown.
213 */
214 public abstract NSArray objectsForSourceGlobalID (
215 EOGlobalID aGlobalID,
216 String aRelationship,
217 EOEditingContext aContext );
218
219 /***
220 * Returns a List of objects the meet the criteria of
221 * the supplied specification. Faults are not allowed in the array.
222 * Each object is registered with the specified editing context.
223 * If any object is already fetched in the specified context,
224 * it is not refetched and that object should be used in the array.
225 */
226 public abstract NSArray objectsWithFetchSpecification (
227 EOFetchSpecification aFetchSpec,
228 EOEditingContext aContext );
229
230 /***
231 * Removes all values from the specified object,
232 * converting it into a fault for the specified id.
233 * New or deleted objects should not be refaulted.
234 */
235 public abstract void refaultObject (
236 Object anObject,
237 EOGlobalID aGlobalID,
238 EOEditingContext aContext );
239
240 /***
241 * Writes all changes in the specified editing context
242 * to the respository. The object store is expected to
243 * post a notification that should be named with the string
244 * constant ObjectsChangedInStoreNotification
245 * with this object store as the object and user info
246 * containing keys named UpdatedKey, InsertedKey, and
247 * DeletedKey that return Lists of the EOGlobalIDs of the
248 * corresponding objects.
249 */
250 public abstract void saveChangesInEditingContext (
251 EOEditingContext aContext );
252 }
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320