473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

soft lock problem

hi, we are using db2 udb v8.1 ESE with type 4 jcc driver. since DB2
can't support pessimistic locking , and our application required that,
which means when both users try to access the same record with intent
to update, the first one grab the record will create a row lock on the
current row reading, before it update, other user can't access the
same record with intent for update read, but can access with read only
type. so when the first user update the row, it will release the row
lock and let the other user with intent for update read to grab the
record. In order to do this, i think i can't use transaction and
isolation level control by the database, db2 support only optimistic
locking ,isn't it? so i think might need to use column locking (soft
lock), which means with extra column like timestamp, but the
disadvantage is when power off, some one who create the lock will
leave the flag there and when server start again, i have to clean up
all thousands tables timestamp column to start over, does anyone has
any idea how to do it efficiently? thanks
Nov 12 '05 #1
1 3569
Xixi,

My understanding is that optimistic lockis what you want and pessimistic
locking is what DB2 does.
Try this (not validated)

CREATE TABLE T(pk not null primary key, c1 INTEGER, version INTEGER)
;
CREATE TRIGGER trg1 NO CASCADE BEFORE UPDATE ON T OF (version)
REFERENCING NEW AS n OLD AS o FOR EACH ROW MODE DB2SQL
SET n.version = CASE WHEN n.version = o.version
THEN -n.version
ELSE raise_error('38000', 'version mismatch')
END
;
-- trg2 must be defined after trg1!
CREATE TRIGGER trg2 NO CASCADE BEFORE UPDATE ON T
REFERENCING NEW AS n OLD AS o FOR EACH ROW MODE DB2SQL
SET n.version = CASE WHEN n.version = -o.version
THEN n.version + 1
ELSE raise_error('38001',
'version not specified')
END
;
CREATE TRIGGER trg3 NO CASCADE BEFORE INSERT ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
SET n.version = 1
;

SELECT c1, version INTO v_c1, v_version FROM T WHERE pk = 5;
.....
UPDATE T SET c1 = v_c1, version = v_version WHERE pk = 5;
....
From CLI you can also use optimistic locking through scrollable cursors.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
6
by: Mark | last post by:
Hi, My page has a table with many columns such that the right-side of the table gets chopped off when printed. I specify a table width of 100%, but otherwise no cell dimensions are specified. ...
1
by: com | last post by:
Extreme Web Reports 2005 - Soft30.com The wizard scans the specified MS Access database and records information such as report names, parameters and subqueries. ......
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
4
by: tbatwork828 | last post by:
Related to my other post on Graphics.FillRectangle and a lot of page faults caused by this call... We determine that when Control.DoubleBuffer=true to avoid the flicker effect,...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: call_me_anything | last post by:
I sometimes wonder how rapidly all the soft junk is increasing in today's world. Look at the number of mails getting piled up, CVS histories and log files, message groups' collosum of info etc....
0
by: paulvz882 | last post by:
comprimes de acomplia en France commander acomplia en ligne aucune prescription acomplia canada soft en ligne +++ PERTE DE POIDS +++ PERTE DE POIDS +++ PERTE DE POIDS +++ + ACHETER DU ACOMPLIA...
0
by: jkjtjktjktjhktjk | last post by:
acheter du acomplia cinq acomplia par email PERTE DE POIDS en France acomplia canada soft en ligne acomplia belgique acomplia belgique bon marche acheter du acomplia en ligne sur internet +++...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.