[smartweb-user] Entity -IntegrityReferenceException
Brought to you by:
rlogiacco
|
From: Pino C. <gco...@gm...> - 2007-06-05 12:46:54
|
Need a control of IntegrityReference when we try to remove an Object from
data-base.
Maybe the Object is referenced from another table in the database and we
must implement a logical remove method.
A possible solution for this problem is:
1) Insert IntegrityReferenceException in
net.smartlab.web.BusinessObjectFactory in the method remove
so the last user is forced to manage this Exception and to implement a
logic while removing an Object from DB.
2) Create a method isRemovible(Object o) in the class referenced that can
throws an IntegrityReferenceException
Es.: I have to remove a CommessaObject from my Db and it's just referenced
from a ProgettoObject and AttivitaObject.
In ProgettoFactory I've implemented a method "boolean existByCommessa(long
id) throws DAOException " and in AttivitaFactory another method "boolean
existByCommessa(long id) throws DAOException "
then I've used re-call these methods in Domain in the method
removeCommessa(String id):
public void removeCommessa(String id) throws BusinessException
,IntegrityReferenceException{
=09=09
=09=09CommessaFactory factory =3D CommessaFactory.getInstance();
=09=09try {
=09=09=09long idCommessa=3DLong.parseLong(id);
=09=09=09if(ProgettoFactory.getInstance().existsByCommessa(idCommessa) ||
AttivitaFactory.getInstance().existsByCommessa(idCommessa)){
=09=09=09=09logger.error("Errore in isRemovibleCommessa");
=09=09=09=09throw new IntegrityReferenceException("Errore di integrit=C3=A0
referenziale");
=09=09=09}
=09=09=09
=09=09=09Commessa toRemove =3D (Commessa) factory.findByKey(Long.parseLong(=
id));
=09=09=09factory.remove(toRemove);
=09=09} catch (DAOException daoe) {
=09=09=09throw new BusinessException(daoe.getMessage());
=09=09}
=09}
In this way in the CommessaAction ,the method remove may throws an
IntegrityReferenceException that we can catch in this way:
public String remove(ActionForm form, HttpServletRequest request,
HttpServletResponse response, ActionMapping mapping) throws ActionException
{
=09=09logger.info("remove di CommessaAction");
=09=09try {
=09=09=09String id =3D request.getParameter("id");
=09=09=09Domain.getInstance().removeCommessa(id);
=09=09} catch (BusinessException e) {
=09=09=09logger.error("errore in remove di CommessaAction", e);
=09=09=09throw new ActionException(e.getMessage(), e.getCause());
=09=09} catch (IntegrityReferenceException ire) {
=09=09=09logger.error("Non posso eliminare il tipo di commessa- ire");
=09=09=09super.addError(new ActionMessage("errors.progetto.reference"), req=
uest);
=09=09=09return "failure";
=09=09}
=09=09return "success";
=09}
It'all..Now It's tima to do it!!
--=20
View this message in context: http://www.nabble.com/Entity--IntegrityRefere=
nceException-tf3871534s17546.html#a10968695
Sent from the SmartWeb Users mailing list archive at Nabble.com.
|