nano-store 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Rakefile +1 -1
- data/lib/nano_store.rb +1 -1
- data/lib/nano_store/version.rb +1 -1
- data/nano-store.gemspec +2 -2
- data/vendor/Podfile.lock +3 -3
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoGlobals.h +1 -3
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSearch.h +3 -5
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NanoStore.h +0 -36
- data/vendor/Pods/Documentation/NanoStore/docset-installed.txt +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Info.plist +3 -3
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoBag.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoEngine.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoExpression.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoObject.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoPredicate.html +6 -6
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoResult.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoSearch.html +4 -65
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoSortDescriptor.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoStore.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFOrderedDictionary.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Protocols/NSFNanoObjectProtocol.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/hierarchy.html +4 -4
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/index.html +4 -4
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Nodes.xml +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens5.xml +6 -6
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens7.xml +2 -24
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens8.xml +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.dsidx +0 -0
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.skidx +0 -0
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.toc +0 -0
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoBag.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoEngine.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoExpression.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoObject.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoPredicate.html +6 -6
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoResult.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoSearch.html +4 -65
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoSortDescriptor.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoStore.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFOrderedDictionary.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/Protocols/NSFNanoObjectProtocol.html +1 -1
- data/vendor/Pods/Documentation/NanoStore/html/hierarchy.html +4 -4
- data/vendor/Pods/Documentation/NanoStore/html/index.html +4 -4
- data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals.h +1 -3
- data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/Headers/NanoStore/NSFNanoSearch.h +3 -5
- data/vendor/Pods/Headers/NanoStore/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/Headers/NanoStore/NanoStore.h +0 -36
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.m +49 -40
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m +53 -42
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.m +89 -80
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m +13 -11
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.h +1 -3
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.m +0 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.m +29 -34
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.m +34 -43
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.h +3 -5
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.m +97 -171
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +12 -13
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.m +82 -83
- data/vendor/Pods/NanoStore/Classes/Public/NanoStore.h +0 -36
- data/vendor/Pods/Pods.bridgesupport +640 -648
- metadata +7 -7
@@ -27,17 +27,16 @@
|
|
27
27
|
#import "NSFNanoResult.h"
|
28
28
|
#import "NanoStore_Private.h"
|
29
29
|
|
30
|
-
@interface NSFNanoResult ()
|
31
|
-
|
32
|
-
/** \cond */
|
33
|
-
@property (nonatomic, assign, readwrite) NSUInteger numberOfRows;
|
34
|
-
@property (nonatomic, strong, readwrite) NSError *error;
|
35
|
-
@property (nonatomic) NSDictionary *results;
|
36
|
-
/** \endcond */
|
37
|
-
|
38
|
-
@end
|
39
|
-
|
40
30
|
@implementation NSFNanoResult
|
31
|
+
{
|
32
|
+
@protected
|
33
|
+
/** \cond */
|
34
|
+
NSDictionary *results;
|
35
|
+
/** \endcond */
|
36
|
+
}
|
37
|
+
|
38
|
+
@synthesize numberOfRows;
|
39
|
+
@synthesize error;
|
41
40
|
|
42
41
|
/** \cond */
|
43
42
|
|
@@ -58,24 +57,24 @@
|
|
58
57
|
|
59
58
|
- (NSString *)description
|
60
59
|
{
|
61
|
-
NSUInteger numberOfColumns = [[
|
60
|
+
NSUInteger numberOfColumns = [[results allKeys]count];
|
62
61
|
|
63
62
|
NSMutableString *description = [NSMutableString string];
|
64
63
|
[description appendString:@"\n"];
|
65
64
|
[description appendString:[NSString stringWithFormat:@"Result address : %p\n", self]];
|
66
65
|
[description appendString:[NSString stringWithFormat:@"Number of columns : %ld\n", numberOfColumns]];
|
67
|
-
if (nil ==
|
66
|
+
if (nil == error)
|
68
67
|
if ([[self columns]count] > 0)
|
69
68
|
[description appendString:[NSString stringWithFormat:@"Columns : %@\n", [[self columns]componentsJoinedByString:@", "]]];
|
70
69
|
else
|
71
70
|
[description appendString:[NSString stringWithFormat:@"Columns : %@\n", @"()"]];
|
72
71
|
else
|
73
72
|
[description appendString:[NSString stringWithFormat:@"Columns : %@\n", @"<column info not available>"]];
|
74
|
-
[description appendString:[NSString stringWithFormat:@"Number of rows : %ld\n",
|
75
|
-
if (nil ==
|
73
|
+
[description appendString:[NSString stringWithFormat:@"Number of rows : %ld\n", numberOfRows]];
|
74
|
+
if (nil == error)
|
76
75
|
[description appendString:[NSString stringWithFormat:@"Error : %@\n", @"<no error>"]];
|
77
76
|
else
|
78
|
-
[description appendString:[NSString stringWithFormat:@"Error : %@\n", [
|
77
|
+
[description appendString:[NSString stringWithFormat:@"Error : %@\n", [error localizedDescription]]];
|
79
78
|
|
80
79
|
// Print up to the first ten rows to help visualize the cursor
|
81
80
|
if (0 != numberOfColumns) {
|
@@ -106,11 +105,11 @@
|
|
106
105
|
}
|
107
106
|
|
108
107
|
// Print the preview of the contents
|
109
|
-
if (
|
110
|
-
NSInteger numberOfRowsToPrint =
|
108
|
+
if (numberOfRows > 0) {
|
109
|
+
NSInteger numberOfRowsToPrint = numberOfRows;
|
111
110
|
NSUInteger j;
|
112
111
|
|
113
|
-
if (
|
112
|
+
if (numberOfRows > 100) {
|
114
113
|
numberOfRowsToPrint = 100;
|
115
114
|
}
|
116
115
|
|
@@ -142,13 +141,13 @@
|
|
142
141
|
|
143
142
|
- (NSFOrderedDictionary *)dictionaryDescription
|
144
143
|
{
|
145
|
-
NSUInteger numberOfColumns = [[
|
144
|
+
NSUInteger numberOfColumns = [[results allKeys]count];
|
146
145
|
|
147
146
|
NSFOrderedDictionary *values = [NSFOrderedDictionary new];
|
148
147
|
|
149
148
|
values[@"Result address"] = [NSString stringWithFormat:@"%p", self];
|
150
149
|
values[@"Number of columns"] = @(numberOfColumns);
|
151
|
-
if (nil ==
|
150
|
+
if (nil == error) {
|
152
151
|
if ([[self columns]count] > 0) {
|
153
152
|
values[@"Columns"] = [[self columns]componentsJoinedByString:@", "];
|
154
153
|
} else {
|
@@ -157,11 +156,11 @@
|
|
157
156
|
} else {
|
158
157
|
values[@"Columns"] = @"<column info not available>";
|
159
158
|
}
|
160
|
-
values[@"Number of rows"] = @(
|
161
|
-
if (nil ==
|
159
|
+
values[@"Number of rows"] = @(numberOfRows);
|
160
|
+
if (nil == error) {
|
162
161
|
values[@"Error"] = @"<nil>";
|
163
162
|
} else {
|
164
|
-
values[@"Error"] = [NSString stringWithFormat:@"%@", [
|
163
|
+
values[@"Error"] = [NSString stringWithFormat:@"%@", [error localizedDescription]];
|
165
164
|
}
|
166
165
|
|
167
166
|
// Print up to the first ten rows to help visualize the cursor
|
@@ -197,11 +196,11 @@
|
|
197
196
|
[printedContent addObject:[contentString copy]];
|
198
197
|
|
199
198
|
// Print the preview of the contents
|
200
|
-
if (
|
201
|
-
NSInteger numberOfRowsToPrint =
|
199
|
+
if (numberOfRows > 0) {
|
200
|
+
NSInteger numberOfRowsToPrint = numberOfRows;
|
202
201
|
NSUInteger j;
|
203
202
|
|
204
|
-
if (
|
203
|
+
if (numberOfRows > 100) {
|
205
204
|
numberOfRowsToPrint = 100;
|
206
205
|
}
|
207
206
|
|
@@ -252,17 +251,17 @@
|
|
252
251
|
|
253
252
|
- (NSArray *)columns
|
254
253
|
{
|
255
|
-
return [
|
254
|
+
return [results allKeys];
|
256
255
|
}
|
257
256
|
|
258
257
|
- (NSString *)valueAtIndex:(NSUInteger)index forColumn:(NSString *)column
|
259
258
|
{
|
260
|
-
return [[
|
259
|
+
return [[results objectForKey:column]objectAtIndex:index];
|
261
260
|
}
|
262
261
|
|
263
262
|
- (NSArray *)valuesForColumn:(NSString *)column
|
264
263
|
{
|
265
|
-
NSArray *values = [
|
264
|
+
NSArray *values = [results objectForKey:column];
|
266
265
|
|
267
266
|
if (nil == values)
|
268
267
|
values = [NSArray array];
|
@@ -272,17 +271,22 @@
|
|
272
271
|
|
273
272
|
- (NSString *)firstValue
|
274
273
|
{
|
275
|
-
NSArray *columns = [
|
276
|
-
if (([columns count] > 0) && (
|
277
|
-
return [[
|
274
|
+
NSArray *columns = [results allKeys];
|
275
|
+
if (([columns count] > 0) && (numberOfRows > 0)) {
|
276
|
+
return [[results objectForKey:[columns objectAtIndex:0]]objectAtIndex:0];
|
278
277
|
}
|
279
278
|
|
280
279
|
return nil;
|
281
280
|
}
|
282
281
|
|
282
|
+
- (NSError *)error
|
283
|
+
{
|
284
|
+
return [error copy];
|
285
|
+
}
|
286
|
+
|
283
287
|
- (void)writeToFile:(NSString *)path;
|
284
288
|
{
|
285
|
-
[
|
289
|
+
[results writeToFile:[path stringByExpandingTildeInPath] atomically:YES];
|
286
290
|
}
|
287
291
|
|
288
292
|
#pragma mark - Private Methods
|
@@ -312,7 +316,7 @@
|
|
312
316
|
userInfo:nil]raise];
|
313
317
|
|
314
318
|
if ((self = [self init])) {
|
315
|
-
|
319
|
+
results = theResults;
|
316
320
|
[self _calculateNumberOfRows];
|
317
321
|
}
|
318
322
|
|
@@ -332,29 +336,36 @@
|
|
332
336
|
userInfo:nil]raise];
|
333
337
|
|
334
338
|
if ((self = [self init])) {
|
335
|
-
|
339
|
+
error = theError;
|
336
340
|
[self _calculateNumberOfRows];
|
337
341
|
}
|
338
342
|
|
339
343
|
return self;
|
340
344
|
}
|
341
345
|
|
346
|
+
- (void)_setError:(NSError *)theError
|
347
|
+
{
|
348
|
+
if (error != theError) {
|
349
|
+
error = theError;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
342
353
|
- (void)_reset
|
343
354
|
{
|
344
|
-
|
345
|
-
|
346
|
-
|
355
|
+
numberOfRows = -1;
|
356
|
+
results = nil;
|
357
|
+
error = nil;
|
347
358
|
}
|
348
359
|
|
349
360
|
- (void)_calculateNumberOfRows
|
350
361
|
{
|
351
362
|
// We cache the value once, for performance reasons
|
352
|
-
if (-1 ==
|
353
|
-
NSArray *allKeys = [
|
363
|
+
if (-1 == numberOfRows) {
|
364
|
+
NSArray *allKeys = [results allKeys];
|
354
365
|
if ([allKeys count] == 0)
|
355
|
-
|
366
|
+
numberOfRows = 0;
|
356
367
|
else
|
357
|
-
|
368
|
+
numberOfRows = [[results objectForKey:[allKeys lastObject]]count];
|
358
369
|
}
|
359
370
|
}
|
360
371
|
/** \endcond */
|
@@ -35,13 +35,16 @@
|
|
35
35
|
|
36
36
|
@implementation NSFNanoBag
|
37
37
|
{
|
38
|
+
@protected
|
38
39
|
/** \cond */
|
39
|
-
NSMutableDictionary
|
40
|
-
NSMutableDictionary
|
41
|
-
NSMutableDictionary
|
40
|
+
NSMutableDictionary *savedObjects;
|
41
|
+
NSMutableDictionary *unsavedObjects;
|
42
|
+
NSMutableDictionary *removedObjects;
|
42
43
|
/** \endcond */
|
43
44
|
}
|
44
45
|
|
46
|
+
@synthesize store, name, key, savedObjects, unsavedObjects, removedObjects, hasUnsavedChanges;
|
47
|
+
|
45
48
|
+ (NSFNanoBag*)bag
|
46
49
|
{
|
47
50
|
return [[self alloc]initBagWithName:nil andObjects:[NSArray array]];
|
@@ -73,8 +76,8 @@
|
|
73
76
|
if ((self = [self init])) {
|
74
77
|
[self addObjectsFromArray:someObjects error:nil];
|
75
78
|
|
76
|
-
|
77
|
-
|
79
|
+
name = [theName copy];
|
80
|
+
hasUnsavedChanges = YES;
|
78
81
|
}
|
79
82
|
|
80
83
|
return self;
|
@@ -85,13 +88,13 @@
|
|
85
88
|
- (id)init
|
86
89
|
{
|
87
90
|
if ((self = [super init])) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
store = nil;
|
92
|
+
key = [NSFNanoEngine stringWithUUID];
|
93
|
+
savedObjects = [NSMutableDictionary new];
|
94
|
+
unsavedObjects = [NSMutableDictionary new];
|
95
|
+
removedObjects = [NSMutableDictionary new];
|
96
|
+
|
97
|
+
hasUnsavedChanges = NO;
|
95
98
|
}
|
96
99
|
|
97
100
|
return self;
|
@@ -99,7 +102,7 @@
|
|
99
102
|
|
100
103
|
- (id)copyWithZone:(NSZone *)zone
|
101
104
|
{
|
102
|
-
NSFNanoBag *copy = [[[self class]allocWithZone:zone]initNanoObjectFromDictionaryRepresentation:[self dictionaryRepresentation] forKey:[NSFNanoEngine stringWithUUID] store:
|
105
|
+
NSFNanoBag *copy = [[[self class]allocWithZone:zone]initNanoObjectFromDictionaryRepresentation:[self dictionaryRepresentation] forKey:[NSFNanoEngine stringWithUUID] store:store];
|
103
106
|
return copy;
|
104
107
|
}
|
105
108
|
|
@@ -113,15 +116,20 @@
|
|
113
116
|
|
114
117
|
- (void)setName:(NSString *)aName
|
115
118
|
{
|
116
|
-
|
117
|
-
|
119
|
+
name = [aName copy];
|
120
|
+
hasUnsavedChanges = YES;
|
118
121
|
}
|
119
122
|
|
120
123
|
/** \endcond */
|
121
124
|
|
125
|
+
- (NSString *)name
|
126
|
+
{
|
127
|
+
return name;
|
128
|
+
}
|
129
|
+
|
122
130
|
- (NSUInteger)count
|
123
131
|
{
|
124
|
-
return
|
132
|
+
return savedObjects.count + unsavedObjects.count;
|
125
133
|
}
|
126
134
|
|
127
135
|
- (NSString *)description
|
@@ -134,13 +142,13 @@
|
|
134
142
|
NSFOrderedDictionary *values = [NSFOrderedDictionary new];
|
135
143
|
|
136
144
|
values[@"NanoBag address"] = [NSString stringWithFormat:@"%p", self];
|
137
|
-
values[@"Key"] =
|
138
|
-
values[@"Name"] = (nil !=
|
139
|
-
values[@"Document store"] = ([
|
140
|
-
values[@"Has unsaved changes?"] = (
|
141
|
-
values[@"Saved objects"] = @([
|
142
|
-
values[@"Unsaved objects"] = @([
|
143
|
-
values[@"Removed objects"] = @([
|
145
|
+
values[@"Key"] = key;
|
146
|
+
values[@"Name"] = (nil != name) ? name : @"<untitled>";
|
147
|
+
values[@"Document store"] = ([store dictionaryDescription] ? [store dictionaryDescription] : @"<nil>");
|
148
|
+
values[@"Has unsaved changes?"] = (hasUnsavedChanges ? @"YES" : @"NO");
|
149
|
+
values[@"Saved objects"] = @([savedObjects count]);
|
150
|
+
values[@"Unsaved objects"] = @([unsavedObjects count]);
|
151
|
+
values[@"Removed objects"] = @([removedObjects count]);
|
144
152
|
|
145
153
|
return values;
|
146
154
|
}
|
@@ -159,17 +167,17 @@
|
|
159
167
|
{
|
160
168
|
// Iterate the objects collecting the object keys
|
161
169
|
NSMutableArray *objectKeys = [NSMutableArray new];
|
162
|
-
for (NSString *objectKey in
|
170
|
+
for (NSString *objectKey in self.savedObjects) {
|
163
171
|
[objectKeys addObject:objectKey];
|
164
172
|
}
|
165
|
-
for (NSString *objectKey in
|
173
|
+
for (NSString *objectKey in self.unsavedObjects) {
|
166
174
|
[objectKeys addObject:objectKey];
|
167
175
|
}
|
168
176
|
|
169
177
|
NSMutableDictionary *info = [NSMutableDictionary dictionary];
|
170
178
|
|
171
|
-
if (nil !=
|
172
|
-
[info setObject:
|
179
|
+
if (nil != name) {
|
180
|
+
[info setObject:name forKey:NSF_Private_NSFNanoBag_Name];
|
173
181
|
}
|
174
182
|
[info setObject:self.key forKey:NSF_Private_NSFNanoBag_NSFKey];
|
175
183
|
[info setObject:objectKeys forKey:NSF_Private_NSFNanoBag_NSFObjectKeys];
|
@@ -185,17 +193,17 @@
|
|
185
193
|
|
186
194
|
BOOL success = YES;
|
187
195
|
|
188
|
-
NSArray *sortedArraySelf = [[
|
196
|
+
NSArray *sortedArraySelf = [[[self savedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
189
197
|
NSArray *sortedArrayOther = [[[otherNanoBag savedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
190
198
|
if (NO == [sortedArraySelf isEqualToArray:sortedArrayOther]) {
|
191
199
|
success = NO;
|
192
200
|
} else {
|
193
|
-
sortedArraySelf = [[
|
201
|
+
sortedArraySelf = [[[self unsavedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
194
202
|
sortedArrayOther = [[[otherNanoBag unsavedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
195
203
|
if (NO == [sortedArraySelf isEqualToArray:sortedArrayOther]) {
|
196
204
|
success = NO;
|
197
205
|
} else {
|
198
|
-
sortedArraySelf = [[
|
206
|
+
sortedArraySelf = [[[self removedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
199
207
|
sortedArrayOther = [[[otherNanoBag removedObjects]allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
200
208
|
if (NO == [sortedArraySelf isEqualToArray:sortedArrayOther]) {
|
201
209
|
success = NO;
|
@@ -220,10 +228,10 @@
|
|
220
228
|
NSDictionary *info = [(id)object dictionaryRepresentation];
|
221
229
|
|
222
230
|
if (objectKey && info) {
|
223
|
-
[
|
224
|
-
[
|
225
|
-
[
|
226
|
-
|
231
|
+
[savedObjects removeObjectForKey:objectKey];
|
232
|
+
[unsavedObjects setObject:object forKey:objectKey];
|
233
|
+
[removedObjects removeObjectForKey:objectKey];
|
234
|
+
hasUnsavedChanges = YES;
|
227
235
|
} else {
|
228
236
|
NSString *message = nil;
|
229
237
|
if (nil == objectKey)
|
@@ -273,20 +281,21 @@
|
|
273
281
|
|
274
282
|
- (void)removeAllObjects
|
275
283
|
{
|
276
|
-
NSMutableDictionary *objects = [[NSMutableDictionary alloc]initWithCapacity:(
|
284
|
+
NSMutableDictionary *objects = [[NSMutableDictionary alloc]initWithCapacity:(savedObjects.count + removedObjects.count)];
|
277
285
|
|
278
286
|
// Save the object and its key
|
279
|
-
for (id object in
|
287
|
+
for (id object in savedObjects) {
|
280
288
|
[objects setObject:object forKey:[object performSelector:@selector(key)]];
|
281
289
|
}
|
282
290
|
|
283
291
|
// Save the previously removed objects (if any)
|
284
|
-
[objects addEntriesFromDictionary:
|
292
|
+
[objects addEntriesFromDictionary:removedObjects];
|
293
|
+
|
294
|
+
[savedObjects removeAllObjects];
|
295
|
+
[unsavedObjects removeAllObjects];
|
296
|
+
[removedObjects setDictionary:objects];
|
297
|
+
hasUnsavedChanges = YES;
|
285
298
|
|
286
|
-
[_savedObjects removeAllObjects];
|
287
|
-
[_unsavedObjects removeAllObjects];
|
288
|
-
[_removedObjects setDictionary:objects];
|
289
|
-
_hasUnsavedChanges = YES;
|
290
299
|
}
|
291
300
|
|
292
301
|
- (void)removeObjectsInArray:(NSArray *)someObjects
|
@@ -305,22 +314,22 @@
|
|
305
314
|
}
|
306
315
|
|
307
316
|
// Is the object an existing one?
|
308
|
-
id object = [
|
317
|
+
id object = [savedObjects objectForKey:objectKey];
|
309
318
|
if (nil != object) {
|
310
|
-
[
|
319
|
+
[savedObjects removeObjectForKey:objectKey];
|
311
320
|
} else {
|
312
321
|
// Is the object still unsaved?
|
313
|
-
object = [
|
322
|
+
object = [unsavedObjects objectForKey:objectKey];
|
314
323
|
if (nil != object) {
|
315
|
-
[
|
324
|
+
[unsavedObjects removeObjectForKey:objectKey];
|
316
325
|
}
|
317
326
|
}
|
318
327
|
|
319
328
|
if (nil == object) {
|
320
329
|
// The object doesn't exist, so there is no need to mark the bag as dirty
|
321
330
|
} else {
|
322
|
-
[
|
323
|
-
|
331
|
+
[removedObjects setObject:object forKey:objectKey];
|
332
|
+
hasUnsavedChanges = YES;
|
324
333
|
}
|
325
334
|
}
|
326
335
|
|
@@ -337,7 +346,7 @@
|
|
337
346
|
return YES;
|
338
347
|
}
|
339
348
|
|
340
|
-
if (nil ==
|
349
|
+
if (nil == store) {
|
341
350
|
if (nil != outError) {
|
342
351
|
*outError = [NSError errorWithDomain:NSFDomainKey
|
343
352
|
code:NSFNanoStoreErrorKey
|
@@ -347,42 +356,42 @@
|
|
347
356
|
return NO;
|
348
357
|
}
|
349
358
|
|
350
|
-
return [self _saveInStore:
|
359
|
+
return [self _saveInStore:store error:outError];
|
351
360
|
}
|
352
361
|
|
353
362
|
#pragma mark -
|
354
363
|
|
355
364
|
- (void)deflateBag
|
356
365
|
{
|
357
|
-
NSArray *savedObjectsCopy = [[NSArray alloc]initWithArray:[
|
366
|
+
NSArray *savedObjectsCopy = [[NSArray alloc]initWithArray:[savedObjects allKeys]];
|
358
367
|
|
359
368
|
for (id saveObjectKey in savedObjectsCopy) {
|
360
|
-
[
|
369
|
+
[savedObjects setObject:[NSNull null] forKey:saveObjectKey];
|
361
370
|
}
|
362
371
|
|
363
372
|
}
|
364
373
|
|
365
374
|
- (void)inflateBag
|
366
375
|
{
|
367
|
-
NSArray *objectKeys = [
|
376
|
+
NSArray *objectKeys = [savedObjects allKeys];
|
368
377
|
[self _inflateObjectsWithKeys:objectKeys];
|
369
378
|
}
|
370
379
|
|
371
380
|
- (BOOL)reloadBagWithError:(out NSError **)outError
|
372
381
|
{
|
373
382
|
// If the bag is not associated to a document store, there is no need to continue
|
374
|
-
if (nil ==
|
383
|
+
if (nil == store) {
|
375
384
|
return YES;
|
376
385
|
}
|
377
386
|
|
378
387
|
// Refresh the bag to match the contents stored on the database
|
379
|
-
[self _inflateObjectsWithKeys:[NSArray arrayWithObject:
|
380
|
-
NSFNanoBag *savedBag = [
|
388
|
+
[self _inflateObjectsWithKeys:[NSArray arrayWithObject:key]];
|
389
|
+
NSFNanoBag *savedBag = [savedObjects objectForKey:key];
|
381
390
|
if (nil != savedBag) {
|
382
|
-
[
|
383
|
-
[
|
384
|
-
for (NSString *objectKey in
|
385
|
-
[
|
391
|
+
[savedObjects removeAllObjects];
|
392
|
+
[savedObjects addEntriesFromDictionary:savedBag.savedObjects];
|
393
|
+
for (NSString *objectKey in unsavedObjects) {
|
394
|
+
[savedObjects removeObjectForKey:objectKey];
|
386
395
|
}
|
387
396
|
} else {
|
388
397
|
if (nil != outError) {
|
@@ -399,11 +408,11 @@
|
|
399
408
|
|
400
409
|
- (BOOL)undoChangesWithError:(out NSError **)outError
|
401
410
|
{
|
402
|
-
[
|
403
|
-
[
|
404
|
-
[
|
411
|
+
[savedObjects removeAllObjects];
|
412
|
+
[unsavedObjects removeAllObjects];
|
413
|
+
[removedObjects removeAllObjects];
|
405
414
|
|
406
|
-
|
415
|
+
hasUnsavedChanges = NO;
|
407
416
|
|
408
417
|
return [self reloadBagWithError:outError];
|
409
418
|
}
|
@@ -417,18 +426,18 @@
|
|
417
426
|
- (id)initNanoObjectFromDictionaryRepresentation:(NSDictionary *)dictionary forKey:(NSString *)aKey store:(NSFNanoStore *)aStore
|
418
427
|
{
|
419
428
|
if ((self = [self init])) {
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
429
|
+
name = [[dictionary objectForKey:NSF_Private_NSFNanoBag_Name]copy];
|
430
|
+
store = aStore;
|
431
|
+
key = aKey;
|
432
|
+
savedObjects = [NSMutableDictionary new];
|
433
|
+
unsavedObjects = [NSMutableDictionary new];
|
434
|
+
removedObjects = [NSMutableDictionary new];
|
426
435
|
|
427
436
|
NSArray *objectKeys = [dictionary objectForKey:NSF_Private_NSFNanoBag_NSFObjectKeys];
|
428
437
|
|
429
438
|
[self _inflateObjectsWithKeys:objectKeys];
|
430
439
|
|
431
|
-
|
440
|
+
hasUnsavedChanges = NO;
|
432
441
|
}
|
433
442
|
|
434
443
|
return self;
|
@@ -441,35 +450,35 @@
|
|
441
450
|
|
442
451
|
- (NSString *)nanoObjectKey
|
443
452
|
{
|
444
|
-
return
|
453
|
+
return key;
|
445
454
|
}
|
446
455
|
|
447
456
|
- (void)_setStore:(NSFNanoStore *)aStore
|
448
457
|
{
|
449
|
-
|
458
|
+
store = aStore;
|
450
459
|
}
|
451
460
|
|
452
461
|
- (BOOL)_saveInStore:(NSFNanoStore *)someStore error:(out NSError **)outError
|
453
462
|
{
|
454
463
|
// Save the unsaved objects first...
|
455
|
-
NSArray *contentsToBeSaved = [
|
464
|
+
NSArray *contentsToBeSaved = [unsavedObjects allValues];
|
456
465
|
if ([contentsToBeSaved count] > 0) {
|
457
466
|
[someStore _addObjectsFromArray:contentsToBeSaved forceSave:YES error:outError];
|
458
467
|
}
|
459
468
|
|
460
469
|
// Move the existing objects to the unsaved list, in order to save the bag
|
461
|
-
[
|
462
|
-
[
|
463
|
-
[
|
470
|
+
[unsavedObjects addEntriesFromDictionary:savedObjects];
|
471
|
+
[savedObjects removeAllObjects];
|
472
|
+
[removedObjects removeAllObjects];
|
464
473
|
|
465
474
|
// Save the unsaved bag...
|
466
475
|
BOOL success = [someStore _addObjectsFromArray:[NSArray arrayWithObject:self] forceSave:YES error:outError];
|
467
476
|
|
468
477
|
if (YES == success) {
|
469
|
-
[
|
478
|
+
[unsavedObjects removeAllObjects];
|
470
479
|
success = [self reloadBagWithError:outError];
|
471
480
|
if (YES == success) {
|
472
|
-
|
481
|
+
hasUnsavedChanges = NO;
|
473
482
|
}
|
474
483
|
return success;
|
475
484
|
}
|
@@ -480,14 +489,14 @@
|
|
480
489
|
- (void)_inflateObjectsWithKeys:(NSArray *)someKeys
|
481
490
|
{
|
482
491
|
if ([someKeys count] != 0) {
|
483
|
-
NSFNanoSearch *search = [NSFNanoSearch searchWithStore:
|
492
|
+
NSFNanoSearch *search = [NSFNanoSearch searchWithStore:store];
|
484
493
|
NSString *quotedString = [NSFNanoSearch _quoteStrings:someKeys joiningWithDelimiter:@","];
|
485
494
|
NSString *theSQLStatement = [NSString stringWithFormat:@"SELECT NSFKey, NSFKeyedArchive, NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", quotedString];
|
486
495
|
|
487
496
|
NSDictionary *results = [search executeSQL:theSQLStatement returnType:NSFReturnObjects error:nil];
|
488
497
|
|
489
498
|
if (nil != results) {
|
490
|
-
[
|
499
|
+
[savedObjects addEntriesFromDictionary:results];
|
491
500
|
}
|
492
501
|
}
|
493
502
|
}
|