[Opensource] Implementing declarative referencial integrity
Stephen Owens
sowens at csdcorp.com
Fri Aug 2 11:36:06 PDT 2002
Mike,
Not quite true...there's another half to this. Your DBObjects can
override the checkAllRefferedToBy() method to enforce integrity during
deletions of foreign key targets to ensure nobody is referring to them.
Within that method I use the referredToBy method to test whether anybody
is using the record. I don't think this is the highest performance
method possible, but it certainly works, I've used it successfully in a
couple of projects.
Here's an example. In this example the FDCategory class implements the
checkAllReferredToBy method to ensure that you can't delete a category
that is in use by an activity. The referredToBy method checks the
activity using the primary key of the category and the foreign key
FDActivity.FLD_CATEGORY_ID in the activity table. Some messy details
like setting the database name are taken care of in the class
constructors in this example.
/*
* This method overrides the method in DBObject to ensure that deletions
* don't corrupt referential integrity.
*/
protected synchronized void checkAllReferredToBy() throws DBException
{
FDActivity activity = new FDActivity();
referredToBy( activity, FDActivity.FLD_CATEGORYID,
"This category is still in use at an activity, you may not delete
it." );
} /* checkAllReferredToBy() */
> -----Original Message-----
> From: Michael Rimov [mailto:rimovm at centercomp.com]
> Sent: Friday, August 02, 2002 1:21 PM
> To: opensource at jcorporate.com
> Subject: Re: [Opensource] Implementing declarative referencial
integrity
>
> At 05:31 PM 8/1/2002 +0200, you wrote:
>
> >Hello,
> >
> >
> > According to the developer's guide, declarative referencial
> integrity
> >can be used for DBObjects, but it doesn't say how.. I found about
using
> >foreign keys in MultiDBObjects, but they are read-only. In the rest
of
> >docs, FAQs and Forum I found nothng about it.
> >
> > Is it actually possible?? If yes, how can it be done?
>
> I would say that it's not fully available yet. So far, if you call
> addDetail() from the 'master' dbobject then calling delete() can
delete
> all
> the 'detail' objects. However, I don't believe anybody has
implemented
> anything further than that. AT this point, I would still recommend
adding
> referential integrity through mainly your database server.
>
> HTH!
> -Mike
>
> _______________________________________________
> Opensource mailing list
> Opensource at jcorporate.com
> http://mail.jcorporate.com/mailman/listinfo/opensource
> Archives: http://mail.jcorporate.com/pipermail/opensource/
More information about the Opensource
mailing list