Re: JDBC Transactions

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Jonathan Tripathy <jonnyt(at)abpni(dot)co(dot)uk>
Cc: Filip Rembiałkowski <filip(dot)rembialkowski(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: JDBC Transactions
Date: 2010-11-01 18:54:40
Message-ID: 4CCF0CF0.3020008@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/1/2010 1:38 PM, Jonathan Tripathy wrote:
>
>>> Hi Andy,
>>>
>>> Thanks for your reply. Would the above code be classed as a single
>>> transaction then?
>> Yes, assuming there's no explicit transaction control
>> (COMMIT/ROLLBACK/END) in your queries.
> Actually, we do have maybe one or 2 queries that use ROLLBACK, however
> ROLLBACK happens at the end of a "code block" so the question is
> probably moot.
>>> And if so, I could just simple leave out the line which
>>> says "//Insert SQL here to lock table"?
>> In PostgreSQL, locking is done automatically depending on actual
>> isolation level and SQL queries.
>> You can use explicit locking but most of the time it's not needed.
>>
> I'll give you the exact case where I'm worried:
>
> We have a table of customers, and each customer can have multiple
> memberships (which are stored in the memberships table). We want our
> deleteMembership(int membershipID) method to remove the membership, then
> check to see if there are no more memberships left for the corresponding
> customer, and if there are none, delete the corresponding customer as well.
>

Hum.. yeah, I can see a race condition there. but even with table
locking I can see it. Not sure how your stuff works, but I'm thinking
website:

user1 goes to customer page, clicks on "add membership" and starts
filling out info.

user2 goes to customer page, clicks on "delete membership" of the last
member ship, which blows away the membership, then the customer.

user1 clicks save.

Wouldnt matter for user2 if you locked the table or not, right?

-Andy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Tripathy 2010-11-01 19:01:48 Re: JDBC Transactions
Previous Message Carlos Mennens 2010-11-01 18:49:39 Re: 8.4 Data Not Compatible with 9.0.1 Upgrade?