| 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.EOFetchSpecification; |
| 21 |
|
import net.wotonomy.control.EOObjectStoreCoordinator; |
| 22 |
|
import net.wotonomy.foundation.NSArray; |
| 23 |
|
import net.wotonomy.foundation.NSDictionary; |
| 24 |
|
import net.wotonomy.foundation.NSMutableDictionary; |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
public class EOModelGroup { |
| 36 |
|
|
| 37 |
|
private static EOModelGroup _defaultGroup; |
| 38 |
|
private static EOModelGroup _globalGroup; |
| 39 |
|
protected NSMutableDictionary _models; |
| 40 |
|
|
| 41 |
|
public EOModelGroup() { |
| 42 |
0 |
super(); |
| 43 |
0 |
} |
| 44 |
|
|
| 45 |
|
public void addModel(EOModel model) { |
| 46 |
0 |
if (model.name() == null) |
| 47 |
0 |
throw new IllegalArgumentException("Cannot add an unnamed model to a group."); |
| 48 |
0 |
if (_models.objectForKey(model.name()) != null) |
| 49 |
0 |
throw new IllegalArgumentException("Cannot add model " + model.name() + |
| 50 |
0 |
" to group because it already contains a model with the same name."); |
| 51 |
0 |
NSArray ents = model.entityNames(); |
| 52 |
0 |
for (int i = 0; i < ents.count(); i++) { |
| 53 |
0 |
String ename = (String)ents.objectAtIndex(i); |
| 54 |
0 |
if (entityNamed(ename) != null) |
| 55 |
0 |
throw new IllegalArgumentException("Cannot add model " + model.name() + |
| 56 |
0 |
" to group because it contains entity named " + ename); |
| 57 |
|
} |
| 58 |
0 |
_models.setObjectForKey(model, model.name()); |
| 59 |
0 |
} |
| 60 |
|
|
| 61 |
|
public void removeModel(EOModel model) { |
| 62 |
0 |
_models.removeObjectForKey(model.name()); |
| 63 |
0 |
} |
| 64 |
|
|
| 65 |
|
public void addModelWithPath(String path) { |
| 66 |
0 |
EOModel model = new EOModel(path); |
| 67 |
0 |
addModel(model); |
| 68 |
0 |
} |
| 69 |
|
|
| 70 |
|
public void addModelsFromDirectory(String dir) { |
| 71 |
0 |
} |
| 72 |
|
|
| 73 |
|
public static void setDefaultGroup(EOModelGroup group) { |
| 74 |
0 |
_defaultGroup = group; |
| 75 |
0 |
} |
| 76 |
|
public static EOModelGroup defaultGroup() { |
| 77 |
0 |
if (_defaultGroup == null) { |
| 78 |
0 |
_defaultGroup = globalModelGroup(); |
| 79 |
|
} |
| 80 |
0 |
return _defaultGroup; |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
public static EOModelGroup globalModelGroup() { |
| 84 |
0 |
if (_globalGroup == null) { |
| 85 |
0 |
_globalGroup = new EOModelGroup(); |
| 86 |
|
|
| 87 |
|
} |
| 88 |
0 |
return _globalGroup; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
public EOEntity entityForObject(net.wotonomy.control.EOEnterpriseObject eo) { |
| 92 |
0 |
return null; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
public EOEntity entityNamed(String name) { |
| 96 |
0 |
java.util.Enumeration enumeration = _models.objectEnumerator(); |
| 97 |
0 |
while (enumeration.hasMoreElements()) { |
| 98 |
0 |
EOModel m = (EOModel)enumeration.nextElement(); |
| 99 |
0 |
if (m.entityNamed(name) != null) |
| 100 |
0 |
return m.entityNamed(name); |
| 101 |
0 |
} |
| 102 |
0 |
return null; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
public EOModel modelNamed(String name) { |
| 106 |
0 |
return (EOModel)_models.objectForKey(name); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
public NSArray modelNames() { |
| 110 |
0 |
return _models.allKeys(); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
public NSArray models() { |
| 114 |
0 |
return _models.allValues(); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
public EOModel modelWithPath(String path) { |
| 118 |
0 |
java.util.Enumeration enumeration = _models.objectEnumerator(); |
| 119 |
0 |
while (enumeration.hasMoreElements()) { |
| 120 |
0 |
EOModel m = (EOModel)enumeration.nextElement(); |
| 121 |
0 |
if (m.path() != null && m.path().equals(path)) |
| 122 |
0 |
return m; |
| 123 |
0 |
} |
| 124 |
0 |
return null; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
public EOStoredProcedure storedProcedureNamed(String name) { |
| 128 |
0 |
java.util.Enumeration enumeration = _models.objectEnumerator(); |
| 129 |
0 |
while (enumeration.hasMoreElements()) { |
| 130 |
0 |
EOModel m = (EOModel)enumeration.nextElement(); |
| 131 |
0 |
if (m.storedProcedureNamed(name) != null) |
| 132 |
0 |
return m.storedProcedureNamed(name); |
| 133 |
0 |
} |
| 134 |
0 |
return null; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
public EOFetchSpecification fetchSpecificationNamed(String fetchSpecName, String entityName) { |
| 138 |
0 |
EOEntity e = entityNamed(entityName); |
| 139 |
0 |
if (e == null) |
| 140 |
0 |
return null; |
| 141 |
0 |
return e.fetchSpecificationNamed(fetchSpecName); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
public void loadAllModelObjects() { |
| 145 |
0 |
java.util.Enumeration enumeration = _models.objectEnumerator(); |
| 146 |
0 |
while (enumeration.hasMoreElements()) { |
| 147 |
0 |
EOModel m = (EOModel)enumeration.nextElement(); |
| 148 |
|
|
| 149 |
0 |
NSArray ents = m.entities(); |
| 150 |
0 |
for (int i=0; i<ents.count(); i++) { |
| 151 |
0 |
EOEntity e = (EOEntity)ents.objectAtIndex(i); |
| 152 |
|
|
| 153 |
0 |
e.fetchSpecificationNamed("whatever"); |
| 154 |
|
} |
| 155 |
0 |
} |
| 156 |
0 |
} |
| 157 |
|
|
| 158 |
|
public static void setModelGroupForObjectStoreCoordinator(EOObjectStoreCoordinator coord, EOModelGroup group) { |
| 159 |
0 |
NSMutableDictionary d = new NSMutableDictionary(coord.userInfo()); |
| 160 |
0 |
d.setObjectForKey(group, "ModelGroup"); |
| 161 |
0 |
coord.setUserInfo(d); |
| 162 |
0 |
} |
| 163 |
|
public static EOModelGroup modelGroupForObjectStoreCoordinator(EOObjectStoreCoordinator coord) { |
| 164 |
0 |
NSDictionary d = coord.userInfo(); |
| 165 |
0 |
if (d == null) |
| 166 |
0 |
return defaultGroup(); |
| 167 |
0 |
Object g = d.objectForKey("ModelGroup"); |
| 168 |
0 |
if (g != null && g instanceof EOModelGroup) |
| 169 |
0 |
return (EOModelGroup)g; |
| 170 |
0 |
return defaultGroup(); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|