1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package net.wotonomy.access; |
19 |
|
|
20 |
|
import java.io.File; |
21 |
|
import java.io.FileInputStream; |
22 |
|
import java.io.IOException; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import net.wotonomy.control.EOAndQualifier; |
26 |
|
import net.wotonomy.control.EOClassDescription; |
27 |
|
import net.wotonomy.control.EOFetchSpecification; |
28 |
|
import net.wotonomy.control.EOGenericRecord; |
29 |
|
import net.wotonomy.control.EOGlobalID; |
30 |
|
import net.wotonomy.control.EOIntegralKeyGlobalID; |
31 |
|
import net.wotonomy.control.EOKeyGlobalID; |
32 |
|
import net.wotonomy.control.EOKeyValueArchiver; |
33 |
|
import net.wotonomy.control.EOKeyValueQualifier; |
34 |
|
import net.wotonomy.control.EOKeyValueUnarchiver; |
35 |
|
import net.wotonomy.control.EOQualifier; |
36 |
|
import net.wotonomy.control.EOVectorKeyGlobalID; |
37 |
|
import net.wotonomy.foundation.NSArray; |
38 |
|
import net.wotonomy.foundation.NSDictionary; |
39 |
|
import net.wotonomy.foundation.NSKeyValueCoding; |
40 |
|
import net.wotonomy.foundation.NSMutableArray; |
41 |
|
import net.wotonomy.foundation.NSMutableDictionary; |
42 |
|
import net.wotonomy.foundation.NSPropertyListSerialization; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public class EOEntity implements EOPropertyListEncoding { |
54 |
|
|
55 |
0 |
protected NSMutableDictionary _attributes = new NSMutableDictionary(); |
56 |
0 |
protected NSMutableDictionary _relations = new NSMutableDictionary(); |
57 |
0 |
private NSMutableArray _classPropertyNames = new NSMutableArray(); |
58 |
0 |
private NSMutableArray _classProperties = new NSMutableArray(); |
59 |
0 |
private NSMutableArray _classPropertyAttributes = new NSMutableArray(); |
60 |
0 |
private NSMutableArray _classPropertyManyRelationships = new NSMutableArray(); |
61 |
0 |
private NSMutableArray _classPropertyOneRelationships = new NSMutableArray(); |
62 |
0 |
protected NSArray _pkAttributes = NSArray.EmptyArray; |
63 |
0 |
protected NSArray _pkAttributeNames = NSArray.EmptyArray; |
64 |
0 |
protected NSMutableDictionary _fetchSpecs = new NSMutableDictionary(); |
65 |
0 |
protected NSMutableArray _lockingAttributes = new NSMutableArray(); |
66 |
|
|
67 |
|
protected String _className; |
68 |
|
protected String _name; |
69 |
|
protected String _externalName; |
70 |
|
protected boolean _isAbstract; |
71 |
|
protected boolean _isReadOnly; |
72 |
|
protected EOModel _model; |
73 |
|
protected NSDictionary _userInfo; |
74 |
|
protected NSDictionary _internalInfo; |
75 |
|
private boolean _loadedFetchSpecs; |
76 |
|
|
77 |
|
public EOEntity() { |
78 |
0 |
super(); |
79 |
0 |
} |
80 |
|
|
81 |
|
public EOEntity(NSDictionary dict, Object obj) { |
82 |
0 |
super(); |
83 |
0 |
_model = (EOModel)obj; |
84 |
0 |
setName((String)dict.objectForKey("name")); |
85 |
0 |
setExternalName((String)dict.objectForKey("externalName")); |
86 |
0 |
setClassName((String)dict.objectForKey("className")); |
87 |
0 |
if (dict.objectForKey("internalInfo") != null) |
88 |
0 |
_internalInfo = (NSDictionary)dict.objectForKey("internalInfo"); |
89 |
0 |
if (dict.objectForKey("userInfo") != null) |
90 |
0 |
_userInfo = (NSDictionary)dict.objectForKey("userInfo"); |
91 |
|
|
92 |
|
|
93 |
0 |
NSArray atr = (NSArray)dict.objectForKey("attributes"); |
94 |
0 |
for (int i = 0; i < atr.count(); i++) { |
95 |
0 |
NSDictionary d = (NSDictionary)atr.objectAtIndex(i); |
96 |
0 |
EOAttribute atrib = new EOAttribute(d, this); |
97 |
0 |
addAttribute(atrib); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
0 |
atr = (NSArray)dict.objectForKey("primaryKeyAttributes"); |
102 |
0 |
NSMutableArray pka = new NSMutableArray(); |
103 |
0 |
for (int i = 0; i < atr.count(); i++) { |
104 |
0 |
EOAttribute a = attributeNamed((String)atr.objectAtIndex(i)); |
105 |
0 |
pka.addObject(a); |
106 |
|
} |
107 |
0 |
_pkAttributes = new NSArray(pka); |
108 |
0 |
_pkAttributeNames = atr; |
109 |
|
|
110 |
|
|
111 |
0 |
_lockingAttributes.removeAllObjects(); |
112 |
0 |
atr = (NSArray)dict.objectForKey("attributesUsedForLocking"); |
113 |
0 |
for (int i = 0; i < atr.count(); i++) { |
114 |
0 |
String x = (String)atr.objectAtIndex(i); |
115 |
0 |
EOAttribute a = attributeNamed(x); |
116 |
0 |
_lockingAttributes.addObject(a); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
0 |
atr = (NSArray)dict.objectForKey("classProperties"); |
121 |
0 |
if (atr != null) { |
122 |
0 |
for (int i = 0; i < atr.count(); i++) |
123 |
0 |
if (!_classPropertyNames.containsObject((atr.objectAtIndex(i)))) |
124 |
0 |
_classPropertyNames.addObject(atr.objectAtIndex(i)); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
0 |
atr = (NSArray)dict.objectForKey("relationships"); |
129 |
0 |
if (atr != null) { |
130 |
0 |
for (int i = 0; i < atr.count(); i++) { |
131 |
0 |
NSDictionary d = (NSDictionary)atr.objectAtIndex(i); |
132 |
0 |
EORelationship rel = new EORelationship(d, this); |
133 |
0 |
addRelationship(rel); |
134 |
|
} |
135 |
|
} |
136 |
0 |
} |
137 |
|
|
138 |
|
public void addAttribute(EOAttribute atr) { |
139 |
0 |
if (atr.name() == null) |
140 |
0 |
throw new IllegalArgumentException("Cannot add an unnamed attribute to an entity."); |
141 |
0 |
if (_attributes.objectForKey(atr.name()) != null) |
142 |
0 |
throw new IllegalArgumentException("Entity " + name() + " already has an attribute named " + atr.name()); |
143 |
0 |
_attributes.setObjectForKey(atr, atr.name()); |
144 |
0 |
atr.setEntity(this); |
145 |
0 |
_lockingAttributes.addObject(atr); |
146 |
0 |
_classProperties.addObject(atr); |
147 |
0 |
_classPropertyNames.addObject(atr.name()); |
148 |
0 |
_classPropertyAttributes.addObject(atr); |
149 |
0 |
} |
150 |
|
|
151 |
|
public void removeAttribute(EOAttribute atr) { |
152 |
0 |
_attributes.removeObjectForKey(atr.name()); |
153 |
0 |
atr.setEntity(null); |
154 |
0 |
_classProperties.removeObject(atr); |
155 |
0 |
_classPropertyNames.removeObject(atr.name()); |
156 |
0 |
_classPropertyAttributes.removeObject(atr); |
157 |
0 |
} |
158 |
|
|
159 |
|
public void addFetchSpecification(EOFetchSpecification fspec, String name) { |
160 |
0 |
loadFetchSpecifications(); |
161 |
0 |
if (_fetchSpecs.objectForKey(name) != null) |
162 |
0 |
throw new IllegalArgumentException("Entity " + name() + " already has a fetch specification named " + name); |
163 |
0 |
_fetchSpecs.setObjectForKey(fspec, name); |
164 |
0 |
} |
165 |
|
|
166 |
|
public void removeFetchSpecificationNamed(String name) { |
167 |
0 |
_fetchSpecs.removeObjectForKey(name); |
168 |
0 |
} |
169 |
|
|
170 |
|
public EOFetchSpecification fetchSpecificationNamed(String name) { |
171 |
0 |
loadFetchSpecifications(); |
172 |
0 |
return (EOFetchSpecification)_fetchSpecs.objectForKey(name); |
173 |
|
} |
174 |
|
|
175 |
|
public NSArray fetchSpecificationNames() { |
176 |
0 |
loadFetchSpecifications(); |
177 |
0 |
return _fetchSpecs.allKeys(); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
private void loadFetchSpecifications() { |
184 |
0 |
if (_loadedFetchSpecs) |
185 |
0 |
return; |
186 |
0 |
_loadedFetchSpecs = true; |
187 |
0 |
if (model().path() == null) |
188 |
0 |
return; |
189 |
0 |
File f = new File(model().path()); |
190 |
|
|
191 |
0 |
f = new File(f, name() + ".fspec"); |
192 |
0 |
if (!f.exists()) |
193 |
0 |
return; |
194 |
0 |
NSDictionary fdict = null; |
195 |
0 |
String x = null; |
196 |
|
try { |
197 |
0 |
FileInputStream fin = new FileInputStream(f); |
198 |
0 |
byte[] b = new byte[fin.available()]; |
199 |
0 |
fin.read(b); |
200 |
0 |
fin.close(); |
201 |
0 |
x = new String(b); |
202 |
0 |
} catch (IOException ex) { |
203 |
0 |
throw new IllegalArgumentException("Cannot read file " + f); |
204 |
0 |
} |
205 |
0 |
fdict = NSPropertyListSerialization.dictionaryForString(x); |
206 |
0 |
if (fdict == null) |
207 |
0 |
throw new IllegalArgumentException("Cannot read dictionary from " + f); |
208 |
0 |
NSArray keys = fdict.allKeys(); |
209 |
|
|
210 |
|
|
211 |
0 |
EOKeyValueUnarchiver unarch = new EOKeyValueUnarchiver(fdict); |
212 |
0 |
for (int i = 0; i < keys.count(); i++) { |
213 |
0 |
String k = (String)keys.objectAtIndex(i); |
214 |
0 |
EOFetchSpecification fs = (EOFetchSpecification)unarch.decodeObjectForKey(k); |
215 |
0 |
if (fs != null) |
216 |
0 |
_fetchSpecs.setObjectForKey(fs, k); |
217 |
|
} |
218 |
0 |
} |
219 |
|
|
220 |
|
public NSArray attributes() { |
221 |
0 |
return _attributes.allValues(); |
222 |
|
} |
223 |
|
|
224 |
|
public EOAttribute attributeNamed(String name) { |
225 |
0 |
return (EOAttribute)_attributes.objectForKey(name); |
226 |
|
} |
227 |
|
|
228 |
|
public NSArray flattenedAttributes() { |
229 |
0 |
return null; |
230 |
|
} |
231 |
|
|
232 |
|
public void setClassName(String name) { |
233 |
0 |
_className = name; |
234 |
0 |
} |
235 |
|
public String className() { |
236 |
0 |
return _className; |
237 |
|
} |
238 |
|
|
239 |
|
public void setName(String name) { |
240 |
0 |
_name = name; |
241 |
0 |
} |
242 |
|
public String name() { |
243 |
0 |
return _name; |
244 |
|
} |
245 |
|
|
246 |
|
public void setExternalName(String name) { |
247 |
0 |
_externalName = name; |
248 |
0 |
} |
249 |
|
public String externalName() { |
250 |
0 |
return _externalName; |
251 |
|
} |
252 |
|
|
253 |
|
public void addRelationship(EORelationship rel) { |
254 |
0 |
if (rel.name() == null) |
255 |
0 |
throw new IllegalArgumentException("Cannot add an unnamed relationship to an entity."); |
256 |
0 |
if (_relations.objectForKey(rel.name()) != null) |
257 |
0 |
throw new IllegalArgumentException("Entity " + name() + " already has a relationship named " + rel.name()); |
258 |
0 |
if (_attributes.objectForKey(rel.name()) != null) |
259 |
0 |
throw new IllegalArgumentException("Entity " + name() + " has an attribute named " + rel.name()); |
260 |
0 |
_relations.setObjectForKey(rel, rel.name()); |
261 |
0 |
_classProperties.addObject(rel); |
262 |
0 |
_classPropertyNames.addObject(rel.name()); |
263 |
0 |
if (rel.isToMany()) |
264 |
0 |
_classPropertyManyRelationships.addObject(rel); |
265 |
|
else |
266 |
0 |
_classPropertyOneRelationships.addObject(rel); |
267 |
0 |
} |
268 |
|
|
269 |
|
public void removeRelationship(EORelationship rel) { |
270 |
0 |
_relations.removeObjectForKey(rel.name()); |
271 |
0 |
_classProperties.removeObject(rel); |
272 |
0 |
_classPropertyNames.removeObject(rel.name()); |
273 |
0 |
_classPropertyManyRelationships.removeObject(rel); |
274 |
0 |
_classPropertyOneRelationships.removeObject(rel); |
275 |
0 |
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
public NSArray relationships() { |
281 |
0 |
return _relations.allValues(); |
282 |
|
} |
283 |
|
|
284 |
|
public EORelationship relationshipNamed(String name) { |
285 |
0 |
return (EORelationship)_relations.objectForKey(name); |
286 |
|
} |
287 |
|
public EOModel model() { |
288 |
0 |
return _model; |
289 |
|
} |
290 |
|
|
291 |
|
public void setPrimaryKeyAtributes(NSArray pk) { |
292 |
0 |
_pkAttributes = pk; |
293 |
0 |
} |
294 |
|
public NSArray primaryKeyAttributes() { |
295 |
0 |
return _pkAttributes; |
296 |
|
} |
297 |
|
|
298 |
|
public NSArray primaryKeyAttributeNames() { |
299 |
0 |
if (_pkAttributeNames.count() != _pkAttributes.count()) { |
300 |
0 |
NSMutableArray arr = new NSMutableArray(); |
301 |
0 |
for (int i = 0; i < _pkAttributes.count(); i++) { |
302 |
0 |
EOAttribute a = (EOAttribute)_pkAttributes.objectAtIndex(i); |
303 |
0 |
arr.addObject(a.name()); |
304 |
|
} |
305 |
0 |
_pkAttributeNames = new NSArray(arr); |
306 |
|
} |
307 |
0 |
return _pkAttributeNames; |
308 |
|
} |
309 |
|
|
310 |
|
public boolean hasSimplePrimaryKey() { |
311 |
0 |
return _pkAttributes.count() == 1; |
312 |
|
} |
313 |
|
|
314 |
|
public boolean isValidPrimaryKeyAttribute(EOAttribute attr) { |
315 |
0 |
return !attr.allowsNull(); |
316 |
|
} |
317 |
|
|
318 |
|
public void setAttributesUsedForLocking(NSArray value) { |
319 |
0 |
_lockingAttributes.removeAllObjects(); |
320 |
0 |
_lockingAttributes.addObjectsFromArray(value); |
321 |
0 |
} |
322 |
|
public NSArray attributesUsedForLocking() { |
323 |
0 |
return new NSArray(_lockingAttributes); |
324 |
|
} |
325 |
|
|
326 |
|
public void setClassProperties(NSArray value) { |
327 |
0 |
_classProperties.removeAllObjects(); |
328 |
0 |
_classProperties.addObjectsFromArray(value); |
329 |
0 |
_classPropertyNames.removeAllObjects(); |
330 |
0 |
_classPropertyAttributes.removeAllObjects(); |
331 |
0 |
_classPropertyOneRelationships.removeAllObjects(); |
332 |
0 |
_classPropertyManyRelationships.removeAllObjects(); |
333 |
0 |
for (int i = 0; i < value.count(); i++) { |
334 |
0 |
EOProperty o = (EOProperty)value.objectAtIndex(i); |
335 |
0 |
_classPropertyNames.addObject(o.name()); |
336 |
0 |
if (o instanceof EOAttribute) { |
337 |
0 |
_classPropertyAttributes.addObject(o); |
338 |
0 |
} else if (o instanceof EORelationship) { |
339 |
0 |
if (((EORelationship)o).isToMany()) |
340 |
0 |
_classPropertyManyRelationships.addObject(o); |
341 |
|
else |
342 |
0 |
_classPropertyOneRelationships.addObject(o); |
343 |
|
} |
344 |
|
} |
345 |
0 |
} |
346 |
|
public NSArray classProperties() { |
347 |
0 |
if (_classProperties == null) { |
348 |
0 |
if (_classPropertyNames == null) |
349 |
0 |
return NSArray.EmptyArray; |
350 |
|
else { |
351 |
0 |
NSMutableArray props = new NSMutableArray(); |
352 |
0 |
NSMutableArray atribs = new NSMutableArray(); |
353 |
0 |
NSMutableArray ones = new NSMutableArray(); |
354 |
0 |
NSMutableArray manies = new NSMutableArray(); |
355 |
0 |
for (int i = 0; i < _classPropertyNames.count(); i++) { |
356 |
0 |
String name = (String)_classPropertyNames.objectAtIndex(i); |
357 |
0 |
EOAttribute a = attributeNamed(name); |
358 |
0 |
EORelationship r = relationshipNamed(name); |
359 |
0 |
if (a != null) { |
360 |
0 |
props.addObject(a); |
361 |
0 |
atribs.addObject(a); |
362 |
0 |
} else if (r != null) { |
363 |
0 |
props.addObject(r); |
364 |
0 |
if (r.isToMany()) |
365 |
0 |
manies.addObject(r); |
366 |
|
else |
367 |
0 |
ones.addObject(r); |
368 |
0 |
} else |
369 |
0 |
throw new IllegalArgumentException("Cannot find attribute or relationship named " + name); |
370 |
|
} |
371 |
0 |
_classProperties = props; |
372 |
0 |
_classPropertyAttributes = atribs; |
373 |
0 |
_classPropertyOneRelationships = ones; |
374 |
0 |
_classPropertyManyRelationships = manies; |
375 |
|
} |
376 |
|
} |
377 |
0 |
return _classProperties; |
378 |
|
} |
379 |
|
|
380 |
|
public NSArray classPropertyNames() { |
381 |
0 |
return _classPropertyNames; |
382 |
|
} |
383 |
|
|
384 |
|
public NSArray classPropertyAttributeNames() { |
385 |
0 |
if (_classPropertyAttributes == null) |
386 |
0 |
return NSArray.EmptyArray; |
387 |
0 |
NSMutableArray arr = new NSMutableArray(_classPropertyAttributes.count()); |
388 |
0 |
for (int i = 0 ; i < _classPropertyAttributes.count(); i++) { |
389 |
0 |
EOAttribute a = (EOAttribute)_classPropertyAttributes.objectAtIndex(i); |
390 |
0 |
arr.addObject(a.name()); |
391 |
|
} |
392 |
0 |
return arr; |
393 |
|
} |
394 |
|
|
395 |
|
public NSArray classPropertyToManyRelationshipNames() { |
396 |
0 |
if (_classPropertyManyRelationships == null) |
397 |
0 |
return NSArray.EmptyArray; |
398 |
0 |
NSMutableArray arr = new NSMutableArray(_classPropertyManyRelationships.count()); |
399 |
0 |
for (int i = 0 ; i < _classPropertyManyRelationships.count(); i++) { |
400 |
0 |
EOAttribute a = (EOAttribute)_classPropertyManyRelationships.objectAtIndex(i); |
401 |
0 |
arr.addObject(a.name()); |
402 |
|
} |
403 |
0 |
return arr; |
404 |
|
} |
405 |
|
|
406 |
|
public NSArray classPropertyToOneRelationshipNames() { |
407 |
0 |
if (_classPropertyOneRelationships == null) |
408 |
0 |
return NSArray.EmptyArray; |
409 |
0 |
NSMutableArray arr = new NSMutableArray(_classPropertyOneRelationships.count()); |
410 |
0 |
for (int i = 0 ; i < _classPropertyOneRelationships.count(); i++) { |
411 |
0 |
EOAttribute a = (EOAttribute)_classPropertyOneRelationships.objectAtIndex(i); |
412 |
0 |
arr.addObject(a.name()); |
413 |
|
} |
414 |
0 |
return arr; |
415 |
|
} |
416 |
|
|
417 |
|
public void setIsAbstractEntity(boolean flag) { |
418 |
0 |
_isAbstract = flag; |
419 |
0 |
} |
420 |
|
public boolean isAbstractEntity() { |
421 |
0 |
return _isAbstract; |
422 |
|
} |
423 |
|
|
424 |
|
public void setReadOnly(boolean flag) { |
425 |
0 |
_isReadOnly = flag; |
426 |
0 |
} |
427 |
|
public boolean isReadOnly() { |
428 |
0 |
return _isReadOnly; |
429 |
|
} |
430 |
|
|
431 |
|
public void setStoredProcedure(EOStoredProcedure proc, String operation) { |
432 |
0 |
} |
433 |
|
public EOStoredProcedure storedProcedureForOperation(String operation) { |
434 |
0 |
return null; |
435 |
|
} |
436 |
|
|
437 |
|
public NSArray subEntities() { |
438 |
0 |
return null; |
439 |
|
} |
440 |
|
|
441 |
|
public NSArray attributesToFetch() { |
442 |
0 |
return attributes(); |
443 |
|
} |
444 |
|
|
445 |
|
public NSArray externalModelsReferenced() { |
446 |
0 |
return null; |
447 |
|
} |
448 |
|
|
449 |
|
public EOClassDescription classDescriptionForInstances() { |
450 |
0 |
EOClassDescription cd = EOClassDescription.classDescriptionForEntityName(name()); |
451 |
0 |
if (cd == null) { |
452 |
0 |
cd = new EOEntityClassDescription(this); |
453 |
0 |
Class cl = null; |
454 |
|
try { |
455 |
0 |
cl = Class.forName(className()); |
456 |
0 |
} catch (ClassNotFoundException ex) { |
457 |
0 |
cl = EOGenericRecord.class; |
458 |
0 |
} |
459 |
0 |
EOClassDescription.registerClassDescription(cd, cl); |
460 |
|
} |
461 |
0 |
return cd; |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
public EOGlobalID globalIDForRow(Map row) { |
471 |
0 |
NSArray pknames = primaryKeyAttributeNames(); |
472 |
0 |
EOKeyGlobalID gid = null; |
473 |
0 |
if (pknames.count() == 1 && row.get(pknames.objectAtIndex(0)) instanceof Number) { |
474 |
0 |
Number n = (Number)row.get(pknames.objectAtIndex(0)); |
475 |
0 |
gid = new EOIntegralKeyGlobalID(name(), n); |
476 |
0 |
} else { |
477 |
0 |
Object[] vals = new Object[pknames.count()]; |
478 |
0 |
for (int i = 0; i < pknames.count(); i++) { |
479 |
0 |
Object v = row.get(pknames.objectAtIndex(i)); |
480 |
0 |
vals[i] = v; |
481 |
|
} |
482 |
0 |
gid = new EOVectorKeyGlobalID(name(), vals); |
483 |
|
} |
484 |
0 |
return gid; |
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
public NSDictionary primaryKeyForGlobalID(EOGlobalID gid) { |
494 |
0 |
if (!(gid instanceof EOKeyGlobalID)) |
495 |
0 |
return null; |
496 |
0 |
Object[] vals = ((EOKeyGlobalID)gid).keyValues(); |
497 |
0 |
NSArray pknames = primaryKeyAttributeNames(); |
498 |
0 |
return new NSDictionary(vals, pknames.toArray()); |
499 |
|
} |
500 |
|
|
501 |
|
public EOQualifier qualifierForPrimaryKey(Map pkey) { |
502 |
0 |
NSArray pknames = primaryKeyAttributeNames(); |
503 |
0 |
EOQualifier q = null; |
504 |
0 |
NSMutableArray subq = new NSMutableArray(pknames.count()); |
505 |
0 |
for (int i = 0; i < pknames.count(); i++) { |
506 |
0 |
String key = (String)pknames.objectAtIndex(i); |
507 |
0 |
Object v = pkey.get(key); |
508 |
0 |
if (v == null || v == NSKeyValueCoding.NullValue) |
509 |
0 |
throw new IllegalArgumentException("Primary key with null values."); |
510 |
0 |
subq.addObject(new EOKeyValueQualifier(key, EOQualifier.QualifierOperatorEqual, v)); |
511 |
|
} |
512 |
0 |
if (subq.count() == 1) |
513 |
0 |
q = (EOQualifier)subq.objectAtIndex(0); |
514 |
|
else |
515 |
0 |
q = new EOAndQualifier(subq); |
516 |
0 |
return q; |
517 |
|
} |
518 |
|
|
519 |
|
public void setUserInfo(NSDictionary value) { |
520 |
0 |
_userInfo = value; |
521 |
0 |
} |
522 |
|
public NSDictionary userInfo() { |
523 |
0 |
return _userInfo; |
524 |
|
} |
525 |
|
|
526 |
|
public void awakeWithPropertyList(NSDictionary plist) { |
527 |
0 |
} |
528 |
|
|
529 |
|
public void encodeIntoPropertyList(NSMutableDictionary dict) { |
530 |
0 |
dict.setObjectForKey(name(), "name"); |
531 |
0 |
dict.setObjectForKey(externalName(), "externalName"); |
532 |
0 |
dict.setObjectForKey(className(), "className"); |
533 |
|
|
534 |
|
|
535 |
0 |
NSMutableArray arr = new NSMutableArray(_attributes.allValues()); |
536 |
0 |
for (int i = 0; i < _attributes.count(); i++) { |
537 |
0 |
EOAttribute a = (EOAttribute)arr.objectAtIndex(i); |
538 |
0 |
NSMutableDictionary d = new NSMutableDictionary(); |
539 |
0 |
a.encodeIntoPropertyList(d); |
540 |
0 |
arr.replaceObjectAtIndex(i, d); |
541 |
|
} |
542 |
0 |
dict.setObjectForKey(arr, "attributes"); |
543 |
|
|
544 |
0 |
if (_relations.count() > 0) { |
545 |
0 |
arr = new NSMutableArray(_relations.allValues()); |
546 |
0 |
for (int i = 0; i < _relations.count(); i++) { |
547 |
0 |
EORelationship r = (EORelationship)arr.objectAtIndex(i); |
548 |
0 |
NSMutableDictionary d = new NSMutableDictionary(); |
549 |
0 |
r.encodeIntoPropertyList(d); |
550 |
0 |
arr.replaceObjectAtIndex(i, d); |
551 |
|
} |
552 |
0 |
dict.setObjectForKey(arr, "relationships"); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
0 |
NSMutableDictionary d = new NSMutableDictionary(); |
557 |
0 |
loadFetchSpecifications(); |
558 |
0 |
java.util.Enumeration enumeration = _fetchSpecs.keyEnumerator(); |
559 |
0 |
while (enumeration.hasMoreElements()) { |
560 |
0 |
String k = (String)enumeration.nextElement(); |
561 |
0 |
EOFetchSpecification f = (EOFetchSpecification)_fetchSpecs.objectForKey(k); |
562 |
0 |
EOKeyValueArchiver arch = new EOKeyValueArchiver(); |
563 |
0 |
f.encodeWithKeyValueArchiver(arch); |
564 |
0 |
d.setObjectForKey(arch.dictionary(), k); |
565 |
0 |
} |
566 |
0 |
dict.setObjectForKey(d, "fetchSpecificationDictionary"); |
567 |
|
|
568 |
|
|
569 |
0 |
dict.setObjectForKey(_classPropertyNames, "classProperties"); |
570 |
0 |
dict.setObjectForKey(_pkAttributeNames, "primaryKeyAttributes"); |
571 |
0 |
arr = new NSMutableArray(_lockingAttributes); |
572 |
0 |
for (int i = 0; i < arr.count(); i++) |
573 |
0 |
arr.replaceObjectAtIndex(i, ((EOAttribute)arr.objectAtIndex(i)).name()); |
574 |
0 |
dict.setObjectForKey(arr, "attributesUsedForLocking"); |
575 |
0 |
if (_userInfo != null && _userInfo.count() > 0 ) |
576 |
0 |
dict.setObjectForKey(_userInfo, "userInfo"); |
577 |
0 |
if (_internalInfo != null && _internalInfo.count() > 0 ) |
578 |
0 |
dict.setObjectForKey(_internalInfo, "internalInfo"); |
579 |
0 |
} |
580 |
|
|
581 |
|
public EOAttribute _attributeForPath(String path) { |
582 |
0 |
NSArray comps = NSArray.componentsSeparatedByString(path, "."); |
583 |
0 |
if (comps.count() < 2) |
584 |
0 |
return null; |
585 |
0 |
EORelationship r = null; |
586 |
0 |
EOEntity e = this; |
587 |
0 |
for (int i = 0; i < comps.count()-1; i++) { |
588 |
0 |
String name = (String)comps.objectAtIndex(i); |
589 |
0 |
r = e.relationshipNamed(name); |
590 |
0 |
if (r == null) |
591 |
0 |
return null; |
592 |
0 |
e = r.destinationEntity(); |
593 |
|
} |
594 |
0 |
return e.attributeNamed((String)comps.lastObject()); |
595 |
|
} |
596 |
|
|
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|