Re: Of Inheritance and AwakeFromInsertion
Re: Of Inheritance and AwakeFromInsertion
- Subject: Re: Of Inheritance and AwakeFromInsertion
- From: David Avendasora <email@hidden>
- Date: Wed, 19 Mar 2008 11:42:10 -0400
On Mar 19, 2008, at 11:02 AM, Chuck Hill wrote:
On Mar 19, 2008, at 5:21 AM, David Avendasora wrote:
Hi all,
I've run into something that _seems_ to work, but just seems
"wrong" and I don't see how to do it "right".
I have the following inheritance structure in my model:
LotCode (NOT abstract)
ManufacturedBatch extends LotCode.
When I call awakeFromInsertion on the superclass I do it as follows :
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (lotCodeType() == null) {
setLotCodeType(1);
}
}
But when I call awakeFromInsertion on the subclass I have to do this:
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (lotCodeType() == null || lotCodeType.equals(1)) {
setLotCodeType(2);
}
}
I know that you should _never_ change the class of an EO after
creating it, but that's exactly what I'm doing here.
Well, no. You are changing the value that EOF uses to determine
class when it fetches the object.
So, even though the restricting qualifier value is changing that
doesn't actually impact what attributes and relationships that EOF
sees as part of the Object? Is it just when it goes to save the EO
that it checks to see it's type to know how to save it? What parts of
EOF pay attention to the restricting qualifier?
When awakeFromInsertion is called on the subclass, the first thing
it does is call super.awakeFromInsertion, which sets the class to
LotCode, but then I change it to a ManufacturedBatch immediately
after.
The Java object is already created. It class does not and can not
change.
Since the restricting qualifier != instanceOf, I have to be careful
because it would be possible to instantiate as one thing but set the
qualifier to something else.
If I don't do this, a call of ManufacturedBatch
newManufacturedBatch = new ManufacturedBatch() returns a LotCode
instead.
! (newManufacturedBatch instanceof ManufacturedBatch)? That seems
highly improbable just after a call to new.
Okay, I was confusing myself. In the UI of the application it shows
(based on the restricting qualifier's value) if the object is a
LotCode or ManufacturedBatch. I was interpreting this as ==
instanceOf. It was actually an instance of ManufacturedBatch, even
though the UI showed LotCode.
So, is this an exception to the rule "never change an EO's class"
or is it because I'm doing it in the awakeFromInsertion process
that it is okay?
Or is it wrong to do this and I just haven't been bitten by it yet?
Either your description above is inaccurate, or something is totally
wacked out in your code.
Most likely a little of column A, and a little of column B.
Dave
_______________________________________________
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