-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLOObjectStore.j
233 lines (202 loc) · 9.14 KB
/
LOObjectStore.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* LOSimpleJSONObjectStore.j
*
* Created by Martin Carlberg on Mars 5, 2012.
* Copyright 2012, All rights reserved.
*/
@import <Foundation/CPObject.j>
@import "LOJSKeyedArchiver.j"
@import "LOFetchSpecification.j"
@implementation LOObjectStore : CPObject {
}
/*!
* Designated method for requesting objects.
* Must call [objectContext objectsReceived: withFetchSpecification:] when objects are received
*/
- (void)requestObjectsWithFetchSpecification:(LOFetchSpecification)aFetchSpecification objectContext:(LOObjectContext)anObjectContext requestId:(id)aRequestId withCompletionHandler:(Function)aCompletionBlock {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Convenience method calling -requestObjectsWithFetchSpecification:objectContext:requestId:withCompletionHandler: without requestId.
*/
- (void)requestObjectsWithFetchSpecification:(LOFetchSpecification)aFetchSpecification objectContext:(LOObjectContext)anObjectContext withCompletionHandler:(Function)aCompletionBlock {
[self requestObjectsWithFetchSpecification:aFetchSpecification objectContext:anObjectContext requestId:nil withCompletionHandler:aCompletionBlock];
}
/*!
* Convenience method calling -requestObjectsWithFetchSpecification:objectContext:requestId:withCompletionHandler: with neither requestId nor completion handler.
*/
- (void)requestObjectsWithFetchSpecification:(LOFetchSpecification)aFetchSpecification objectContext:(LOObjectContext)anObjectContext {
[self requestObjectsWithFetchSpecification:aFetchSpecification objectContext:anObjectContext requestId:nil withCompletionHandler:nil];
}
/*!
* Designated method for requesting fault array.
* Must call [objectContext faultReceived:(CPArray)objectList withFetchSpecification:(LOFetchSpecification)fetchSpecification faultArray:(LOFaultArray)faultArray] when fault objects are received
*/
- (void)requestFaultArray:(LOFaultArray)faultArray withFetchSpecification:(LOFetchSpecification)fetchSpecification objectContext:(LOObjectContext)objectContext requestId:(id)aRequestId withCompletionHandler:(Function)aCompletionBlock {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Convenience method calling requestFaultArray:withFetchSpecification:objectContext:requestId:withCompletionHandler: without requestId.
*/
- (void)requestFaultArray:(LOFaultArray)faultArray withFetchSpecification:(LOFetchSpecification)fetchSpecification objectContext:(LOObjectContext)objectContext withCompletionHandler:(Function)aCompletionBlock {
[self requestFaultArray:faultArray withFetchSpecification:fetchSpecification objectContext:objectContext requestId:nil withCompletionHandler:aCompletionBlock];
}
/*!
* Designated method for requesting fault objects.
* Must call [objectContext faultReceived:(CPArray)objectList withFetchSpecification:(LOFetchSpecification)fetchSpecification faultObject:(LOFaultObject)faultObject] when fault objects are received
*/
- (void)requestFaultObjects:(CPArray)faultObjects withFetchSpecification:(LOFetchSpecification)fetchSpecification objectContext:(LOObjectContext)objectContext requestId:(id)aRequestId withCompletionHandler:(Function)aCompletionBlock {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Convenience method calling -requestFaultObjects:withFetchSpecification:objectContext:requestId:withCompletionHandler: without requestId.
*/
- (void)requestFaultObjects:(CPArray)faultObjects withFetchSpecification:(LOFetchSpecification)fetchSpecification objectContext:(LOObjectContext)objectContext withCompletionHandler:(Function)aCompletionBlock {
[self requestFaultObjects:faultObjects withFetchSpecification:fetchSpecification objectContext:objectContext requestId:nil withCompletionHandler:aCompletionBlock];
}
/*!
* Cancel all currently running requests with a specific requestId and object context.
* A requestId argument of nil means match any request with respect to requestId, and similarly for the anObjectContext argument.
* Thus,
*
* [objectStore cancelRequestsWithRequestId:nil withObjectContext:ctx];
*
* cancels all requests to ctx regardless of requestId, and
*
* [objectStore cancelRequestsWithRequestId:nil withObjectContext:nil];
*
* cancels all requests regardless of both requestId and object context.
*/
- (void)cancelRequestsWithRequestId:(id)aRequestId withObjectContext:(LOObjectContext)anObjectContext {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* This method should save all changes to the backend.
* The ObjectContext has a list of LOModifyRecord that contains all changes.
*/
- (void)saveChangesWithObjectContext:(LOObjectContext)objectContext withCompletionHandler:(Function)aCompletionBlock {
}
/*!
* Must return an array with keys for all attributes for this object.
* To many relationship keys and to one relationsship foreign key attributes should be included.
* To one relationsship attribute should not be included.
* Primary key should not be included.
* The objectContext will observe all these attributes for changes and record them.
*/
- (CPArray)attributeKeysForObject:(id)theObject withType:(CPString)entityName {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Must return an array with keys for all to many relationship attributes for this object
* The objectContext will observe all these attributes for changes and record them.
*/
- (CPArray)relationshipKeysForObject:(id)theObject withType:(CPString)entityName {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns the type of the object
*/
- (CPString)typeOfObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Sets the type on the object
*/
- (void)setType:(CPString)aType onObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns a unique id for the object
*/
- (CPString)globalIdForObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns globalId for entity type and primary key. Should return nil if primaryKey is nil.
* Right now we only use the primary key as global id as we always has totaly unique primary keys.
* TODO: This framework does propably not yet support that the global id is different from primary key.
*/
- (CPString)globalIdForObjectType:(CPString)objectType andPrimaryKey:(CPString)primaryKey {
return primaryKey;
}
/*!
* Returns an url for saving the data. This method can also be overwritten to alter
* the data before it is sent to the url.
*/
- (CPString)urlForSaveChangesWithData:(id)data {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns an url for requestObjects.
*/
- (CPURLRequest)urlForRequestObjectsWithFetchSpecification:(LOFetchSpecification)fetchSpecification {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns the type for the raw row.
*/
- (CPString)typeForRawRow:(id)row objectContext:(LOObjectContext)objectContext fetchSpecification:(LOFetchSpecification)fetchSpecification {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns type of the object
*/
- (CPString)typeOfObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns the primary key attribute for the raw row of a type and for an object context.
*/
- (CPString)primaryKeyAttributeForType:(CPString)aType objectContext:(LOObjectContext)objectContext {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns true if the attribute for the raw row is a foreign key for a type and for an object context.
*/
- (BOOL)isForeignKeyAttribute:(CPString)attribute forType:(CPString)aType objectContext:(LOObjectContext)objectContext {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns to one relationship attribute that correspond to the foreign key attribute for the type
*/
- (CPString)toOneRelationshipAttributeForForeignKeyAttribute:(CPString)attribute forType:(CPString)aType objectContext:(LOObjectContext)objectContext {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns foreign key attribute that correspond to the to one relationship attribute for the type
*/
- (CPString)foreignKeyAttributeForToOneRelationshipAttribute:(CPString)attribute forType:(CPString)aType {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns the primary key for the raw row with type aType.
*/
- (CPString)primaryKeyForRawRow:(id)row forType:(CPString)aType objectContext:(LOObjectContext)objectContext {
var primaryKeyAttribute = [self primaryKeyAttributeForType:aType objectContext:objectContext];
return row[primaryKeyAttribute];
}
/*!
* Returns the primary key value for an object.
*/
- (CPString)primaryKeyForObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Sets the primary key value for an object.
*/
- (void)setPrimaryKey:(CPString)thePrimaryKey forObject:(id)theObject {
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
* Returns a new object for the type.
*/
- (id)newObjectForType:(CPString)aType objectContext:(LOObjectContext)objectContext {
return [objectContext newObjectForType:aType];
}
/*!
* Returns LOError for response and data if the backend has returned a error.
*/
- (LOError)errorForResponse:(CPHTTPURLResponse)response andData:(CPString)data fromURL:(CPString)urlString {
return nil;
}
@end