| 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 |
|
|
| 32 |
|
|
| 33 |
|
|
| 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 |
0 |
super(); |
| 47 |
0 |
_context = context; |
| 48 |
0 |
_channel = _context.adaptorContext().createAdaptorChannel(); |
| 49 |
0 |
} |
| 50 |
|
|
| 51 |
|
public EOAdaptorChannel adaptorChannel() { |
| 52 |
0 |
return _channel; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public EODatabaseContext databaseContext() { |
| 56 |
0 |
return _context; |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
public void cancelFetch() { |
| 60 |
0 |
_channel.cancelFetch(); |
| 61 |
0 |
} |
| 62 |
|
|
| 63 |
|
public Object fetchObject() { |
| 64 |
0 |
NSDictionary r = _channel.fetchRow(); |
| 65 |
0 |
EOGlobalID gid = _currEntity.globalIDForRow(r); |
| 66 |
0 |
Object eo = _currEC.objectForGlobalID(gid); |
| 67 |
0 |
if (eo == null) { |
| 68 |
0 |
eo = EOClassDescription.classDescriptionForEntityName(_currEntity.name()).createInstanceWithEditingContext(_currEC, gid); |
| 69 |
0 |
if (eo instanceof EOKeyValueCodingAdditions) |
| 70 |
0 |
((EOKeyValueCodingAdditions)eo).takeValuesFromDictionary(r); |
| 71 |
|
else |
| 72 |
0 |
EOKeyValueCodingAdditions.DefaultImplementation.takeValuesFromDictionary(eo, r); |
| 73 |
0 |
} else { |
| 74 |
0 |
if (isRefreshingObjects()) { |
| 75 |
|
|
| 76 |
|
} |
| 77 |
|
} |
| 78 |
0 |
return eo; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
public boolean isFetchInProgress() { |
| 82 |
0 |
return _channel.isFetchInProgress(); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
public void setIsLocking(boolean flag) { |
| 86 |
0 |
_locking = flag; |
| 87 |
0 |
} |
| 88 |
|
|
| 89 |
|
public boolean isLocking() { |
| 90 |
0 |
return _locking; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
public void setIsRefreshingObjects(boolean flag) { |
| 94 |
0 |
_refreshing = flag; |
| 95 |
0 |
} |
| 96 |
|
|
| 97 |
|
public boolean isRefreshingObjects() { |
| 98 |
0 |
return _refreshing; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public void selectObjectsWithFetchSpecification(EOFetchSpecification fspec, EOEditingContext ec) { |
| 102 |
0 |
setIsLocking(fspec.locksObjects()); |
| 103 |
0 |
setIsRefreshingObjects(fspec.refreshesRefetchedObjects()); |
| 104 |
0 |
setCurrentEditingContext(ec); |
| 105 |
0 |
setCurrentEntity(databaseContext().database().entityNamed(fspec.entityName())); |
| 106 |
0 |
NSMutableArray atts = new NSMutableArray(); |
| 107 |
0 |
atts.addObjectsFromArray(_currEntity.attributes()); |
| 108 |
0 |
adaptorChannel().selectAttributes(atts, fspec, isLocking(), _currEntity); |
| 109 |
0 |
adaptorChannel().setAttributesToFetch(atts); |
| 110 |
0 |
_attributes = atts; |
| 111 |
0 |
} |
| 112 |
|
|
| 113 |
|
public void setCurrentEditingContext(EOEditingContext ec) { |
| 114 |
0 |
_currEC = ec; |
| 115 |
0 |
} |
| 116 |
|
|
| 117 |
|
public void setCurrentEntity(EOEntity entity) { |
| 118 |
0 |
_currEntity = entity; |
| 119 |
0 |
} |
| 120 |
|
|
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|