Re: Convenience functions in model classes
Re: Convenience functions in model classes
- Subject: Re: Convenience functions in model classes
- From: "Denis Frolov" <email@hidden>
- Date: Fri, 11 Apr 2008 11:14:30 +0400
On Fri, Apr 11, 2008 at 5:46 AM, Jeff Schmitz <email@hidden> wrote:
> Continuing on with my EO indoctrination, I think I understand the concepts
> ok, but when it comes to fleshing the concepts out into actual code I'm
> still struggling. I was hoping before I get too along down a wrong road,
> one of you experts might take a look at a small function I've added to one
> of my EO Objects. This function basically traverses down several EO
> Relationships and loops through an array of EO Objects at the end, looking
> at the state of an attribute (selectedItem) in each one in order to
> determine a result to return.
>
>
> public class Pool extends _Pool {
> private static Logger log = Logger.getLogger(Pool.class);
>
> // Question 1: Does a function like this really belong down in my EO class.
> // There's something about doing the actual Fetches in this class that rubs
> // me the wrong way, however I don't want to put it in my Component classes
> // either since there may be multiple components that would like this
> // functionality.
> // Question 2: If it does belong down in my EO class, does it belong in
> THIS EO class,
> // which represents the "top of the chain"
> // in a chain of relationships that are traversed to get the actual data to
> // return? Or should I just fetch the entry from here first and move this
> function down
> // into the Entry EO Class?
>
> // Question 3: Does this need to be static?
> public boolean hasResults(EOEditingContext ec, String poolName,
> String entryName) {
Have a look at Wonder's EOEnterpriseObjectClazz.java. A good example
of usage is BugTracker project (e.g. BugClazz.java).
Methods like this one go to clazz, they are not static and so can be
overridden in subclasses of clazz which is very useful if you have
inheritance in your model.
>
> EOQualifier poolQual = Pool.NAME.eq(poolName);
> EOQualifier entryQual = Entry.NAME.eq(entryName);
> boolean results = false;
>
> // Question 4: Is exception handling always the best way to handle the
> // no results case? OR should it be saved for cases where not
> finding
> // what you're looking for indicates there is something really
> wrong with
> // your app?
> try {
> Entry entry = Pool.fetchRequiredPool(ec, poolQual).entries(
> entryQual).objectAtIndex(0);
>
> // Check first round to see if any actuals have been set.
> for (int i = 0; i < 4; i++) {
> for (int j = 0; j < 7; j++) {
>
> // This call is to the Mike Schrag approved "game" function from
> // my previous message (see below).
> if (entry.game(i, j).selectedItem() != 2) {
>
>
> // If selectedItem isn't 2 for any game, results have been posted.
> results = true;
>
>
> //Break out of loops
> i = 4;
> j = 7;
> }
> }
> }
>
> // Question 5: Do I need any other exception handling?
> } catch (NoSuchElementException e) {
> results = false;
> }
>
> return results;
>
> }
> }
>
> On Apr 4, 2008, at 11:50 PM, Jeff Schmitz wrote:
>
>
>
> Hello
>
> As I get rolling down the EO highway, I find myself wanting to put
> convenience functions in the model classes that are generated by the
> EOGenerator (yes, I'm using the generation gap classes for this). e.g. to
> more closely mimic indexing a two dimensional array like the "old" way I
> used to do things, I create the following to retrieve a Game object from in
> from a model class that contains a one to many relationship to Game objects:
>
>
> public Game game(int group, int gameIndex) {
> EOQualifier gameQual =
> Game.GROUP.eq(group).and(Game.GAMEINDEX.eq(gameIndex));
> Game game = this.games(gameQual).objectAtIndex(0);
> return game;
> }
>
> Is this a good thing? Just hoping to get some feedback before I go too far
> down this road.
>
> Thanks,
> Jeff
>
>
> _______________________________________________
> 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
>
> _______________________________________________
> 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
>
_______________________________________________
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