nano-store 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +3 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +193 -0
  7. data/Rakefile +1 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/nano-store.rb +1 -0
  10. data/lib/nano_store/bag.rb +98 -0
  11. data/lib/nano_store/model.rb +142 -0
  12. data/lib/nano_store/nano_store.rb +36 -0
  13. data/lib/nano_store/store_extension.rb +150 -0
  14. data/lib/nano_store/version.rb +3 -0
  15. data/lib/nano_store.rb +14 -0
  16. data/nano-store.gemspec +17 -0
  17. data/resources/.gitignore +0 -0
  18. data/spec/bag_spec.rb +66 -0
  19. data/spec/model_spec.rb +130 -0
  20. data/spec/nano_store_spec.rb +48 -0
  21. data/spec/store_extension_spec.rb +110 -0
  22. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
  23. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
  24. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
  25. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
  26. data/vendor/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
  27. data/vendor/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
  28. data/vendor/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
  29. data/vendor/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
  30. data/vendor/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
  31. data/vendor/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
  32. data/vendor/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
  33. data/vendor/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
  34. data/vendor/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
  35. data/vendor/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
  36. data/vendor/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
  37. data/vendor/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
  38. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
  39. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
  40. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
  41. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
  42. data/vendor/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
  43. data/vendor/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
  44. data/vendor/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
  45. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
  46. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
  47. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
  48. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.m +835 -0
  49. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
  50. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
  51. data/vendor/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
  52. data/vendor/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
  53. data/vendor/NanoStore/Classes/Public/NanoStore.h +463 -0
  54. data/vendor/NanoStore/LICENSE +25 -0
  55. data/vendor/NanoStore/NanoStore.bridgesupport +1215 -0
  56. data/vendor/NanoStore/README.md +411 -0
  57. metadata +118 -0
@@ -0,0 +1,124 @@
1
+ /*
2
+ NSFNanoSortDescriptor.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import <Foundation/Foundation.h>
28
+
29
+ #import "NSFNanoGlobals.h"
30
+
31
+ /*! @file NSFNanoSortDescriptor.h
32
+ @brief A unit that describes a sort to be used in conjunction with a search operation.
33
+ */
34
+
35
+ /** @class NSFNanoSortDescriptor
36
+ * A unit that describes a sort to be used in conjunction with a search operation.
37
+ * @details <b>Example:</b>
38
+ @code
39
+ // Instantiate a NanoStore and open it
40
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
41
+ [nanoStore removeAllObjectsFromStoreAndReturnError:nil];
42
+
43
+ NSFNanoObject *obj1 = [NSFNanoObject nanoObjectWithDictionary:[NSDictionary dictionaryWithObject:@"Madrid" forKey:@"City"]];
44
+ NSFNanoObject *obj2 = [NSFNanoObject nanoObjectWithDictionary:[NSDictionary dictionaryWithObject:@"Barcelona" forKey:@"City"]];
45
+ NSFNanoObject *obj3 = [NSFNanoObject nanoObjectWithDictionary:[NSDictionary dictionaryWithObject:@"San Sebastian" forKey:@"City"]];
46
+ NSFNanoObject *obj4 = [NSFNanoObject nanoObjectWithDictionary:[NSDictionary dictionaryWithObject:@"Zaragoza" forKey:@"City"]];
47
+ NSFNanoObject *obj5 = [NSFNanoObject nanoObjectWithDictionary:[NSDictionary dictionaryWithObject:@"Tarragona" forKey:@"City"]];
48
+
49
+ [nanoStore addObjectsFromArray:[NSArray arrayWithObjects:obj1, obj2, obj3, obj4, obj5, nil] error:nil];
50
+
51
+ // Prepare the sort descriptor
52
+ NSFNanoSortDescriptor *sortCities = [[NSFNanoSortDescriptor alloc]initWithAttribute:@"City" ascending:YES];
53
+
54
+ // Prepare the search
55
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
56
+ search.sort = [NSArray arrayWithObjects: sortCities, nil];
57
+
58
+ // Perform the search
59
+ NSArray *searchResults = [search searchObjectsWithReturnType:NSFReturnObjects error:nil];
60
+ STAssertTrue ([searchResults count] == 5, @"Expected to find five objects.");
61
+ STAssertTrue ([[[[searchResults objectAtIndex:0]info]objectForKey:@"City"]isEqualToString:@"Barcelona"], @"Expected to find Barcelona.");
62
+
63
+ for (NSFNanoObject *object in searchResults) {
64
+ NSLog(@"%@", [[object info]objectForKey:@"City"]);
65
+ }
66
+
67
+ // Cleanup
68
+ [sortCities release];
69
+
70
+ // Close the document store
71
+ [nanoStore closeWithError:nil];
72
+ @endcode
73
+ */
74
+
75
+ @interface NSFNanoSortDescriptor : NSObject
76
+
77
+ /** * The property key to use when performing a comparison */
78
+ @property (nonatomic, readonly) NSString *attribute;
79
+ /** * The property to indicate whether the comparison should be performed in ascending mode */
80
+ @property (nonatomic, readonly) BOOL isAscending;
81
+
82
+ /** @name Creating and Initializing Expressions
83
+ */
84
+
85
+ //@{
86
+
87
+ /** * Creates and returns an sort descriptor with the specified key and ordering.
88
+ * @param theKey the property key to use when performing a comparison. Must not be nil or empty.
89
+ * @param ascending YES if the sort descriptor specifies sorting in ascending order, otherwise NO.
90
+ * @return A sort descriptor initialized with the specified key and ordering.
91
+ * @warning The parameter theKey must not be nil.
92
+ * @throws NSFUnexpectedParameterException is thrown if the key is nil.
93
+ * @see \link initWithKey:ascending: - (id)initWithKey:(NSString *)theKey ascending:(BOOL)ascending \endlink
94
+ */
95
+
96
+ + (NSFNanoSortDescriptor *)sortDescriptorWithAttribute:(NSString *)theAttribute ascending:(BOOL)ascending;
97
+
98
+ /** * Initializes a newly allocated sort descriptor with the specified key and ordering.
99
+ * @param theKey the property key to use when performing a comparison. Must not be nil or empty.
100
+ * @param ascending YES if the sort descriptor specifies sorting in ascending order, otherwise NO.
101
+ * @return A sort descriptor initialized with the specified key and ordering.
102
+ * @warning The parameter theKey must not be nil.
103
+ * @throws NSFUnexpectedParameterException is thrown if the key is nil.
104
+ * @see \link sortDescriptorWithKey:ascending: - (NSFNanoSortDescriptor *)sortDescriptorWithKey:(NSString *)theKey ascending:(BOOL)ascending \endlink
105
+ */
106
+
107
+ - (id)initWithAttribute:(NSString *)theAttribute ascending:(BOOL)ascending;
108
+
109
+ //@}
110
+
111
+ /** @name Miscellaneous
112
+ */
113
+
114
+ //@{
115
+
116
+ /** * Returns a string representation of the sort.
117
+ * @note Check properties attribute and isAscending to find out the current state of the sort.
118
+ */
119
+
120
+ - (NSString *)description;
121
+
122
+ //@}
123
+
124
+ @end
@@ -0,0 +1,79 @@
1
+ /*
2
+ NSFNanoSortDescriptor.m
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoSortDescriptor.h"
28
+ #import "NSFNanoGlobals.h"
29
+
30
+ @implementation NSFNanoSortDescriptor
31
+ {
32
+ /** \cond */
33
+ NSString *attribute;
34
+ BOOL isAscending;
35
+ /** \endcond */
36
+ }
37
+
38
+ @synthesize attribute, isAscending;
39
+
40
+ + (NSFNanoSortDescriptor *)sortDescriptorWithAttribute:(NSString *)theAttribute ascending:(BOOL)ascending
41
+ {
42
+ return [[self alloc]initWithAttribute:theAttribute ascending:ascending];
43
+ }
44
+
45
+ - (id)initWithAttribute:(NSString *)theAttribute ascending:(BOOL)ascending
46
+ {
47
+ if (theAttribute.length == 0)
48
+ [[NSException exceptionWithName:NSFUnexpectedParameterException
49
+ reason:[NSString stringWithFormat:@"*** -[%@ %s]: theAttribute is invalid.", [self class], _cmd]
50
+ userInfo:nil]raise];
51
+
52
+ if ((self = [super init])) {
53
+ attribute = [theAttribute copy];
54
+ isAscending = ascending;
55
+ }
56
+
57
+ return self;
58
+ }
59
+
60
+ /** \cond */
61
+
62
+
63
+ /** \endcond */
64
+
65
+ #pragma mark -
66
+
67
+ - (NSString*)description
68
+ {
69
+ NSMutableString *description = [NSMutableString string];
70
+
71
+ [description appendString:@"\n"];
72
+ [description appendString:[NSString stringWithFormat:@"Sort descriptor address : 0x%x\n", self]];
73
+ [description appendString:[NSString stringWithFormat:@"Attribute : %@\n", attribute]];
74
+ [description appendString:[NSString stringWithFormat:@"Is ascending? : %@\n", (isAscending ? @"YES" : @"NO")]];
75
+
76
+ return description;
77
+ }
78
+
79
+ @end
@@ -0,0 +1,475 @@
1
+ /*
2
+ NSFNanoStore.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ /*! @file NSFNanoStore.h
28
+ @brief The document store is where the objects get saved. It can be file-based (permanent of temporary) or memory-backed.
29
+ */
30
+
31
+ /** @class NSFNanoStore
32
+ * The document store is where the objects get saved. It can be file-based (permanent of temporary) or memory-backed.
33
+ *
34
+ * @details <b>Example:</b>
35
+ @code
36
+ // Instantiate a NanoStore and open it
37
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
38
+
39
+ // Add some data to the document store
40
+ NSDictionary *info = ...;
41
+ NSFNanoObject *object = [NSFNanoObject nanoObjectWithDictionary:info];
42
+ [nanoStore addObject:object error:nil];
43
+
44
+ // Return all objects via NSFNanoSearch
45
+ NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
46
+ NSDictionary *searchResults = [search searchObjectsWithReturnType:NSFReturnObjects error:nil];
47
+
48
+ // Return the keys of all objects
49
+ NSArray *keys = [search searchObjectsWithReturnType:NSFReturnKeys error:nil];
50
+
51
+ // Search one or more objects with a series of keys via NSFNanoStore
52
+ NSArray *objects = [nanoStore objectsWithKeysInArray:[NSArray arrayWithObject:@"ABC-123"]];
53
+
54
+ // Search an object with a given key via NSFNanoSearch
55
+ [search setKey:@"ABC-123"];
56
+ objects = [search searchObjectsWithReturnType:NSFReturnObjects error:nil];
57
+
58
+ // Remove an object from the document store
59
+ [nanoStore removeObject:object error:nil];
60
+
61
+ // Close the document store
62
+ [nanoStore closeWithError:nil];
63
+ @endcode
64
+ */
65
+
66
+ #import <Foundation/Foundation.h>
67
+
68
+ #import <sqlite3.h>
69
+
70
+ @class NSFNanoEngine, NSFNanoResult, NSFNanoBag, NSFNanoSortDescriptor;
71
+
72
+ @interface NSFNanoStore : NSObject
73
+
74
+ /** * A reference to the engine used by the document store, which contains a reference to the SQLite database. */
75
+ @property (nonatomic, strong, readonly) NSFNanoEngine *nanoStoreEngine;
76
+ /** * The type of engine mode used by NanoStore to process data in the document store.
77
+ The mode can be one of two options: <i>NSFEngineProcessingDefaultMode</i> and <i>NSFEngineProcessingFastMode</i>. See <i>NSFEngineProcessingMode</i>
78
+ to learn more about how these options affect the engine behavior.
79
+
80
+ In default mode, the pragmas are set as follows:
81
+
82
+ - PRAGMA fullfsync = OFF;
83
+ - PRAGMA synchronous = FULL;
84
+ - PRAGMA journal_mode = DELETE;
85
+ - PRAGMA temp_store = DEFAULT;
86
+
87
+ In fast mode, the pragmas are set to:
88
+
89
+ - PRAGMA fullfsync = OFF;
90
+ - PRAGMA synchronous = OFF;
91
+ - PRAGMA journal_mode = MEMORY;
92
+ - PRAGMA temp_store = MEMORY;
93
+
94
+ @note Set this property before you open the document store.
95
+ @see - (BOOL)openWithError:(out NSError **)outError;
96
+ */
97
+ @property (nonatomic, assign, readwrite) NSFEngineProcessingMode nanoEngineProcessingMode;
98
+ /** * Number of iterations that will trigger an automatic save. */
99
+ @property (nonatomic, assign, readwrite) NSUInteger saveInterval;
100
+ /** * Whether there are objects that haven't been saved to the store. */
101
+ @property (nonatomic, readonly) BOOL hasUnsavedChanges;
102
+
103
+ /** @name Creating and Initializing NanoStore
104
+ */
105
+
106
+ //@{
107
+
108
+ /** * Creates and returns a document store of a specific type at a given file path.
109
+ * @param theType the type of document store that will be created.
110
+ * @param thePath the file path where the document store will be created. Can be nil (see warning for additional info).
111
+ * @return A document store upon success, nil otherwise.
112
+ * @note
113
+ * To manipulate the document store, you must first open it. If you don't need to configure settings for the document store, you can use
114
+ * \link createAndOpenStoreWithType:path:error: + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath error:(out NSError **)outError \endlink instead.
115
+ * @warning
116
+ * The path is only meaningful for document stores of type \link NSFGlobals::NSFPersistentStoreType NSFPersistentStoreType \endlink. It must not be nil.
117
+ * @throws NSFUnexpectedParameterException is thrown if the file path is nil or empty and the type is set to @ref NSFPersistentStoreType "NSFPersistentStoreType".
118
+ * @see \link openWithError: - (BOOL)openWithError:(out NSError **)outError \endlink
119
+ * @see \link createAndOpenStoreWithType:path:error: + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath error:(out NSError **)outError \endlink
120
+ */
121
+
122
+ + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath;
123
+
124
+ /** * Creates, opens and returns a document store of a specific type at a given file path.
125
+ * @param theType the type of document store that will be created.
126
+ * @param thePath the file path where the document store will be created. Can be nil (see warning for additional info).
127
+ * @param outError is used if an error occurs. May be NULL.
128
+ * @return A document store upon success, nil otherwise.
129
+ * @note
130
+ * If you need to configure settings for the document store, you can use \link createStoreWithType:path: + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath \endlink instead.
131
+ * @warning
132
+ * The path is only meaningful for document stores of type @ref NSFPersistentStoreType "NSFPersistentStoreType". It must not be nil.
133
+ * @throws NSFUnexpectedParameterException is thrown if the file path is nil or empty and the type is set to @ref NSFPersistentStoreType "NSFPersistentStoreType".
134
+ * @see \link openWithError: - (BOOL)openWithError:(out NSError **)outError \endlink
135
+ * @see \link createStoreWithType:path: + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath \endlink
136
+ */
137
+
138
+ + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath error:(out NSError **)outError;
139
+
140
+ /** * Initializes a newly allocated document store of a specific type at a given file path.
141
+ * @param theType the type of document store that will be created.
142
+ * @param thePath the file path where the document store will be created. Can be nil (see note for additional info).
143
+ * @return A document store upon success, nil otherwise.
144
+ * @note
145
+ * To manipulate the document store, you must first open it. If you don't need to configure settings for the document store, you can use
146
+ * \link createAndOpenStoreWithType:path:error: + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath error:(out NSError **)outError \endlink instead.
147
+ * @warning
148
+ * The path is only meaningful for document stores of type @ref NSFPersistentStoreType "NSFPersistentStoreType". It must not be nil.
149
+ * @throws NSFUnexpectedParameterException is thrown if the file path is nil and the type is set to @ref NSFPersistentStoreType "NSFPersistentStoreType".
150
+ * @see \link openWithError: - (BOOL)openWithError:(out NSError **)outError \endlink
151
+ * @see \link createAndOpenStoreWithType:path:error: + (NSFNanoStore *)createAndOpenStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath error:(out NSError **)outError \endlink
152
+ */
153
+
154
+ - (id)initStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath;
155
+
156
+ //@}
157
+
158
+ /** @name Opening and Closing
159
+ */
160
+
161
+ //@{
162
+
163
+ /** * Opens the document store, making it ready for manipulation.
164
+ * @param outError is used if an error occurs. May be NULL.
165
+ * @return YES upon success, NO otherwise.
166
+ * @note The document store needs to be opened only after opening a document store via
167
+ * \link createStoreWithType:path: + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath\endlink.
168
+ * The property nanoEngineProcessingMode allows to set the type of engine mode used by NanoStore to process data in the document store. Set this property before you open the document store.
169
+ * @see \link createStoreWithType:path: + (NSFNanoStore *)createStoreWithType:(NSFNanoStoreType)theType path:(NSString *)thePath \endlink
170
+ */
171
+
172
+ - (BOOL)openWithError:(out NSError **)outError;
173
+
174
+ /** * Closes the document store.
175
+ * @param outError is used if an error occurs. May be NULL.
176
+ * @see \link isClosed - (BOOL)isClosed \endlink
177
+ */
178
+
179
+ - (BOOL)closeWithError:(out NSError **)outError;
180
+
181
+ //@}
182
+
183
+ /** @name Accessors
184
+ */
185
+
186
+ //@{
187
+
188
+ /** * Location where the document store is found.
189
+ * @note If the document store is file-based, its path will be returned. If it's a memory-backed document store, \link :Globals::NSFMemoryDatabase NSFMemoryDatabase \endlink will be returned instead.
190
+ */
191
+
192
+ - (NSString *)filePath;
193
+
194
+ /** * Checks whether the document store is closed or open.
195
+ * @see \link close - (void)close \endlink
196
+ */
197
+
198
+ - (BOOL)isClosed;
199
+
200
+ //@}
201
+
202
+ /** @name Adding and Removing Objects
203
+ */
204
+
205
+ //@{
206
+
207
+ /** * Adds an \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object to the document store.
208
+ * @param theObject is added to the document store.
209
+ * @param outError is used if an error occurs. May be NULL.
210
+ * @return YES upon success, NO otherwise.
211
+ * @warning This value cannot be nil and it must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
212
+ * @throws NSFNonConformingNanoObjectProtocolException is thrown if the object is non-\link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink compliant.
213
+ * @see \link addObjectsFromArray:error: - (BOOL)addObjectsFromArray:(NSArray *)theObjects error:(out NSError **)outError \endlink
214
+ */
215
+
216
+ - (BOOL)addObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError;
217
+
218
+ /** * Adds a series of \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant objects to the document store.
219
+ * @param theObjects is an array of objects to be added to the document store. The objects must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
220
+ * @param outError is used if an error occurs. May be NULL.
221
+ * @return YES upon success, NO otherwise.
222
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
223
+ * @throws NSFNonConformingNanoObjectProtocolException is thrown if the object is non-\link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink compliant.
224
+ * @see \link addObject:error: - (BOOL)addObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError \endlink
225
+ */
226
+
227
+ - (BOOL)addObjectsFromArray:(NSArray *)theObjects error:(out NSError **)outError;
228
+
229
+ /** * Removes an object from the document store.
230
+ * @param theObject the object to be removed from the document store.
231
+ * @param outError is used if an error occurs. May be NULL.
232
+ * @return YES upon success, NO otherwise.
233
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
234
+ * @see \link removeObjectsWithKeysInArray:error: - (BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError \endlink
235
+ * @see \link removeObjectsInArray:error: - (BOOL)removeObjectsInArray:(NSArray *)theObjects error:(out NSError **)outError \endlink
236
+ * @see \link removeAllObjectsFromStoreAndReturnError: - (BOOL)removeAllObjectsFromStoreAndReturnError:(out NSError **)outError \endlink
237
+ */
238
+
239
+ - (BOOL)removeObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError;
240
+
241
+ /** * Removes the list of objects with the specified keys from the document store.
242
+ * @param theKeys the list of keys to be removed from the document store.
243
+ * @param outError is used if an error occurs. May be NULL.
244
+ * @return YES upon success, NO otherwise.
245
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
246
+ * @see \link removeObject:error: - (BOOL)removeObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError \endlink
247
+ * @see \link removeObjectsInArray:error: - (BOOL)removeObjectsInArray:(NSArray *)theObjects error:(out NSError **)outError \endlink
248
+ * @see \link removeAllObjectsFromStoreAndReturnError: - (BOOL)removeAllObjectsFromStoreAndReturnError:(out NSError **)outError \endlink
249
+ */
250
+
251
+ - (BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError;
252
+
253
+ /** * Removes the list of objects from the document store.
254
+ * @param theObjects the list of objects to be removed from the document store.
255
+ * @param outError is used if an error occurs. May be NULL.
256
+ * @return YES upon success, NO otherwise.
257
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
258
+ * @see \link removeObject:error: - (BOOL)removeObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError \endlink
259
+ * @see \link removeObjectsWithKeysInArray:error: - (BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError \endlink
260
+ * @see \link removeAllObjectsFromStoreAndReturnError: - (BOOL)removeAllObjectsFromStoreAndReturnError:(out NSError **)outError \endlink
261
+ */
262
+
263
+ - (BOOL)removeObjectsInArray:(NSArray *)theObjects error:(out NSError **)outError;
264
+
265
+ /** * Removes all objects from the document store.
266
+ * @param outError is used if an error occurs. May be NULL.
267
+ * @return YES upon success, NO otherwise.
268
+ * @note Please note that the unoccupied space will not be reclaimed, so after clearing the cache use \link compactStoreAndReturnError: - (BOOL)compactStoreAndReturnError:(out NSError **)outError \endlink
269
+ * if you want to decrease the database file size.
270
+ * @see \link removeObject:error: - (BOOL)removeObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError \endlink
271
+ * @see \link removeObjectsWithKeysInArray:error: - (BOOL)removeObjectsWithKeysInArray:(NSArray *)theKeys error:(out NSError **)outError \endlink
272
+ * @see \link removeObjectsInArray:error: - (BOOL)removeObjectsInArray:(NSArray *)theObjects error:(out NSError **)outError \endlink
273
+ */
274
+
275
+ - (BOOL)removeAllObjectsFromStoreAndReturnError:(out NSError **)outError;
276
+
277
+ //@}
278
+
279
+ /** @name Searching and Gathering Data
280
+ */
281
+
282
+ //@{
283
+
284
+ /** * Returns a new array containing the bags found in the document store.
285
+ * @returns An array with the bags found in the document store.
286
+ * @see \link bagsWithKeysInArray: - (NSArray *)bagsWithKeysInArray:(NSArray *)theKeys \endlink
287
+ * @see \link bagsContainingObjectWithKey: - (NSArray *)bagsContainingObjectWithKey:(NSString *)theKey \endlink
288
+ */
289
+
290
+ - (NSArray *)bags;
291
+
292
+ /** * Retrieves the bag associated with the specified name.
293
+ * @param theName the name of the bag.
294
+ * @returns The bag that matches the specified name, nil otherwise.
295
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
296
+ */
297
+
298
+ - (NSFNanoBag *)bagWithName:(NSString *)theName;
299
+
300
+ /** * Returns a new array containing the bags found in the document store matching the specified list of keys.
301
+ * @param theKeys the list of bag keys.
302
+ * @returns An array with the bags that match the specified list of keys.
303
+ * @see \link bags - (NSArray *)bags \endlink
304
+ * @see \link bagsContainingObjectWithKey: - (NSArray *)bagsContainingObjectWithKey:(NSString *)theKey \endlink
305
+ */
306
+
307
+ - (NSArray *)bagsWithKeysInArray:(NSArray *)theKeys;
308
+
309
+ /** * Returns a new array containing the bags found in the document store which contain the object specified by the key.
310
+ * @param theKey the key of the object.
311
+ * @returns An array with the bags that contain the object matching the specified key.
312
+ * @see \link bags - (NSArray *)bags \endlink
313
+ * @see \link bagsWithKeysInArray: - (NSArray *)bagsWithKeysInArray:(NSArray *)theKeys \endlink
314
+ */
315
+
316
+ - (NSArray *)bagsContainingObjectWithKey:(NSString *)theKey;
317
+
318
+ /** * Returns a new array containing the objects found in the document store matching the specified list of keys.
319
+ * @param theKeys the list of \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object keys.
320
+ * @returns An array with the objects matching the specified list of keys.
321
+ * @note The keys can belong to any object class: NSFNanoObject, NSFNanoBag or any \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object.
322
+ */
323
+
324
+ - (NSArray *)objectsWithKeysInArray:(NSArray *)theKeys;
325
+
326
+ /** * Returns a new array containing the objects classes in the document store.
327
+ * @returns An array of the class names found in the document store.
328
+ * @note The classes can be NSFNanoObject, NSFNanoBag or any \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object.
329
+ */
330
+
331
+ - (NSArray *)allObjectClasses;
332
+
333
+ /** * Returns an array containing the objects in the document store which match a specific class name.
334
+ * @param theClassName the name of the class that will be used for searching. Cannot be NULL.
335
+ * @returns An array of objects of the specified class name.
336
+ * @note The classes can be NSFNanoObject, NSFNanoBag or any \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object.
337
+ * @throws NSFUnexpectedParameterException is thrown if the class name is nil or empty.
338
+ */
339
+
340
+ - (NSArray *)objectsOfClassNamed:(NSString *)theClassName;
341
+
342
+ /** * Returns a sorted array containing the objects in the document store which match a specific class name.
343
+ * @param theClassName the name of the class that will be used for searching. Cannot be NULL.
344
+ * @param theSortDescriptors the array of descriptors used to sort the array. May be NULL.
345
+ * @returns An array of objects of the specified class name sorted if the sort descriptor was specified.
346
+ * @note The classes can be NSFNanoObject, NSFNanoBag or any \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object.
347
+ * @throws NSFUnexpectedParameterException is thrown if the class name is nil or empty.
348
+ */
349
+
350
+ - (NSArray *)objectsOfClassNamed:(NSString *)theClassName usingSortDescriptors:(NSArray *)theSortDescriptors;
351
+
352
+ /** * Returns the number of objects in the document store which match a specific class name.
353
+ * @param theClassName the name of the class that will be used for searching. Cannot be NULL.
354
+ * @returns The count of objects of the specified class name.
355
+ * @note The classes can be NSFNanoObject, NSFNanoBag or any \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object.
356
+ * @throws NSFUnexpectedParameterException is thrown if the class name is nil or empty.
357
+ */
358
+
359
+ - (long long)countOfObjectsOfClassNamed:(NSString *)theClassName;
360
+
361
+ //@}
362
+
363
+ /** @name Saving and Maintenance
364
+ */
365
+
366
+ //@{
367
+
368
+ /** * Saves the uncommitted changes to the document store.
369
+ * @param outError is used if an error occurs. May be NULL.
370
+ * @return YES upon success, NO otherwise.
371
+ * @note After storing several objects and depending on the save interval, some objects could be left in the cache in an unsaved state.
372
+ * Therefore, it's always a good idea to call \link saveStoreAndReturnError: - (BOOL)saveStoreAndReturnError:(out NSError **)outError \endlink
373
+ * @see \link discardUnsavedChanges - (void)discardUnsavedChanges \endlink
374
+ */
375
+
376
+ - (BOOL)saveStoreAndReturnError:(out NSError **)outError;
377
+
378
+ /** * Discards the uncommitted changes that were added to the document store.
379
+ * @see \link saveStoreAndReturnError: - (BOOL)saveStoreAndReturnError:(out NSError **)outError \endlink
380
+ */
381
+
382
+ - (void)discardUnsavedChanges;
383
+
384
+ /** * Compact the database file size.
385
+ * @param outError is used if an error occurs. May be NULL.
386
+ * @return YES upon success, NO otherwise.
387
+ */
388
+
389
+ - (BOOL)compactStoreAndReturnError:(out NSError **)outError;
390
+
391
+ /** * Remove all indexes from the document store.
392
+ * @param outError is used if an error occurs. May be NULL.
393
+ * @return YES upon success, NO otherwise.
394
+ * @note Clearing the indexes could speed up document store manipulations (insertions, updates and deletions).
395
+ * @see \link rebuildIndexesAndReturnError: - (BOOL)rebuildIndexesAndReturnError:(out NSError **)outError \endlink
396
+ */
397
+
398
+ - (BOOL)clearIndexesAndReturnError:(out NSError **)outError;
399
+
400
+ /** * Recreate all indexes from the document store.
401
+ * @param outError is used if an error occurs. May be NULL.
402
+ * @return YES upon success, NO otherwise.
403
+ * @note Rebuilding the indexes recreates the indexes previously removed with \link clearIndexesAndReturnError: - (BOOL)clearIndexesAndReturnError:(out NSError **)outError \endlink.
404
+ * @see \link clearIndexesAndReturnError: - (BOOL)clearIndexesAndReturnError:(out NSError **)outError \endlink
405
+ */
406
+
407
+ - (BOOL)rebuildIndexesAndReturnError:(out NSError **)outError;
408
+
409
+ /** * Makes a copy of the document store to a different location and optionally compacts it to its minimum size.
410
+ * @param thePath is the location where the document store should be copied to.
411
+ * @param shouldCompact is used to flag whether the document store should be compacted.
412
+ * @param outError is used if an error occurs. May be NULL.
413
+ * @return YES upon success, NO otherwise.
414
+ * @note Works with both, file-based and memory-backed document stores.
415
+ * @see \link clearIndexesAndReturnError: - (BOOL)clearIndexesAndReturnError:(out NSError **)outError \endlink
416
+ */
417
+
418
+ - (BOOL)saveStoreToDirectoryAtPath:(NSString *)thePath compactDatabase:(BOOL)shouldCompact error:(out NSError **)outError;
419
+
420
+ //@}
421
+
422
+ /** @name Transactions
423
+ */
424
+
425
+ //@{
426
+
427
+ /** * Start a transaction.
428
+ * @param outError is used if an error occurs. May be NULL.
429
+ * @return YES upon success, NO otherwise.
430
+ * @attention Use this method instead of the ones provided by NSFNanoEngine.
431
+ * @see \link clearIndexesAndReturnError: - (BOOL)clearIndexesAndReturnError:(out NSError **)outError \endlink
432
+ * @see \link commitTransactionAndReturnError: - (BOOL)commitTransactionAndReturnError:(out NSError **)outError \endlink
433
+ * @see \link rollbackTransactionAndReturnError: - (BOOL)rollbackTransactionAndReturnError:(out NSError **)outError \endlink
434
+ */
435
+
436
+ - (BOOL)beginTransactionAndReturnError:(out NSError **)outError;
437
+
438
+ /** * Commit a transaction.
439
+ * @param outError is used if an error occurs. May be NULL.
440
+ * @return YES upon success, NO otherwise.
441
+ * @attention Use this method instead of the ones provided by NSFNanoEngine.
442
+ * @see \link rebuildIndexesAndReturnError: - (BOOL)rebuildIndexesAndReturnError:(out NSError **)outError \endlink
443
+ * @see \link beginTransactionAndReturnError: - (BOOL)beginTransactionAndReturnError:(out NSError **)outError \endlink
444
+ * @see \link rollbackTransactionAndReturnError: - (BOOL)rollbackTransactionAndReturnError:(out NSError **)outError \endlink
445
+ */
446
+
447
+ - (BOOL)commitTransactionAndReturnError:(out NSError **)outError;
448
+
449
+ /** * Rollback a transaction.
450
+ * @param outError is used if an error occurs. May be NULL.
451
+ * @return YES upon success, NO otherwise.
452
+ * @attention Use this method instead of the ones provided by NSFNanoEngine.
453
+ * @see \link rebuildIndexesAndReturnError: - (BOOL)rebuildIndexesAndReturnError:(out NSError **)outError \endlink
454
+ * @see \link beginTransactionAndReturnError: - (BOOL)beginTransactionAndReturnError:(out NSError **)outError \endlink
455
+ * @see \link commitTransactionAndReturnError: - (BOOL)commitTransactionAndReturnError:(out NSError **)outError \endlink
456
+ */
457
+
458
+ - (BOOL)rollbackTransactionAndReturnError:(out NSError **)outError;
459
+
460
+ //@}
461
+
462
+ /** @name Miscellaneous
463
+ */
464
+
465
+ //@{
466
+
467
+ /** * Returns a string representation of the store.
468
+ * @note Check properties nanoEngineProcessingMode and saveInterval to find out the current state of the object.
469
+ */
470
+
471
+ - (NSString *)description;
472
+
473
+ //@}
474
+
475
+ @end