Re: Modeling an optional to-one relationship
Re: Modeling an optional to-one relationship
- Subject: Re: Modeling an optional to-one relationship
- From: Chuck Hill <email@hidden>
- Date: Thu, 14 Jan 2010 13:46:50 -0800
Hi Mark,
On Jan 14, 2010, at 3:36 AM, Mark Ritchie wrote:
Hi Chuck!
On 13/Jan/2010, at 5:17 PM, Chuck Hill wrote:
The Obj-C implementation is hazy in my memory. In Java, rather
than throwing a hissy fit, it will create a "dummy fault EO". That
is, an EO with all null values and no real existence. What Lon
wants is a real null, not a dummy EO. Kelly Hawk's fix was to throw
an exception (the old behavior) rather than return some insane
zombie EO. That fix (thanks Kelly!) is still in my Java code and I
think lurking in Wonder somewhere too.
Yes, I believe that's the intended behaviour... The DatabaseContext
tracks that newly created EO and throws an exception if you attempt
to modify and then save it.
Almost, it throws when the fault is fired.
A search of my Wonder workarea which I'd just sync'd revealed only
one reference to the code:
./Common/Frameworks/ERExtensions/Documentation/
ReleaseNotes.txt:ERDatabaseContextDelegate - Added Kelly Hawks' fix
for the missing to one relationship
Search again, it is in ERXDatabaseContextDelegate. I just looked at
it. The Wonder version handles situations that the original code
below does not.
I could not find any of the actual implementation anymore.
If you had a Java version, perhaps you could dig it up?
My pleasure!
public class DatabaseContextDelegate
{
private Logger logger = LoggerFactory.makeLogger();
/**
* Delegate on EODatabaseContext that gets called when a to-one
fault cannot find its data in the database. The object is
* a cleared fault. We raise here to restore the functionality
that existed prior to WebObjects 4.5. Whenever a fault fails
* for a globalID (i.e. the object is NOT found in the database),
we may raise.
*
* Source: Kelly Hawk, http://wodeveloper.com/omniLists/eof/2000/December/msg00149.html
*/
public boolean
databaseContextFailedToFetchObject
(com.webobjects.eoaccess.EODatabaseContext context,
java.lang.Object object,
com.webobjects.eocontrol.EOGlobalID globalID)
{
EOEditingContext ec = ((EOEnterpriseObject)
object).editingContext();
// we need to refault the object before raising, otherwise,
if the caller traps the exception, it will be a successful
// lookup the next time a fault with the same global id
fires. NOTE: refaulting in a sharedEditingContext is illegal,
// so we specifically check for that special case.
if (! (ec instanceof EOSharedEditingContext))
{
context.refaultObject((EOEnterpriseObject) object,
globalID, ec);
}
String failureMessage = "Failed to fetch " +
object.getClass() + " with globalID " + globalID;
logger.error(failureMessage);
throw new EOObjectNotAvailableException(failureMessage);
}
}
Chuck
--
Chuck Hill Senior Consultant / VP Development
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