| 1 |
|
package net.wotonomy.test; |
| 2 |
|
|
| 3 |
|
import java.io.Serializable; |
| 4 |
|
import java.util.Date; |
| 5 |
|
import java.util.LinkedList; |
| 6 |
|
import java.util.List; |
| 7 |
|
import java.util.Random; |
| 8 |
|
import java.util.StringTokenizer; |
| 9 |
|
|
| 10 |
|
import net.wotonomy.control.EOEditingContext; |
| 11 |
|
import net.wotonomy.control.EOKeyValueCodingSupport; |
| 12 |
|
import net.wotonomy.datastore.DataSoup; |
| 13 |
|
import net.wotonomy.datastore.SerializedFileSoup; |
| 14 |
|
import net.wotonomy.datastore.XMLFileSoup; |
| 15 |
|
import net.wotonomy.foundation.internal.ValueConverter; |
| 16 |
|
|
| 17 |
0 |
public class TestObject implements Serializable |
| 18 |
|
{ |
| 19 |
|
static final long serialVersionUID = -5482454640042392838L; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
public EOEditingContext editingContext; |
| 23 |
0 |
public EOEditingContext getEditingContext() { return editingContext; }; |
| 24 |
|
|
| 25 |
0 |
public TestObject() |
| 26 |
0 |
{ |
| 27 |
0 |
date = new Date(); |
| 28 |
0 |
firstName = randomParse( |
| 29 |
0 |
"Bert|Ernie|Elmo|Zoe|Arthur|Emily|DJ|Grover|Oscar|Max|Big|Twinkle"); |
| 30 |
0 |
middleName = new StringBuffer( randomParse( |
| 31 |
0 |
"Rufus|Remy|Martin|Josephus|Ulysses|Homer|Bart|Tip|Onegin|Meredith|Jay") ); |
| 32 |
0 |
lastName = randomParse( |
| 33 |
0 |
"Alejandro|Alexander|Bird|Gosling|Joy|Van Hoff|Pedia|Marr|McNealy|Ping"); |
| 34 |
0 |
address = randomParse( "1|2|3|4" ) + randomParse( "0|1|00|10|5|50" ) + |
| 35 |
0 |
randomParse( "0|00|1|01|5|05|9|09||000" ) + " " + randomParse( |
| 36 |
0 |
"Merry|Berry|Perry|Jerry|Meadow|Falls|Elm|Raspberry|Strawberry") + " " |
| 37 |
0 |
+ randomParse( "Road|Lane|Court|Drive|Parkway|Terrace" ); |
| 38 |
0 |
city = randomParse( |
| 39 |
0 |
"Springfield|Sterling|Cascades|Vienna|Reston|Paris|London|Runnymeade"); |
| 40 |
0 |
state = randomParse( |
| 41 |
0 |
"TX|NJ|NY|VA|DC|MD|NC|SC|WV|AR|FL|CA|TN" ); |
| 42 |
0 |
zip = ValueConverter.getIntValue( |
| 43 |
0 |
randomParse( "1|2|3|4" ) + "0" + randomParse( "0|1|2|3|5" ) + |
| 44 |
0 |
randomParse( "6|7|8|9" ) + randomParse( "6|7|8|9" ) ); |
| 45 |
0 |
age = (short) ( new Random().nextDouble() * 40 + 18 ); |
| 46 |
0 |
childCount = -1; |
| 47 |
|
|
| 48 |
0 |
childList = null; |
| 49 |
0 |
} |
| 50 |
|
|
| 51 |
|
protected Date date; |
| 52 |
0 |
public Date getCreateDate() { return date; } |
| 53 |
0 |
public void setCreateDate( Date aDate ) { date = aDate; } |
| 54 |
|
|
| 55 |
|
protected String firstName; |
| 56 |
0 |
public String getFirstName() { return firstName; } |
| 57 |
0 |
public void setFirstName( String aName ) { firstName = aName; } |
| 58 |
|
|
| 59 |
|
protected String lastName; |
| 60 |
0 |
public String getLastName() { return lastName; } |
| 61 |
|
public void setLastName( String aName ) { |
| 62 |
0 |
if ( "Jones".equals( aName ) ) throw new RuntimeException( "Jones not allowed" ) ; |
| 63 |
0 |
lastName = aName; |
| 64 |
0 |
} |
| 65 |
|
|
| 66 |
|
protected StringBuffer middleName; |
| 67 |
0 |
public StringBuffer getMiddleName() { return middleName; } |
| 68 |
0 |
public void setMiddleName( StringBuffer aName ) { middleName = aName; } |
| 69 |
|
|
| 70 |
|
protected String address; |
| 71 |
0 |
public String getAddress() { return address; } |
| 72 |
0 |
public void setAddress( String anAddress ) { address = anAddress; } |
| 73 |
|
|
| 74 |
|
protected String city; |
| 75 |
0 |
public String getCity() { return city; } |
| 76 |
0 |
public void setCity( String aCity ) { city = aCity; } |
| 77 |
|
|
| 78 |
|
protected String state; |
| 79 |
0 |
public String getState() { return state; } |
| 80 |
0 |
public void setState( String aState ) { state = aState; } |
| 81 |
|
|
| 82 |
|
protected int zip; |
| 83 |
0 |
public int getZipCode() { return zip; } |
| 84 |
0 |
public void setZipCode( int aZipCode ) { zip = aZipCode; } |
| 85 |
|
|
| 86 |
|
protected short age; |
| 87 |
0 |
public short getAge() { return age; } |
| 88 |
0 |
public void setAge( short anAge ) { age = anAge; } |
| 89 |
|
|
| 90 |
|
protected boolean special; |
| 91 |
0 |
public Boolean isSpecial() { return new Boolean( special ); } |
| 92 |
0 |
public void setSpecial( Boolean isSpecial ) { special = isSpecial.booleanValue(); } |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
protected int childCount; |
| 140 |
|
public int getChildCount() |
| 141 |
|
{ |
| 142 |
0 |
if ( childCount == -1 ) |
| 143 |
|
{ |
| 144 |
|
|
| 145 |
|
|
| 146 |
0 |
if ( childCount < 0 ) childCount = 0; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
0 |
if ( childList != null ) |
| 153 |
|
{ |
| 154 |
0 |
return childList.size(); |
| 155 |
|
} |
| 156 |
|
else |
| 157 |
|
{ |
| 158 |
0 |
return 0; |
| 159 |
|
} |
| 160 |
|
}; |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
protected List childList; |
| 165 |
|
public List getChildList() |
| 166 |
|
{ |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
0 |
if ( childList == null ) |
| 181 |
|
{ |
| 182 |
0 |
childList = new LinkedList(); |
| 183 |
|
} |
| 184 |
0 |
return childList; |
| 185 |
|
} |
| 186 |
|
public void setChildList( List aChildList ) |
| 187 |
|
{ |
| 188 |
0 |
childList = aChildList; |
| 189 |
0 |
} |
| 190 |
|
|
| 191 |
|
protected TestObject parent; |
| 192 |
0 |
public TestObject getParent() { return parent; } |
| 193 |
0 |
public void setParent( TestObject anObject ) { parent = anObject; } |
| 194 |
|
|
| 195 |
0 |
public String getHash() { return Integer.toHexString( System.identityHashCode( this ) ); } |
| 196 |
|
|
| 197 |
|
public String getFullName() |
| 198 |
|
{ |
| 199 |
|
|
| 200 |
0 |
return firstName + " " + middleName + " " + lastName; |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
public boolean equals( Object anObject ) |
| 204 |
|
{ |
| 205 |
0 |
return anObject == this; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
public String toString() |
| 209 |
|
{ |
| 210 |
0 |
return "[" + getClass().getName() |
| 211 |
0 |
+ "@" + Integer.toHexString( System.identityHashCode(this) ) |
| 212 |
0 |
+ ":" + getFullName() + "]"; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
0 |
private static Random random = new Random(); |
| 218 |
|
private static String randomParse( String aString ) |
| 219 |
|
{ |
| 220 |
0 |
String result = ""; |
| 221 |
0 |
StringTokenizer tokens = new StringTokenizer( aString, "|" ); |
| 222 |
0 |
int n = (int) ( random.nextDouble() * tokens.countTokens() ); |
| 223 |
0 |
for ( int i = 0; i <= n; i++ ) |
| 224 |
|
{ |
| 225 |
0 |
result = tokens.nextToken(); |
| 226 |
|
} |
| 227 |
0 |
return result; |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
public Object valueForKey( String aKey ) |
| 240 |
|
{ |
| 241 |
0 |
System.out.println( "valueForKey: " + aKey ); |
| 242 |
0 |
return EOKeyValueCodingSupport.valueForKey( this, aKey ); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| 251 |
|
|
| 252 |
|
|
| 253 |
|
public void takeValueForKey( Object aValue, String aKey ) |
| 254 |
|
{ |
| 255 |
0 |
System.out.println( "takeValueForKey: " + aValue + " : " + aKey ); |
| 256 |
0 |
EOKeyValueCodingSupport.takeValueForKey( this, aValue, aKey ); |
| 257 |
0 |
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
|
|
| 263 |
|
public Object storedValueForKey( String aKey ) |
| 264 |
|
{ |
| 265 |
0 |
System.out.println( "storedValueForKey: " + aKey ); |
| 266 |
0 |
return EOKeyValueCodingSupport.storedValueForKey( this, aKey ); |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
|
public void takeStoredValueForKey( Object aValue, String aKey ) |
| 274 |
|
{ |
| 275 |
0 |
System.out.println( "takeStoredValueForKey: " + aValue + " : " + aKey ); |
| 276 |
0 |
EOKeyValueCodingSupport.takeStoredValueForKey( this, aValue, aKey ); |
| 277 |
0 |
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| 285 |
|
public Object handleQueryWithUnboundKey( String aKey ) |
| 286 |
|
{ |
| 287 |
0 |
System.out.println( "handleQueryWithUnboundKey: " + aKey ); |
| 288 |
0 |
return EOKeyValueCodingSupport.handleQueryWithUnboundKey( this, aKey ); |
| 289 |
|
} |
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
public void handleTakeValueForUnboundKey( Object aValue, String aKey ) |
| 298 |
|
{ |
| 299 |
0 |
System.out.println( "handleTakeValueForUnboundKey: " + aValue + " : " + aKey ); |
| 300 |
0 |
EOKeyValueCodingSupport.handleTakeValueForUnboundKey( this, aValue, aKey ); |
| 301 |
0 |
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
|
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
public void unableToSetNullForKey( String aKey ) |
| 311 |
|
{ |
| 312 |
0 |
System.out.println( "unableToSetNullForKey: " + aKey ); |
| 313 |
0 |
EOKeyValueCodingSupport.unableToSetNullForKey( this, aKey ); |
| 314 |
0 |
} |
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
|
public static void main( String[] argv ) |
| 320 |
|
{ |
| 321 |
0 |
int count = 100; |
| 322 |
0 |
boolean xmlMode = false; |
| 323 |
0 |
if ( argv.length > 0 ) |
| 324 |
|
{ |
| 325 |
0 |
Integer parsed = ValueConverter.getInteger( argv[0] ); |
| 326 |
0 |
if ( parsed != null ) count = parsed.intValue(); |
| 327 |
|
|
| 328 |
0 |
if ( argv.length > 1 ) |
| 329 |
|
{ |
| 330 |
0 |
if ( argv[1].indexOf( "xml" ) > -1 ) |
| 331 |
|
{ |
| 332 |
0 |
xmlMode = true; |
| 333 |
|
} |
| 334 |
|
} |
| 335 |
|
} |
| 336 |
|
|
| 337 |
0 |
long millis = System.currentTimeMillis(); |
| 338 |
|
|
| 339 |
0 |
DataSoup store = null; |
| 340 |
0 |
if ( xmlMode ) |
| 341 |
|
{ |
| 342 |
0 |
store = new XMLFileSoup( "testObjects-xml" ); |
| 343 |
0 |
} |
| 344 |
|
else |
| 345 |
|
{ |
| 346 |
0 |
store = new SerializedFileSoup( "testObjects-java" ); |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
Object o; |
| 350 |
0 |
for ( int i = 0; i < count; i++ ) |
| 351 |
|
{ |
| 352 |
0 |
store.addObject( new TestObject() ); |
| 353 |
|
} |
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
0 |
System.out.println( System.currentTimeMillis() - millis + " milliseconds" ); |
| 361 |
0 |
} |
| 362 |
|
} |