ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brandon Goodin <brandon.goo...@gmail.com>
Subject Re: Duplicate Key in Db
Date Thu, 24 Feb 2005 05:15:34 GMT
You are simply performing error interpreatation for user consumption.
So, no matter what SQLException gets thrown it will simply display an
error to the user. However, i would not recommend that you get into
the practice of deciding how to proceed based upon the type of
SQLException that is being thrown. An excpetion is an exception. Pass
it back to the user and don't use it for control flow.

I personally would not get into using sql error interpretation cuz
it's more work than it's worth, imo. But, i can see where someone
would think otherwise.

Anyway, i hope you see my point. I'm not dogging someone for
interpreting an exception for user consumption. I AM saying it is bad
practice to decide how your application proceeds or fails based on the
type of SQL Exception.

Brandon


On Thu, 24 Feb 2005 04:45:38 +0000, Tim Christopher
<tim.christopher@gmail.com> wrote:
> My probably goes a little against the grain of what you are saying,
> though I've only just read your comments...
> 
> What I've done is to extend the framework to allow iBATIS to return an
> int for insertions calls, then created a constants file (as a HashMap)
> to turn returned values into entries from the properties file.
> 
> As far as I'm concerned it means that I don't have to think what
> select statements I have to do to enforce the db design - with the
> added bonus of not having to run the statements in the first place as
> they have their own overhead.
> 
> The only bad bit is how I determine the error, which is done using a
> regular expression.  Although I feel this is maybe not the cleanest
> approach I do feel it will be fast, reliable, and require no
> additional configuration (other than to set the appropiate value in my
> properties file).  It also means that if I discover a better way to
> catch the error I can change it in the extension bit I have written
> without updating anything else.  Furthermore you could just as easily
> catch more errors and have a different value in your properties file
> for each.
> 
> Beow is how my app deals with the connection:
> 
> >>>>>>
> int errorStatus = moduleService.insertModule(module);
> if (errorStatus < 0) { // All error states have a negative value in
> constants file.
>     String propertiesName = SqlMapDaoConstants.getErrorKey(errorStatus);
>     ActionMessages msgs = new ActionMessages();
>     ActionMessage message = new ActionMessage(propertiesName);
>     msgs.add(ActionMessages.GLOBAL_MESSAGE, message);
>     saveMessages(request, msgs);
>     return mapping.findForward("insertSuccess");
> }
> // Insertion was a success
> // Note: Variable 'msgs' used as not to hide field:
> //                'org.apache.struts.actions.DispatchAction.messages'
> ActionMessages msgs = new ActionMessages();
> ActionMessage message = new ActionMessage(
>                                                "message.module.insert.success");
> msgs.add(ActionMessages.GLOBAL_MESSAGE, message);
> saveMessages(request, msgs);
> return mapping.findForward("insertSuccess");
> <<<<<<
>

Mime
View raw message