ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: Duplicate Key in Db
Date Wed, 23 Feb 2005 19:11:05 GMT
Have you considered a stored procedure for this?

If the rules surrounding the data are as complex and fluid as they
sound, that may be the easiest way to centralize the managment of
them.

Larry


On Wed, 23 Feb 2005 18:54:02 +0000, Tim Christopher
<tim.christopher@gmail.com> wrote:
> So what happens if you have a SQL statement that inserts data into
> serveral tables.  Every change to the database would require you to
> reevaluate what checks (select statements) need to be done to ensure a
> situtation where it is possible for duplicate primary keys to occur in
> each table.  I do not consider this to be a maintainable solution,
> even though iBATIS does seem to be the best database framework I've
> seen. :o)
> 
> Would it not be possible to override one of the iBATIS files
> introducing a try / catch loop to catch the database error at runtime
> and set it to achieve the following behaviour:
> 
>   #### ModuleService #### OLD
>   public void insertModule (Module module)
>   {
>     moduleDAO.insertModule(module);
>   }
> 
>   #### ModuleDispatchAction #### OLD
>   ModuleService moduleService = ModuleService.getInstance();
>   DynaActionForm moduleMaintenanceForm = (DynaActionForm) form;
>   Module module = new Module();
>   BeanUtils.copyProperties(module, moduleMaintenanceForm);
>   moduleService.insertModule(module);
>   ...
> 
> -----------------------------------------
> 
>   #### ModuleService #### NEW
>   public boolean insertModule (Module module)
>   {
>     return (moduleDAO.insertModule(module) != null);
>   }
> 
>   #### ModuleDispatchAction #### NEW
>   ModuleService moduleService = ModuleService.getInstance();
>   DynaActionForm moduleMaintenanceForm = (DynaActionForm) form;
>   Module module = new Module();
>   BeanUtils.copyProperties(module, moduleMaintenanceForm);
>   if (moduleService.insertModule(module)) {
>       // Update went ok
>   }
>   else {
>       // Update failed for unknown reason
>     ActionMessages msgs = new ActionMessages();
>     ActionMessage message = new ActionMessage("insert.fail");
>     msgs.add(ActionMessages.GLOBAL_MESSAGE, message);
>     saveMessages(request, msgs);
>   }
> 
>   #### App.properties #### NEW
>   insert.fail=The update failed failed.  This may be because the
> result would have caused a duplicate field where a unique value is
> required.  Please check your data, and report this to the site admin.
> 
> Ok, so that's not perfect but would save running select queries on the
> db before inserting data.  It would also mean that you wouldn't have
> to look through what checks are made when the db is modified...  I'm
> sure I must be missing something though as the above approach seems
> obvious to me :oS
> 
> Tim Christopher
>

Mime
View raw message