Hi there,

again I've bumped into a pretty darn weird behaviour.

All my PKs are INTs, all generated by EOF (occasionally through 
rawPrimaryKeyInTransaction, most times — and unless I am overlooking something, 
*all the times* in the problem described below, the most usual way, simply as a 
side-effect of a save).

One of my entities has a DB constraint which makes sure its auctionSeq 
attribute stays unique. There's the following code to keep it so (simplified 
for better readability):

===
def mySaveChanges(ec) {
    try {
        ec.saveChanges()
    } catch (EOGeneralAdaptorException e) {
        ec.rootObjectStore.lock() // possibly superfluous at this moment, can't 
harm
        String emsg=e.localizedMessage, 
cname='UNIQUE_AUCTION_SEQ_CONSTRAINT_NAME(C_AUCTION_SEQ=' // incidentally, is 
there a better way to recognise a constraint? This is UGLY (but works OK)
        if (emsg.indexOf(cname)<0) throw // another problem, let's fail saving
        def failedauction=ec.registeredObjects.find { it instanceof DBAuction }
        ++failedauction.auctionSeq
        mySaveChanges(ec) // let's try again with an incremented seq
        ec.rootObjectStore.unlock()
    }
}
===

It very rarely happens that the code is actually needed, but it is possible 
e.g., if two users create auctions concurrently. Today, it happened -- 
strangely enough, only one user created auction, but some dumb tester left 
auctions with nonsensical seqs (much higher than the current value at the time) 
in the DB long long ago, and we just have bumped into them today.

The code above worked perfectly, there were two bad test auctions (say, with 
seqs 2766 and 2767, with the current seq just reaching 2766), their seqs were 
skipped all right, newly created auction was stored without a glitch with the 
proper unique seq 2768 and a new PK, say, 1012857. So far so good.

*But* five minutes later, the user created another new auction. There was 
absolutely no problem app-side, the newly created action got new unique seq 
2769, but EOF assigned to it *again* the same PK, 1012857! Of course, save 
failed.

The user logged out, logged in, and this time in new session and new EC created 
the new auction all right, seq 2769, PK 1012858, all well and swell.

Couple of minutes later, another user, logged in for hours, tried to create a 
new auction is his independent session with a different EC, and *again* got PK 
1012857 (and of course, save failed)! He did not try again.

Can perhaps anyone see a possible culprit? Thanks!
OC

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to