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 net.wotonomy.control.EOClassDescription;
21 import net.wotonomy.control.EOEditingContext;
22 import net.wotonomy.control.EOFetchSpecification;
23 import net.wotonomy.control.EOGlobalID;
24 import net.wotonomy.control.EOKeyValueCodingAdditions;
25 import net.wotonomy.foundation.NSArray;
26 import net.wotonomy.foundation.NSDictionary;
27 import net.wotonomy.foundation.NSMutableArray;
28
29 /***
30 *
31 * @author ezamudio@nasoft.com
32 * @author $Author: cgruber $
33 * @version $Revision: 894 $
34 */
35 public class EODatabaseChannel {
36
37 protected EODatabaseContext _context;
38 protected EOAdaptorChannel _channel;
39 protected EOEntity _currEntity;
40 protected EOEditingContext _currEC;
41 protected NSArray _attributes;
42 protected boolean _locking;
43 protected boolean _refreshing;
44
45 public EODatabaseChannel(EODatabaseContext context) {
46 super();
47 _context = context;
48 _channel = _context.adaptorContext().createAdaptorChannel();
49 }
50
51 public EOAdaptorChannel adaptorChannel() {
52 return _channel;
53 }
54
55 public EODatabaseContext databaseContext() {
56 return _context;
57 }
58
59 public void cancelFetch() {
60 _channel.cancelFetch();
61 }
62
63 public Object fetchObject() {
64 NSDictionary r = _channel.fetchRow();
65 EOGlobalID gid = _currEntity.globalIDForRow(r);
66 Object eo = _currEC.objectForGlobalID(gid);
67 if (eo == null) {
68 eo = EOClassDescription.classDescriptionForEntityName(_currEntity.name()).createInstanceWithEditingContext(_currEC, gid);
69 if (eo instanceof EOKeyValueCodingAdditions)
70 ((EOKeyValueCodingAdditions)eo).takeValuesFromDictionary(r);
71 else
72 EOKeyValueCodingAdditions.DefaultImplementation.takeValuesFromDictionary(eo, r);
73 } else {
74 if (isRefreshingObjects()) {
75
76 }
77 }
78 return eo;
79 }
80
81 public boolean isFetchInProgress() {
82 return _channel.isFetchInProgress();
83 }
84
85 public void setIsLocking(boolean flag) {
86 _locking = flag;
87 }
88
89 public boolean isLocking() {
90 return _locking;
91 }
92
93 public void setIsRefreshingObjects(boolean flag) {
94 _refreshing = flag;
95 }
96
97 public boolean isRefreshingObjects() {
98 return _refreshing;
99 }
100
101 public void selectObjectsWithFetchSpecification(EOFetchSpecification fspec, EOEditingContext ec) {
102 setIsLocking(fspec.locksObjects());
103 setIsRefreshingObjects(fspec.refreshesRefetchedObjects());
104 setCurrentEditingContext(ec);
105 setCurrentEntity(databaseContext().database().entityNamed(fspec.entityName()));
106 NSMutableArray atts = new NSMutableArray();
107 atts.addObjectsFromArray(_currEntity.attributes());
108 adaptorChannel().selectAttributes(atts, fspec, isLocking(), _currEntity);
109 adaptorChannel().setAttributesToFetch(atts);
110 _attributes = atts;
111 }
112
113 public void setCurrentEditingContext(EOEditingContext ec) {
114 _currEC = ec;
115 }
116
117 public void setCurrentEntity(EOEntity entity) {
118 _currEntity = entity;
119 }
120
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138