Hi,
I have added a long overdue functionnality for the framework: reference
constraints
Before when we wanted to delete an entity that was being referenced by
another entity, we would get a "A major error has occured". The reason
is that the exception is an SQL Exception. Therefore we could not
differenciate this exception from any other SQLException. This was
quite a drag because if, for example, you want to delete a city but this
city is referenced by 10 addresses, you would need to:
- Try deleting the city and get a "A major error has occured",
- "Guess" that the reason is a Foreign Key Exception,
- Start looking for those references and delete them.
- Try deleting the city again.
I have therefore implemented a solution to this problem:
Since there is no way to differenciate SQLExceptions other than by
parsing their text (which is unacceptable since it would be dependent on
the underlying database), I have added a method in the entity DAO which
validates if there are any references before the delete.
If the validation finds such references, a ReferenceConstraintException
is thrown in which is stored a list of ReferenceConstraint instances. A
ReferenceConstraint has 2 attributes:
- class: the class of the entity that references the entity we wish to
delete
- identifier: a string representing this particular instance (built with
the toString)
In the front end, I made a ReferenceConstraintExceptionHandler that
simply builds messages with the list of ReleaseConstraints and calls the
systemAlertTile to display them.
This will without a doubt cause the delete to be a little slower but at
least the exception will be properly handled and will already give an
insight to the user as to which entities he needs to go modify
references to.
If you have any questions or objections concerning this, let me know.
François
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Mdarad-toolbox-devs mailing list
Mdarad-toolbox-devs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mdarad-toolbox-devs