-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: need some help comming up with a better app model
PostPosted: Thu Oct 16, 2003 3:57 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
I want to have objects like:
User
Event
Gallery
Image

Gallerys can have many Images
Users can have many Gallerys
Events can have many Gallerys

currently I have a UserGallery and EventGallery that has the relationship between the User/Event and Gallery but im looking for better solution, I want to be able to view a Gallery and know who owns it, either a User or an Event.

how should I have it to where I only have one Gallery and that Gallery be 'owned' by either a User or an Event?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2003 4:08 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Well, one idea is to create an Owner superclass, which both User and Event extend, and of course, add in their own properties.

So, each, Gallery would have an Owner, and each Owner can have many Gallerys.

A slight variation is to have a table: Owner, in your DB that links to Gallery, and it has two fields, UserID and EventID, which are mutually exclusive, i.e. it has one or the other, the blank one being null or 0, which link to your User and Event tables.

That way you don't have to worry about superclassing.

Any help?

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2003 6:14 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
I actually thought about doing exactly what you mentioned in the second scenario about the gallery having either UserId or EventId but still trying to figure out a cleaner solution.

as far as the owner superclass you mentioned, how would I find out who owns the gallery from the gallery object?

something like gallery.getOwner()
would the Owner object return be a User or an Event? im confused on how this should work


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2003 6:22 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Well, getOwner() would be correct, and it would return an Owner type. To check if it was a User or Event, well, I guess the only way would be to do something like this:

Code:

User user = null;
Event event = null;
int type = 0;

try {
    user = (User) gallery.getOwner();
    type = 1;
}
catch (ClassCastException cce) {
    event = (Event) gallery.getOwner();
    type = 2;
}

if (type==1) {
    //handle as User
}
else if (type==2) {
    //handle as Event
}

Something like that...still a bit messy though...was just an idea. :)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2003 6:58 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
thats sort of what im doing now, but I check to see if a Gallery is in a UserGallery or EventGallery then I get the owner of the Gallery using EventGallery.getEvent(), EventGallery holds the Event and Gallery


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.