Re: Design Question

Ray Kiddy <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
On Jul 20, 2006, at 6:00 PM, Michael Deninger wrote:

> I have a design question that I would like to bounce off some of  
> you more experienced WO developers..
>
> I have some static data that I need to access from within an  
> EOGenericRecord. The data, unfortunately, is not in the DB (and  
> even if it were, creating a relationship to the entity would likely  
> not work for various reasons). The data is essentially a dictionary  
> of keys / values that describe the meaning of the coded values in  
> one of the database tables. E.G.
>
> Entity: PatientAllergy
> 	Attribute: AllergyCode
>
> where AllergyCode is some number (say 83). The meaning of that  
> number is in this dictionary (e.g. value = 83, description =  
> "penicillins")
>
> What is the best way to accomplish this? I have considered the  
> following:
>
> 1) read this dictionary into my Application object at startup.  
> Sounds great, but I cannot figure out how to access EOApplication  
> from an EOGenericRecord
> 2) read this dictionary form disk into each EOGenericRecord at the  
> time it is created. I think that this would work, but it creates a  
> lot of unnecessary repetition of data.
> 3) hard-code the dictionary into an abstract class extending  
> EOGenericRecord and have the Entity inherit from it.
>
> Obviously, I would love to use 1) but I am stuck as I describe  
> above...
>
> Is there any way to accomplish number one or are there other  
> alternatives that I have not thought of or considered?
>
> Thanks!
>
> Mike
> _______________________________________________

Dictionaries that come into your application from the file system are  
exactly like dictionaries that come into your application from the  
database.

You could go ahead and make EOs out of the the AllergyCode  
dictionaries. Since it is static data, i would go ahead and do it in  
the EOSharedEditingContext for the application. This is a good place  
to put shared, read-only data. Or you could just keep the array of  
dictionaries in your application instance.

If you do not want to keep these in a database, you are essentially  
re-implementing your own simple database. That is fine, but I would  
ask why the data cannot go into a database. After all, a file system  
is a database also. It is just one with dumb, or perhaps just  
inflexible, searching.

You can get your application instance from anywhere. Just use the  
static method on the Application class: application().

It may be useful to go through the javadoc and make a list for  
yourself of the static methods. It is very instructive to do so.  
Every static method is the start of a new kind of pathway into the  
classes.

By the way, if you do put this stuff into a shared editing context,  
you can also use the editingContext() method from your EO, then the  
sharedEditingContext() method from that. There's lots of ways to go.

- ray
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.