Mercurial > projects > dstep
comparison dstep/coredata/NSPersistentStoreCoordinator.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Sep 25, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.coredata.NSPersistentStoreCoordinator; | |
8 | |
9 import dstep.coredata.CoreDataDefines; | |
10 import dstep.coredata.NSManagedObjectID; | |
11 import dstep.coredata.NSManagedObjectModel; | |
12 import dstep.coredata.NSPersistentStore; | |
13 import dstep.foundation.NSArray; | |
14 import dstep.foundation.NSDictionary; | |
15 import dstep.foundation.NSError; | |
16 import dstep.foundation.NSLock; | |
17 import dstep.foundation.NSObject; | |
18 import dstep.foundation.NSString; | |
19 import dstep.foundation.NSURL; | |
20 import dstep.objc.bridge.Bridge; | |
21 import dstep.objc.objc; | |
22 | |
23 import bindings = dstep.coredata.NSPersistentStoreCoordinator_bindings; | |
24 | |
25 private | |
26 { | |
27 NSString NSSQLiteStoreType_; | |
28 NSString NSXMLStoreType_; | |
29 NSString NSBinaryStoreType_; | |
30 NSString NSInMemoryStoreType_; | |
31 NSString NSStoreTypeKey_; | |
32 NSString NSStoreUUIDKey_; | |
33 NSString NSPersistentStoreCoordinatorStoresDidChangeNotification_; | |
34 NSString NSAddedPersistentStoresKey_; | |
35 NSString NSRemovedPersistentStoresKey_; | |
36 NSString NSUUIDChangedPersistentStoresKey_; | |
37 NSString NSReadOnlyPersistentStoreOption_; | |
38 NSString NSValidateXMLStoreOption_; | |
39 NSString NSPersistentStoreTimeoutOption_; | |
40 NSString NSSQLitePragmasOption_; | |
41 NSString NSIgnorePersistentStoreVersioningOption_; | |
42 NSString NSMigratePersistentStoresAutomaticallyOption_; | |
43 NSString NSStoreModelVersionHashesKey_; | |
44 NSString NSStoreModelVersionIdentifiersKey_; | |
45 NSString NSPersistentStoreOSCompatibility_; | |
46 } | |
47 | |
48 NSString NSSQLiteStoreType () | |
49 { | |
50 if (NSSQLiteStoreType_) | |
51 return NSSQLiteStoreType_; | |
52 | |
53 return NSSQLiteStoreType_ = new NSString(bindings.NSSQLiteStoreType); | |
54 } | |
55 | |
56 NSString NSXMLStoreType () | |
57 { | |
58 if (NSXMLStoreType_) | |
59 return NSXMLStoreType_; | |
60 | |
61 return NSXMLStoreType_ = new NSString(bindings.NSXMLStoreType); | |
62 } | |
63 | |
64 NSString NSBinaryStoreType () | |
65 { | |
66 if (NSBinaryStoreType_) | |
67 return NSBinaryStoreType_; | |
68 | |
69 return NSBinaryStoreType_ = new NSString(bindings.NSBinaryStoreType); | |
70 } | |
71 | |
72 NSString NSInMemoryStoreType () | |
73 { | |
74 if (NSInMemoryStoreType_) | |
75 return NSInMemoryStoreType_; | |
76 | |
77 return NSInMemoryStoreType_ = new NSString(bindings.NSInMemoryStoreType); | |
78 } | |
79 | |
80 NSString NSStoreTypeKey () | |
81 { | |
82 if (NSStoreTypeKey_) | |
83 return NSStoreTypeKey_; | |
84 | |
85 return NSStoreTypeKey_ = new NSString(bindings.NSStoreTypeKey); | |
86 } | |
87 | |
88 NSString NSStoreUUIDKey () | |
89 { | |
90 if (NSStoreUUIDKey_) | |
91 return NSStoreUUIDKey_; | |
92 | |
93 return NSStoreUUIDKey_ = new NSString(bindings.NSStoreUUIDKey); | |
94 } | |
95 | |
96 NSString NSPersistentStoreCoordinatorStoresDidChangeNotification () | |
97 { | |
98 if (NSPersistentStoreCoordinatorStoresDidChangeNotification_) | |
99 return NSPersistentStoreCoordinatorStoresDidChangeNotification_; | |
100 | |
101 return NSPersistentStoreCoordinatorStoresDidChangeNotification_ = new NSString(bindings.NSPersistentStoreCoordinatorStoresDidChangeNotification); | |
102 } | |
103 | |
104 NSString NSAddedPersistentStoresKey () | |
105 { | |
106 if (NSAddedPersistentStoresKey_) | |
107 return NSAddedPersistentStoresKey_; | |
108 | |
109 return NSAddedPersistentStoresKey_ = new NSString(bindings.NSAddedPersistentStoresKey); | |
110 } | |
111 | |
112 NSString NSRemovedPersistentStoresKey () | |
113 { | |
114 if (NSRemovedPersistentStoresKey_) | |
115 return NSRemovedPersistentStoresKey_; | |
116 | |
117 return NSRemovedPersistentStoresKey_ = new NSString(bindings.NSRemovedPersistentStoresKey); | |
118 } | |
119 | |
120 NSString NSUUIDChangedPersistentStoresKey () | |
121 { | |
122 if (NSUUIDChangedPersistentStoresKey_) | |
123 return NSUUIDChangedPersistentStoresKey_; | |
124 | |
125 return NSUUIDChangedPersistentStoresKey_ = new NSString(bindings.NSUUIDChangedPersistentStoresKey); | |
126 } | |
127 | |
128 NSString NSReadOnlyPersistentStoreOption () | |
129 { | |
130 if (NSReadOnlyPersistentStoreOption_) | |
131 return NSReadOnlyPersistentStoreOption_; | |
132 | |
133 return NSReadOnlyPersistentStoreOption_ = new NSString(bindings.NSReadOnlyPersistentStoreOption); | |
134 } | |
135 | |
136 NSString NSValidateXMLStoreOption () | |
137 { | |
138 if (NSValidateXMLStoreOption_) | |
139 return NSValidateXMLStoreOption_; | |
140 | |
141 return NSValidateXMLStoreOption_ = new NSString(bindings.NSValidateXMLStoreOption); | |
142 } | |
143 | |
144 NSString NSPersistentStoreTimeoutOption () | |
145 { | |
146 if (NSPersistentStoreTimeoutOption_) | |
147 return NSPersistentStoreTimeoutOption_; | |
148 | |
149 return NSPersistentStoreTimeoutOption_ = new NSString(bindings.NSPersistentStoreTimeoutOption); | |
150 } | |
151 | |
152 NSString NSSQLitePragmasOption () | |
153 { | |
154 if (NSSQLitePragmasOption_) | |
155 return NSSQLitePragmasOption_; | |
156 | |
157 return NSSQLitePragmasOption_ = new NSString(bindings.NSSQLitePragmasOption); | |
158 } | |
159 | |
160 NSString NSIgnorePersistentStoreVersioningOption () | |
161 { | |
162 if (NSIgnorePersistentStoreVersioningOption_) | |
163 return NSIgnorePersistentStoreVersioningOption_; | |
164 | |
165 return NSIgnorePersistentStoreVersioningOption_ = new NSString(bindings.NSIgnorePersistentStoreVersioningOption); | |
166 } | |
167 | |
168 NSString NSMigratePersistentStoresAutomaticallyOption () | |
169 { | |
170 if (NSMigratePersistentStoresAutomaticallyOption_) | |
171 return NSMigratePersistentStoresAutomaticallyOption_; | |
172 | |
173 return NSMigratePersistentStoresAutomaticallyOption_ = new NSString(bindings.NSMigratePersistentStoresAutomaticallyOption); | |
174 } | |
175 | |
176 NSString NSStoreModelVersionHashesKey () | |
177 { | |
178 if (NSStoreModelVersionHashesKey_) | |
179 return NSStoreModelVersionHashesKey_; | |
180 | |
181 return NSStoreModelVersionHashesKey_ = new NSString(bindings.NSStoreModelVersionHashesKey); | |
182 } | |
183 | |
184 NSString NSStoreModelVersionIdentifiersKey () | |
185 { | |
186 if (NSStoreModelVersionIdentifiersKey_) | |
187 return NSStoreModelVersionIdentifiersKey_; | |
188 | |
189 return NSStoreModelVersionIdentifiersKey_ = new NSString(bindings.NSStoreModelVersionIdentifiersKey); | |
190 } | |
191 | |
192 NSString NSPersistentStoreOSCompatibility () | |
193 { | |
194 if (NSPersistentStoreOSCompatibility_) | |
195 return NSPersistentStoreOSCompatibility_; | |
196 | |
197 return NSPersistentStoreOSCompatibility_ = new NSString(bindings.NSPersistentStoreOSCompatibility); | |
198 } | |
199 | |
200 class NSPersistentStoreCoordinator : NSObject, INSLocking | |
201 { | |
202 mixin (ObjcWrap); | |
203 | |
204 static NSDictionary registeredStoreTypes () | |
205 { | |
206 return invokeObjcSelfClass!(NSDictionary, "registeredStoreTypes"); | |
207 } | |
208 | |
209 static void registerStoreClass (Class storeClass, NSString storeType) | |
210 { | |
211 return invokeObjcSelfClass!(void, "registerStoreClass:forStoreType:", Class, NSString)(storeClass, storeType); | |
212 } | |
213 | |
214 static NSDictionary metadataForPersistentStoreOfType (NSString storeType, NSURL url, ref NSError error) | |
215 { | |
216 id __arg2; | |
217 | |
218 if (error) | |
219 __arg2 = error.objcObject; | |
220 | |
221 NSDictionary result = invokeObjcSelfClass!(NSDictionary, "metadataForPersistentStoreOfType:URL:error:", NSString, NSURL, id*)(storeType, url, &__arg2); | |
222 | |
223 if (__arg2) | |
224 error = new NSError(__arg2); | |
225 | |
226 return result; | |
227 } | |
228 | |
229 static bool setMetadata (NSDictionary metadata, NSString storeType, NSURL url, ref NSError error) | |
230 { | |
231 id __arg3; | |
232 | |
233 if (error) | |
234 __arg3 = error.objcObject; | |
235 | |
236 bool result = invokeObjcSelfClass!(bool, "setMetadata:forPersistentStoreOfType:URL:error:", NSDictionary, NSString, NSURL, id*)(metadata, storeType, url, &__arg3); | |
237 | |
238 if (__arg3) | |
239 error = new NSError(__arg3); | |
240 | |
241 return result; | |
242 } | |
243 | |
244 void setMetadata (NSDictionary metadata, NSPersistentStore store) | |
245 { | |
246 return invokeObjcSelf!(void, "setMetadata:forPersistentStore:", NSDictionary, NSPersistentStore)(metadata, store); | |
247 } | |
248 | |
249 NSDictionary metadataForPersistentStore (NSPersistentStore store) | |
250 { | |
251 return invokeObjcSelf!(NSDictionary, "metadataForPersistentStore:", NSPersistentStore)(store); | |
252 } | |
253 | |
254 NSPersistentStoreCoordinator initWithManagedObjectModel (NSManagedObjectModel model) | |
255 { | |
256 id result = invokeObjcSelf!(id, "initWithManagedObjectModel:", NSManagedObjectModel)(model); | |
257 return result is this.objcObject ? this : (result !is null ? new NSPersistentStoreCoordinator(result) : null); | |
258 } | |
259 | |
260 this (NSManagedObjectModel model) | |
261 { | |
262 super(NSPersistentStoreCoordinator.alloc.initWithManagedObjectModel(model).objcObject); | |
263 } | |
264 | |
265 NSManagedObjectModel managedObjectModel () | |
266 { | |
267 return invokeObjcSelf!(NSManagedObjectModel, "managedObjectModel"); | |
268 } | |
269 | |
270 NSArray persistentStores () | |
271 { | |
272 return invokeObjcSelf!(NSArray, "persistentStores"); | |
273 } | |
274 | |
275 NSPersistentStore persistentStoreForURL (NSURL URL) | |
276 { | |
277 return invokeObjcSelf!(NSPersistentStore, "persistentStoreForURL:", NSURL)(URL); | |
278 } | |
279 | |
280 NSURL URLForPersistentStore (NSPersistentStore store) | |
281 { | |
282 return invokeObjcSelf!(NSURL, "URLForPersistentStore:", NSPersistentStore)(store); | |
283 } | |
284 | |
285 bool setURL (NSURL url, NSPersistentStore store) | |
286 { | |
287 return invokeObjcSelf!(bool, "setURL:forPersistentStore:", NSURL, NSPersistentStore)(url, store); | |
288 } | |
289 | |
290 NSPersistentStore addPersistentStoreWithType (NSString storeType, NSString configuration, NSURL storeURL, NSDictionary options, ref NSError error) | |
291 { | |
292 id __arg4; | |
293 | |
294 if (error) | |
295 __arg4 = error.objcObject; | |
296 | |
297 NSPersistentStore result = invokeObjcSelf!(NSPersistentStore, "addPersistentStoreWithType:configuration:URL:options:error:", NSString, NSString, NSURL, NSDictionary, id*)(storeType, configuration, storeURL, options, &__arg4); | |
298 | |
299 if (__arg4) | |
300 error = new NSError(__arg4); | |
301 | |
302 return result; | |
303 } | |
304 | |
305 bool removePersistentStore (NSPersistentStore store, ref NSError error) | |
306 { | |
307 id __arg1; | |
308 | |
309 if (error) | |
310 __arg1 = error.objcObject; | |
311 | |
312 bool result = invokeObjcSelf!(bool, "removePersistentStore:error:", NSPersistentStore, id*)(store, &__arg1); | |
313 | |
314 if (__arg1) | |
315 error = new NSError(__arg1); | |
316 | |
317 return result; | |
318 } | |
319 | |
320 NSPersistentStore migratePersistentStore (NSPersistentStore store, NSURL URL, NSDictionary options, NSString storeType, ref NSError error) | |
321 { | |
322 id __arg4; | |
323 | |
324 if (error) | |
325 __arg4 = error.objcObject; | |
326 | |
327 NSPersistentStore result = invokeObjcSelf!(NSPersistentStore, "migratePersistentStore:toURL:options:withType:error:", NSPersistentStore, NSURL, NSDictionary, NSString, id*)(store, URL, options, storeType, &__arg4); | |
328 | |
329 if (__arg4) | |
330 error = new NSError(__arg4); | |
331 | |
332 return result; | |
333 } | |
334 | |
335 NSManagedObjectID managedObjectIDForURIRepresentation (NSURL url) | |
336 { | |
337 return invokeObjcSelf!(NSManagedObjectID, "managedObjectIDForURIRepresentation:", NSURL)(url); | |
338 } | |
339 | |
340 void lock () | |
341 { | |
342 return invokeObjcSelf!(void, "lock"); | |
343 } | |
344 | |
345 void unlock () | |
346 { | |
347 return invokeObjcSelf!(void, "unlock"); | |
348 } | |
349 | |
350 bool tryLock () | |
351 { | |
352 return invokeObjcSelf!(bool, "tryLock"); | |
353 } | |
354 | |
355 static NSDictionary metadataForPersistentStoreWithURL (NSURL url, ref NSError error) | |
356 { | |
357 id __arg1; | |
358 | |
359 if (error) | |
360 __arg1 = error.objcObject; | |
361 | |
362 NSDictionary result = invokeObjcSelfClass!(NSDictionary, "metadataForPersistentStoreWithURL:error:", NSURL, id*)(url, &__arg1); | |
363 | |
364 if (__arg1) | |
365 error = new NSError(__arg1); | |
366 | |
367 return result; | |
368 } | |
369 | |
370 } | |
371 |