• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Non class properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non class properties


  • Subject: Re: Non class properties
  • From: Mark Wardle <email@hidden>
  • Date: Fri, 14 Jan 2011 19:51:14 +0000

Thanks Chuck,

This now works perfectly.

Many thanks,

Mark

On 13 January 2011 23:19, Chuck Hill <email@hidden> 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 = ""> >             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

--
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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Non class properties (From: Mark Wardle <email@hidden>)
 >Re: Non class properties (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: mutually exclusive 1-to-0 or 1 relationship modeling
  • Next by Date: Re: Hudson and frameworks reference
  • Previous by thread: Re: Non class properties
  • Next by thread: Hudson and frameworks reference
  • Index(es):
    • Date
    • Thread