Re: Question about reusing model entities
Re: Question about reusing model entities
- Subject: Re: Question about reusing model entities
- From: Chuck Hill <email@hidden>
- Date: Wed, 16 Jul 2008 20:25:25 -0700
On Jul 16, 2008, at 5:37 PM, Chris Meyer wrote:
Thanks. This looks useful.
Do you do something similar with the DB connection? I've now got a
model in my framework and a model in my application. Some of the
entities in the framework are generic and can optionally be
subclassed (User); others are unlikely to be subclassed
(UserLogEntry).
How do I tell the framework that its entities should be accessed via
the connection in the model in my application rather than the one in
the framework's own model?
See page 53 of Practical WebObjects. Wonder also has code for this as
do the GVC frameworks, Houdah Frameworks, and probably the WO Wiki.
And if a method in the framework fetches and returns an entity, how
would it know to return the subclass of the entity defined in the
application rather than the generic entity in the framework? (This
question probably shows my confusion... I'm sure I'm just thinking
about this problem wrong!)
An object is the type that it is. Anything you say while fetching
won't change that fact. Trust in EOF but make sure your fetches are
deep.
Chuck
On Jul 16, 2008, at 5:09 PM, Jean-François Veillette wrote:
Whenever used, we use the notification of model loaded, and at
runtime change whatever values needed to be tweeked for the current
project. Like changing table name, setting isAbstract (or not),
playing with relationship, etc.
Here is a simple case where we define the isAbstract attribute on
all the entities of a generic model :
first ...
NSNotificationCenter
.defaultCenter().addObserver(AProjectControlerClass.class, new
NSSelector("modelLoadedNotification", new Class[]
{ NSNotification.class }), EOModelGroup.ModelAddedNotification,
null);
and latter ...
public static void modelLoadedNotification(final NSNotification
notification) {
NSLog.debug.appendln(AProjectControlerClass.class.getName() + "
notificationModelCharge...");
EOModel model = (EOModel) notification.object();
if (model.name().equals("AGenericModel")) {
NSArray entities = model.entities();
log.info(model);
Enumeration enim = entities.objectEnumerator();
while (enim.hasMoreElements()) {
EOEntity entity = (EOEntity) enim.nextElement();
log.info(entity);
entity.setIsAbstractEntity(true);
}
}
}
- jfv
Le 08-07-16 à 17:32, Chris Meyer a écrit :
And what about adding additional relationships specific to the
application to the User entity?
Name it GenericUser (or whatever) in the framework. Subclass
GenericUser as User in the app model and add whatever you need.
Done.
Great! It sounds like I'm on the right track.
So how does WO handle the table name? In the framework, the
GenericUser entity will have a table name (and, implicitly, a DB
connection). When subclassing/extending the object in the
_application_, is the table name and connection in the _framework_
just ignored?
--
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
_______________________________________________
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