Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Informix Topics / December 2004

Tip: Looking for answers? Try searching our database.

Informix locking & transactions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BigBob - 30 Dec 2004 00:07 GMT
I need to lock a ROW in an Informix table and hold onto that lock until
the end of a transaction.  During this transaction, 2 seperate Java
processes MIGHT start and want to update a table held in that
transaction before it is released.  Is there any way to accomplish
this?

Let me explain...

An online application issues a "begin work" then opens a cursor with a
select for update going after a single row in a table (e.g. Table A).
The business requires that no one else be allowed to access 'child
tables' linked to that particular row until they back-out(rollback) or
complete the transaction (commit).  This works well within the
application.

However, the problems arose in system testing when we found some
"external" processes in Java that need to update a table (e.g. Table M)
"in" the transaction, but not the particular table locked (e.g. Table
A).  Since Table M is held by the transaction, the Java processes are
prevented from doing the updates.

So, I need to be able to "lock" a row in Table A but not release it
until the commit which could be after they access Table Z, but allow
the external Java processes to update Table M.

Is this possible?  Is there a different design that I could use?
Thanks in advance for the help!
Obnoxio The Chav - 30 Dec 2004 05:42 GMT
BigBob said:
> I need to lock a ROW in an Informix table and hold onto that lock until
> the end of a transaction.  During this transaction, 2 seperate Java
[quoted text clipped - 3 lines]
>
> Let me explain...

Try again. :o)

I really can't understand the problem -- are you using LOCK MODE (ROW) on
all these tables? What ISOLATION LEVEL are you using?

> An online application issues a "begin work" then opens a cursor with a
> select for update going after a single row in a table (e.g. Table A).
[quoted text clipped - 15 lines]
> Is this possible?  Is there a different design that I could use?
> Thanks in advance for the help!

Signature

Bye now,
Obnoxio

"C'est pas parce qu'on n'a rien ? dire qu'il faut fermer sa gueule"
 - Coluche

"I'm trying to see things your way, but I can't get my head up my a.s"
- JCH

"Ogni uomo mi guarda come se fossi una testa di cazzo"
- Marco

I went to the airport to check in and they asked what I did because I
looked like a terrorist. I said I was a comedian. They said, "Say
something funny then." I told them I had just graduated from flying
school.

 -- Ahmed Ahmed
sending to informix-list

Thomas Ronayne - 30 Dec 2004 12:36 GMT
>I need to lock a ROW in an Informix table and hold onto that lock until
>the end of a transaction.  During this transaction, 2 seperate Java
[quoted text clipped - 25 lines]
>
>  

In individual programs that will do anything to a data base, including
external Java programs,

   set isolation to committed read;
   set lock mode to wait;

Seems like that ought to do it.
scottishpoet - 30 Dec 2004 15:57 GMT
And ensure that the tables being access have row level locking.

> >I need to lock a ROW in an Informix table and hold onto that lock until
> >the end of a transaction.  During this transaction, 2 seperate Java
[quoted text clipped - 31 lines]
>
> Seems like that ought to do it.
BigBob - 30 Dec 2004 16:06 GMT
Thanks...they do have Row level.

Appreciate the input!
BigBob - 30 Dec 2004 16:01 GMT
Thanks!  Didn't think about the lock mode wait option.

Would using the Wait allow the Java process to wait until the online
application releases the lock (completes/aborts the transaction) ?
Thanks again,
scottishpoet - 30 Dec 2004 16:06 GMT
And ensure that the tables being access have row level locking.

> >I need to lock a ROW in an Informix table and hold onto that lock until
> >the end of a transaction.  During this transaction, 2 seperate Java
[quoted text clipped - 31 lines]
>
> Seems like that ought to do it.
Madison Pruet - 30 Dec 2004 15:26 GMT
> I need to lock a ROW in an Informix table and hold onto that lock until
> the end of a transaction.  During this transaction, 2 seperate Java
[quoted text clipped - 23 lines]
> Is this possible?  Is there a different design that I could use?
> Thanks in advance for the help!

Two ways ---

1) issue a dummy update on the row (i.e. set col1 = col1 where xxxx)
2) use repeatable read isolation.
Everett Mills - 30 Dec 2004 15:28 GMT
Bob-
    What you may be missing is when you declare your cursor, be sure to include "FOR UPDATE" in your SELECT statement.  That way the engine will lock all rows of your cursor as it reads them, rather than waiting until you issue the UPDATE statement.
    Or, if you're only dealing with one row, you could do something like this:

BEGIN WORK

SELECT * INTO foo_bar.* FROM my_table
WHERE whatever = whatever_else

UPDATE my_table SET * = foo_bar.*

...What ever your process is here...

UPDATE my_table SET * = foo_bar.*

IF ( SQLCA.SQLERRD[3] = 1 AND SQLCA.SQLCODE = 0 ) THEN
   COMMIT WORK
ELSE
   ROLLBACK WORK
END IF

This would force the engine to lock your row and hold it until you issue COMMIT WORK.

            --EEM

> -----Original Message-----
> From: Obnoxio The Chav [mailto:obnoxio@serendipita.com]
[quoted text clipped - 58 lines]
>   -- Ahmed Ahmed
> sending to informix-list

sending to informix-list
Savio Pinto \(s\) - 30 Dec 2004 17:24 GMT
how many rows are present in your tables?, it may be that your queries are doing a sequential scan on the table which may result in the problem that you are experiencing, you may do the following to verify

1. make sure the table is created with the row level locking
2. run the queries in dbaccess and capture the explain plan and may sure they are not doing a sequential scan on the tables
3. make sure you have "lock mode to wait <max # of seconds>" in your code
4. update the statistics for the tables
5. try using an INDEX optimizer directive in the query and see if you experience the same problem.

-----Original Message-----
From: owner-informix-list@iiug.org
[mailto:owner-informix-list@iiug.org]On Behalf Of BigBob
Sent: Wednesday, December 29, 2004 6:08 PM
To: informix-list@iiug.org
Subject: Informix locking & transactions

I need to lock a ROW in an Informix table and hold onto that lock until
the end of a transaction.  During this transaction, 2 seperate Java
processes MIGHT start and want to update a table held in that
transaction before it is released.  Is there any way to accomplish
this?

Let me explain...

An online application issues a "begin work" then opens a cursor with a
select for update going after a single row in a table (e.g. Table A).
The business requires that no one else be allowed to access 'child
tables' linked to that particular row until they back-out(rollback) or
complete the transaction (commit).  This works well within the
application.

However, the problems arose in system testing when we found some
"external" processes in Java that need to update a table (e.g. Table M)
"in" the transaction, but not the particular table locked (e.g. Table
A).  Since Table M is held by the transaction, the Java processes are
prevented from doing the updates.

So, I need to be able to "lock" a row in Table A but not release it
until the commit which could be after they access Table Z, but allow
the external Java processes to update Table M.

Is this possible?  Is there a different design that I could use?
Thanks in advance for the help!

sending to informix-list
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.