Thanks Chuck,

This now works perfectly.

Many thanks,

Mark

On 13 January 2011 23:19, Chuck Hill <[email protected]> wrote:

> From Wonder's ERXCustomObject:
>
>    protected String _primaryKey = null;
>    public String primaryKey() {
>        if(_primaryKey == null) {
>        _primaryKey = ERXEOControlUtilities.primaryKeyStringForObject(this);
>        }
>        return _primaryKey;
>    }
>
> For relationships, call this on the related object or NSArray of related
> objects (e.g. tests.valueForKey("primaryKey")).
>
>
> Chuck
>
>
> On Jan 13, 2011, at 2:39 PM, Mark Wardle wrote:
>
> > 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 = object;
> >             if (index >= 0) {
> >                       String path =
> ERXStringUtilities.keyPathWithoutLastProperty(keyPath);
> >                       src =
> NSKeyValueCodingAdditions.Utility.valueForKeyPath(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 protected])
> > Help/Unsubscribe/Update your Subscription:
> >
> http://lists.apple.com/mailman/options/webobjects-dev/chill%40global-village.net
> >
> > This email sent to [email protected]
>
> --
> Chuck Hill             Senior Consultant / VP Development
>
> Practical WebObjects - for developers who want to increase their overall
> knowledge of WebObjects or who are trying to solve specific problems.
> http://www.global-village.net/products/practical_webobjects
>
>
>
>
>
>
>
>


-- 
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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to