Non class properties
Non class properties
- Subject: Non class properties
- From: Mark Wardle <email@hidden>
- Date: Thu, 13 Jan 2011 22:39:54 +0000
Hi.
I've written a webobjects export to file-based database framework that supports exporting multiple entities to both MS Access and multiple CSV files wrapped up as a CSV file. I don't simply want to export the raw rows or use SQL directly as I need to use logic from the WebObjects side of things (e.g. only downloading information about patients registered with a certain research project when such membership is not simply modelled relationally but by a complex series of consent forms linked to the patient entity via encounter entities). I subsequently use these exported data for specific audit and research / analysis purposes. (I don't want to have to re-write some of this business logic in R for example).
Each table is built using an entity, a qualifier and (optionally) a list of keypaths although the latter will default to the attributes for the entity by default.
All is fine for class properties and everything is exported nicely using either file-based database backend. These values are obviously returned by simply using valueForKeyPath(). Users choose a download format and the database is exported and they receive a message when the export is complete - they then have a link to download and can use this (anonymised, all patient-identifiable information removed) for offline analysis.
The problem is non-class properties.
I need to include arbitrary EO properties (that may invoke complex java logic), EO attributes (standard class properties) and relationships *as well as* non-class properties such as primary keys and foreign keys.
My naive approach was this:
protected static Object valueForKeyPath(Object object, String keyPath) {
Object value = null;
try {
value = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, keyPath);
}
catch(NSKeyValueCoding.UnknownKeyException e) {
int index = keyPath.indexOf('.');
Object src = "">
if (index >= 0) {
String path = ERXStringUtilities.keyPathWithoutLastProperty(keyPath);
src = "" path);
}
String key = ERXStringUtilities.lastPropertyKeyInKeyPath(keyPath);
if (src instanceof EOEnterpriseObject) {
NSDictionary<String, Object> snapshot = ((EOEnterpriseObject) src).snapshot();
value = snapshot.valueForKey(key);
}
}
return value;
}
Although clearly this does not work as the snapshot doesn't contain the non-class properties either.
Is it possible to get at the raw row dictionary from an enterprise object or am I better to fetch the raw rows first, upgrade this into an EO and then fallback to the raw row if the key is not found?
Or is there an easier way to get at non-class properties?
Many thanks,
Mark
--
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden