Re: Design Question
shaun <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Michael,
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
WO can load a properties file for you, so you could read in the data in
the application constructor and store it in a static. Then you can
access it as Application.myDictionary, but this is poor style from the
EO's. Maybe something like the following instead:
//NOTE: untested code
import com.blah.blah.Lookup.Foo;
public Application() {
super();
//Read xyz from somewhere. eg) Properties.
Foo.s = "xyz";
}
package com.blah.blah.Lookup;
public class Foo {
//dictionary would be better for multiple.
public static String s = null;
}
import com.blah.blah.Lookup.Foo;
public Bar extends EOGenericRecord{
//Use a dictionary for multiple.
private String fooValue;
private void loadFoo(){
if(fooValue == null){
fooValue = Foo.s;
}
}
awakeFromFetch(...){
loadFoo();
}
awakeFromInsertion(...){
loadFoo();
}
}
HTH.
cheers,
- shaun