| 1 |
|
package net.wotonomy.test; |
| 2 |
|
|
| 3 |
|
import java.util.Iterator; |
| 4 |
|
import java.util.List; |
| 5 |
|
import java.util.Map; |
| 6 |
|
|
| 7 |
|
import net.wotonomy.control.EOEditingContext; |
| 8 |
|
import net.wotonomy.control.EOFetchSpecification; |
| 9 |
|
import net.wotonomy.control.EOGlobalID; |
| 10 |
|
import net.wotonomy.control.EOObjectStore; |
| 11 |
|
import net.wotonomy.control.EOObserverCenter; |
| 12 |
|
import net.wotonomy.test.DataKeyID; |
| 13 |
|
import net.wotonomy.datastore.DataSoup; |
| 14 |
|
import net.wotonomy.datastore.DataView; |
| 15 |
|
import net.wotonomy.datastore.XMLFileSoup; |
| 16 |
|
import net.wotonomy.foundation.NSArray; |
| 17 |
|
import net.wotonomy.foundation.NSMutableArray; |
| 18 |
|
import net.wotonomy.foundation.internal.Duplicator; |
| 19 |
|
import net.wotonomy.foundation.internal.WotonomyException; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
public class TestObjectStore extends EOObjectStore |
| 26 |
|
{ |
| 27 |
|
DataSoup soup; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
0 |
public TestObjectStore( String aPath ) |
| 33 |
0 |
{ |
| 34 |
0 |
soup = new XMLFileSoup( aPath ); |
| 35 |
0 |
} |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
public NSArray arrayFaultWithSourceGlobalID ( |
| 42 |
|
EOGlobalID aGlobalID, |
| 43 |
|
String aRelationship, |
| 44 |
|
EOEditingContext aContext ) |
| 45 |
|
{ |
| 46 |
0 |
return objectsForSourceGlobalID( |
| 47 |
0 |
aGlobalID, aRelationship, aContext ); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
public Object faultForGlobalID ( |
| 55 |
|
EOGlobalID aGlobalID, |
| 56 |
|
EOEditingContext aContext ) |
| 57 |
|
{ |
| 58 |
0 |
System.out.println( "TestObjectStore: * reading object * : " + aGlobalID ); |
| 59 |
0 |
return soup.getObjectByKey( |
| 60 |
0 |
((DataKeyID)aGlobalID).getKey() ); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
public Object faultForRawRow ( |
| 70 |
|
Map aDictionary, |
| 71 |
|
String anEntityName, |
| 72 |
|
EOEditingContext aContext ) |
| 73 |
|
{ |
| 74 |
|
|
| 75 |
0 |
throw new WotonomyException( |
| 76 |
0 |
"Faults are not yet supported." ); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
public void initializeObject ( |
| 87 |
|
Object anObject, |
| 88 |
|
EOGlobalID aGlobalID, |
| 89 |
|
EOEditingContext aContext ) |
| 90 |
|
{ |
| 91 |
0 |
System.out.println( "TestObjectStore: * reading object * : " + aGlobalID ); |
| 92 |
0 |
Object original = soup.getObjectByKey( |
| 93 |
0 |
((DataKeyID)aGlobalID).getKey() ); |
| 94 |
0 |
EOObserverCenter.notifyObserversObjectWillChange( anObject ); |
| 95 |
0 |
Duplicator.deepCopy( original, anObject ); |
| 96 |
|
|
| 97 |
0 |
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
public void invalidateAllObjects () |
| 105 |
|
{ |
| 106 |
|
|
| 107 |
0 |
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
public void invalidateObjectsWithGlobalIDs ( |
| 115 |
|
List aList ) |
| 116 |
|
{ |
| 117 |
|
|
| 118 |
0 |
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
public boolean isObjectLockedWithGlobalID ( |
| 124 |
|
EOGlobalID aGlobalID, |
| 125 |
|
EOEditingContext aContext ) |
| 126 |
|
{ |
| 127 |
0 |
return false; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
public void lockObjectWithGlobalID ( |
| 134 |
|
EOGlobalID aGlobalID, |
| 135 |
|
EOEditingContext aContext ) |
| 136 |
|
{ |
| 137 |
|
|
| 138 |
0 |
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
public NSArray objectsForSourceGlobalID ( |
| 147 |
|
EOGlobalID aGlobalID, |
| 148 |
|
String aRelationship, |
| 149 |
|
EOEditingContext aContext ) |
| 150 |
|
{ |
| 151 |
|
|
| 152 |
0 |
throw new WotonomyException( |
| 153 |
0 |
"Relationships are not yet supported." ); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
public NSArray objectsWithFetchSpecification ( |
| 164 |
|
EOFetchSpecification aFetchSpec, |
| 165 |
|
EOEditingContext aContext ) |
| 166 |
|
{ |
| 167 |
|
|
| 168 |
|
|
| 169 |
0 |
DataView view = soup.queryObjects( null, null ); |
| 170 |
0 |
System.out.println( "TestObjectStore: ** querying all objects **" ); |
| 171 |
0 |
NSMutableArray result = new NSMutableArray(); |
| 172 |
|
Object o; |
| 173 |
|
Object existing; |
| 174 |
|
DataKeyID id; |
| 175 |
0 |
Iterator it = view.iterator(); |
| 176 |
0 |
while ( it.hasNext() ) |
| 177 |
|
{ |
| 178 |
0 |
o = it.next(); |
| 179 |
0 |
id = new DataKeyID( view.getKeyForObject( o ) ); |
| 180 |
0 |
existing = aContext.objectForGlobalID( id ); |
| 181 |
0 |
if ( existing != null ) |
| 182 |
|
{ |
| 183 |
0 |
o = existing; |
| 184 |
0 |
} |
| 185 |
|
else |
| 186 |
|
{ |
| 187 |
0 |
aContext.recordObject( o, id ); |
| 188 |
|
} |
| 189 |
0 |
result.addObject( o ); |
| 190 |
0 |
} |
| 191 |
0 |
return result; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
public void refaultObject ( |
| 200 |
|
Object anObject, |
| 201 |
|
EOGlobalID aGlobalID, |
| 202 |
|
EOEditingContext aContext ) |
| 203 |
|
{ |
| 204 |
|
|
| 205 |
|
|
| 206 |
0 |
initializeObject( anObject, aGlobalID, aContext ); |
| 207 |
0 |
} |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
public void saveChangesInEditingContext ( |
| 214 |
|
EOEditingContext aContext ) |
| 215 |
|
{ |
| 216 |
|
Object o; |
| 217 |
|
DataKeyID id; |
| 218 |
|
Iterator it; |
| 219 |
|
|
| 220 |
0 |
System.out.println( aContext.updatedObjects() ); |
| 221 |
|
|
| 222 |
|
|
| 223 |
0 |
it = aContext.updatedObjects().iterator(); |
| 224 |
0 |
while ( it.hasNext() ) |
| 225 |
|
{ |
| 226 |
0 |
o = it.next(); |
| 227 |
0 |
id = (DataKeyID) aContext.globalIDForObject( o ); |
| 228 |
0 |
System.out.println( "TestObjectStore: * updating object * : " + id ); |
| 229 |
0 |
soup.updateObject( id.getKey(), o ); |
| 230 |
0 |
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
0 |
it = aContext.deletedObjects().iterator(); |
| 234 |
0 |
while ( it.hasNext() ) |
| 235 |
|
{ |
| 236 |
0 |
o = it.next(); |
| 237 |
0 |
id = (DataKeyID) aContext.globalIDForObject( o ); |
| 238 |
0 |
System.out.println( "TestObjectStore: * deleting object * : " + id ); |
| 239 |
0 |
soup.removeObject( id.getKey() ); |
| 240 |
|
|
| 241 |
0 |
aContext.forgetObject( o ); |
| 242 |
0 |
} |
| 243 |
|
|
| 244 |
|
|
| 245 |
0 |
it = aContext.insertedObjects().iterator(); |
| 246 |
0 |
while ( it.hasNext() ) |
| 247 |
|
{ |
| 248 |
0 |
o = it.next(); |
| 249 |
0 |
id = new DataKeyID( soup.addObject( o ) ); |
| 250 |
0 |
System.out.println( "TestObjectStore: * adding object * : " + id ); |
| 251 |
|
|
| 252 |
0 |
aContext.forgetObject( o ); |
| 253 |
0 |
aContext.recordObject( o, id ); |
| 254 |
0 |
} |
| 255 |
|
|
| 256 |
0 |
} |
| 257 |
|
} |
| 258 |
|
|