ActiveResourceKit  v1.2 (498.0)
 All Classes Files Functions Variables Typedefs Enumerator Properties Macros Pages
ARIncrementalStore+Private.h
Go to the documentation of this file.
1 // ActiveResourceKit ARIncrementalStore+Private.h
2 //
3 // Copyright © 2012, Roy Ratcliffe, Pioneering Software, United Kingdom
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EITHER
16 // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO
18 // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
19 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22 //
23 //------------------------------------------------------------------------------
24 
26 
27 @class ARResource;
28 
30 
31 /*!
32  * @brief Using a particular context, derives a managed-object identifier based
33  * on a resource's element name and its primary key.
34  * @details Derives the entity name from the resource element name.
35  */
36 - (NSManagedObjectID *)objectIDForResource:(ARResource *)resource withContext:(NSManagedObjectContext *)context;
37 
38 /*!
39  * @brief Answers the object identifier for a given resource after caching the
40  * resource against its object identifier.
41  */
42 - (NSManagedObjectID *)objectIDForCachedResource:(ARResource *)resource withContext:(NSManagedObjectContext *)context;
43 
44 /*!
45  * @brief Converts an object identifier to an active resource.
46  * @details The conversion occurs using the resource cache, if the resource
47  * currently exists in the cache (a cache hit). Otherwise the implementation
48  * first loads the cache with the resource using the given object identifier (a
49  * cache miss). Uncached resources become cached before the method returns.
50  */
51 - (ARResource *)cachedResourceForObjectID:(NSManagedObjectID *)objectID error:(NSError **)outError;
52 
53 /*!
54  * @brief Answers a 64-bit version number derived from the given @a resource.
55  * @details Uses the updated-at date-time as the version number. Converts the
56  * update-at date to seconds since the reference date. This amounts to a big
57  * version number, but the version number allows for 64 bits of unsigned integer
58  * width.
59  *
60  * Also makes an assumption about the updated-at dates: that they always exceed
61  * midnight 1st January 2001, the reference point. If they precede that point,
62  * then the reference-relative time interval becomes negative, the signed
63  * interval wraps the unsigned 64-bit version and version numbers start counting
64  * down. This is not what Core Data will expect.
65  *
66  * The implementation multiplies the time interval by 1,000 in order to allow
67  * for rare sub-second updates, if the server-side includes date-time at
68  * sub-second resolutions. RFC 3339 date-time formats allow for sub-second
69  * accuracy.
70  */
71 - (uint64_t)versionForResource:(ARResource *)resource;
72 
73 /*!
74  * @brief Refreshes an object in the incremental store cache.
75  * @param object The object to refresh.
76  * @details The given @a object disappears from the resource cache and becomes a
77  * fault. Subsequent attempts to access the object will refetch its resource
78  * attributes. This happens when objects insert. Inserted objects become
79  * unrealised because the remote server typically validates and further updates
80  * the inserted resource, e.g. by setting its update-at date. It also occurs
81  * when you update an object, for the same reason. Object deletion also
82  * refreshes the cache; the deleted resource disappears from the cache and the
83  * object becomes a fault before disappearing from the managed-object context as
84  * all deleted objects do.
85  */
86 - (void)refreshObject:(NSManagedObject *)object;
87 
88 /*!
89  * @brief Resolves relationships.
90  * @details Picks out the to-one associations. Is there a foreign key with a
91  * matching to-one relationship? Looks for a matching foreign key within the
92  * resource for each to-one relationship. If the foreign key does not exist but
93  * the to-one relationship does, then resolves the relationship at the server
94  * side by assigning the foreign key to the relationship destination's object
95  * reference, its resource identifier. Collects such foreign key attributes
96  * first because there could be multiple. Merge and save them.
97  *
98  * Ignores to-many associations. Rails will handle that.
99  */
100 - (NSDictionary *)foreignKeysForObject:(NSManagedObject *)object resource:(ARResource *)resource;
101 
102 @end