Re: Canonical objects

From: Gili (cowwo..bs.darktech.org)
Date: Sat Sep 03 2005 - 21:23:54 EDT

  • Next message: Gili: "Re: Canonical objects"

            Optimistic locking only operates over a row, right? Not an entire table...

            I think maybe what I have to do is find out which columns are used by
    getCanonicalInstance() and flag them as unique, then my current
    implementation is guaranteed to not run into race conditions. The only
    problem now is that if a race condition occurs my code will get a
    constraint violation exception instead of a optimistic locking
    exception. When the latter occurs my code would retry. When the former
    occurs it is flagged as a bug and I don't handle the exception.

            There needs to be a way for me to flag the former as a recoverable
    operation. I'm not sure how.

    Gili

    Mike Kienenberger wrote:
    > You'd have to do the same thing in Cayenne, or another workaround (try
    > to insert the object and throw it away if you get a constraint
    > violation exception). You're going to have race conditions if you
    > check, then create, then insert. That said, I have used the same
    > process.
    >
    > I wonder if a better workaround might be to create a psuedo-optimistic
    > lock on your unique keys.
    >
    > On 9/3/05, Gili <cowwo..bs.darktech.org> wrote:
    >
    >>Hi,
    >>
    >> Say I have:
    >>
    >>table ImageSpecification [id, width, height]
    >>
    >> In Hibernate if I created a new ImageSpecification in my application
    >>and I wanted to save it into the database only if it didn't already
    >>exist (i.e. canonicalization) I would have to manually invoke something
    >>like this:
    >>
    >>mySpecification = mySpecification.getCanonicalInstance()
    >>
    >> where getCanonicalInstance() is a method I implemented to issue a DB
    >>query and if an equivilent object was found in the DB return it;
    >>otherwise return "this". In this way I would ensure that I never ended
    >>up with two copies in the database of the same specification.
    >>
    >> Would I have to do the same with Cayenne or is there a cleaner way?
    >>
    >>Thank you,
    >>Gili
    >>--
    >>http://www.desktopbeautifier.com/
    >>
    >
    >

    -- 
    http://www.desktopbeautifier.com/
    



    This archive was generated by hypermail 2.0.0 : Sat Sep 03 2005 - 21:23:53 EDT