-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Test lock
PostPosted: Wed Dec 06, 2006 1:16 pm 
Newbie

Joined: Wed Dec 06, 2006 1:10 pm
Posts: 3
Think this a very simple question, but i couldn't found any satisfying answer yet.

Lets says that a Thread put a lock on a given row of a table ( using session.lock(myObj, LockMode.UPGRADE for example ).

How can i test, in another thread, ( or a complete other application that connects to the same database ) whether that row ( let's say i know the object id ) is "locked" or not ?

Thanks a lot, and sorry if my question is really stupid.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 2:15 pm 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
I think, that better term, that applied to this situation, is transaction. When one transaction sets pessimistic lock on row (or collection of rows), any other transaction will be wait until first transaction completes and releases this lock. For test, you must have one long working transaction that sets the lock or simply use db vendor tool to see what rows (or, in case lock escalation, even tables) has been locked. Do i understand your question right?

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:34 am 
Newbie

Joined: Wed Dec 06, 2006 1:10 pm
Posts: 3
Yes, you got my question quite well.
I've already manage to code a test program where the other thread has to wait until the first is finished ( and releases the row ).

Here is my problem, more specifically :
I use hibernate without a server entity ( ok, it's not the textbook case ). I only have n client instances that connect to the same database.
Before i start thinking about setting a manual lock on some business objects ( = row in one of my tables ), i wanted to know if there is a way to do the following :

> Ask the database if a row is locked ( physically )
> if it's not locked, lock it when retrieving it
> if it's locked, give up ( the user then gets a message like "object is locked, please try later" ) without waiting

The problem is that i can't find a way to make this "test" . Couldn't find any method with a return result, or with an exception thrown in case the object is locked

would really appreciate help on this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 6:24 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Well, as i know, there is an option, but it's applied only to Oracle:

LockMode.UPDGRADE_NOWAIT—The same as UPGRADE, but use a SELECT...FOR UPDATE NOWAIT on Oracle. This disables waiting for concurrent lock releases, thus throwing a locking exception immediately if the lock can’t be obtained.

_________________
Best Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.