blob: c55a3862c2a53a32eaf4813f8b37161081c3a19d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package net.wotonomy.test;
import net.wotonomy.control.EOClassDescription;
import net.wotonomy.control.EODataSource;
import net.wotonomy.control.EOEditingContext;
import net.wotonomy.control.EOFetchSpecification;
import net.wotonomy.foundation.NSArray;
/**
* A custom DataSource that works with the datastore package for persistence.
*/
public class TestDataSource extends EODataSource {
private EOEditingContext context;
private Object source;
private String key;
public TestDataSource() {
this(Test.editingContext);
}
public TestDataSource(EOEditingContext aContext) {
context = aContext;
}
public EOEditingContext editingContext() {
return context;
}
/**
* This implementation does nothing.
*/
public void insertObject(Object anObject) {
// creates are handled by createObject().
}
/**
* Deletes the specified object from this data source.
*/
public void deleteObject(Object anObject) {
editingContext().deleteObject(anObject);
}
/**
* Returns a List containing the objects in this data source. This
* implementation returns all TestObjects that have been persisted to the
* datastore in the data directory.
*/
public NSArray fetchObjects() {
if (source == null) {
NSArray result = editingContext().objectsWithFetchSpecification(new EOFetchSpecification());
if (result.size() > 0) {
result = new NSArray(result.objectAtIndex(0));
//result.add( result.objectAtIndex( 0 ) );
}
return result;
} else {
return new NSArray(((TestObject) source).getChildList());
}
}
/**
* Returns a data source that is capable of manipulating objects of the type
* returned by applying the specified key to objects vended by this data source.
*
* @see #qualifyWithRelationshipKey
*/
public EODataSource dataSourceQualifiedByKey(String aKey) {
return new TestDataSource(editingContext());
}
/**
* Restricts this data source to vend those objects that are associated with the
* specified key on the specified object.
*/
public void qualifyWithRelationshipKey(String aKey, Object anObject) {
key = aKey;
source = anObject;
}
/**
* Returns the description of the class of the objects that is vended by this
* data source, or null if this cannot be determined. This implementation
* returns TestObject.
*/
public EOClassDescription classDescriptionForObjects() {
return EOClassDescription.classDescriptionForClass(TestObject.class);
}
}
|