Re: Handling Unique Constraint Violations

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jul 14 2005 - 13:16:34 EDT

  • Next message: Dhruti Ramani: "Re: Cayenne Commit Exception"

    In my EOF past I used to do these checks during validation phase too.
    This of course has concurrency and performance implications in
    addition to simply being ugly...

    A cool framework-level solution would be to classify SQLExceptions
    inside Cayenne and wrap constraint failures in ValidationExceptions.
    This way users will be able to implement consistent validation
    failure handling, regardless of where the exception occurred.

    This of course requires some research and depends on whether a given
    DB engine provides enough info to distinguish between various errors.
    AFAIK Spring JDBC package attempted something like that. Maybe we can
    borrow this code. Or maybe all this is just wishful thinking...

    Andrus

    On Jul 14, 2005, at 8:20 PM, Mike Kienenberger wrote:

    > Kevin Menard <kmenar..ervprise.com> wrote:
    >
    >> What's the Cayenne best practice for handling unique constraint
    >> violations. I can see value in doing an explicit check before
    >> inserting a new row, but I can also see the drawback there (two
    >> places now need to know about this unique constraint). So, I'm
    >> thinking that going ahead with the commit and catching the exception
    >> might be cool, but it also seems to have some drawbacks.
    >> How are you guys doing it?
    >>
    >
    > The one place I've done this before (user names), I check beforehand.
    > In retrospect, I probably should have done this afterward as well.
    >
    > I think you pretty much have to check afterward to provide robust
    > code.
    >
    > But doing it beforehand is a lot easier.
    >
    > Afterward, it's more difficult to know what caused the problem.
    >
    > So I have no answers, but I'm paying attention to what answers
    > someone else
    > comes up with :)
    >
    > -Mike
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Jul 14 2005 - 13:16:34 EDT