You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Antony Paul <an...@hotmail.com> on 2003/11/03 07:36:01 UTC

Design advice needed.

Hi all,
    I need a replacement for row level locking in database. The requirement
is if two users are updating the same row of a table only the user who
updates first will be made to database second user must get a failed
message. This can be done using row level locking. But it allows only one
user to open page for editing at same time. If another user has locked the
row then second user cannot lock the same row or update it. So I want to
implement locking in Container. Is there any design patterns available for
this. Or have anyone implemented this. I am using Tomcat 4.1,Servlets JSP
and Oracle 8i. The application is using  MVC pattern but do not use Struts.

Antony Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Design advice needed.

Posted by Antony Paul <an...@hotmail.com>.
But this requires adding a column to every table.
I found two ways of doing this.
1.  Using time stamp. It requires adding a column to table.
2. Checking data for equality before updating. It requires querying database
again.
Any alternative way.

thanks for the replies

Antony Paul

----- Original Message -----
From: "Jean-Louis" <cl...@hager.fr>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, November 03, 2003 3:13 PM
Subject: Re: Design advice needed.


> Hi,
>
> you can use a timestamp and write for example :
> update ...
> where ...
> and timestamp = 'the timestamp read by the select statement and saved in
your application'
>
> And then check the number of rows updated.
>
> Antony Paul a écrit :
>
> > Can u pls mention what is that Oracle feature ?. Reading the data again
is
> > time consuming.
> > ----- Original Message -----
> > From: "Johan Kok" <jk...@messianic.dyndns.org>
> > To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> > Sent: Monday, November 03, 2003 12:17 PM
> > Subject: RE: Design advice needed.
> >
> > > Anthony,
> > >
> > > Did you consider reading the record without locks, and when an updated
are
> > > made, to take a write-lock, check that the original record are still
the
> > > same and then apply, otherwise fail.
> > >
> > > Your intentions might not work unless all writes are passed through
the
> > > container, as Oracle will not have any control, until a write occurs,
i.e.
> > > you will have to open with read only, and only take out a lock when
you
> > are
> > > going to write, as described above. for safety sake your container
will
> > have
> > > to re-read the data in any case, before commiting, otherwise it may
update
> > > changed data, e.g. updates that are made through other processes or
even
> > > triggers.
> > >
> > > If my memory serves me right, that is something you can do easily with
> > > Oracle (i.e. there's a standard feature implemented), even with Oracle
> > 6/7.
>
> Jean-Louis CLAUSS
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Design advice needed.

Posted by Jean-Louis <cl...@hager.fr>.
Hi,

you can use a timestamp and write for example :
update ...
where ...
and timestamp = 'the timestamp read by the select statement and saved in your application'

And then check the number of rows updated.

Antony Paul a écrit :

> Can u pls mention what is that Oracle feature ?. Reading the data again is
> time consuming.
> ----- Original Message -----
> From: "Johan Kok" <jk...@messianic.dyndns.org>
> To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> Sent: Monday, November 03, 2003 12:17 PM
> Subject: RE: Design advice needed.
>
> > Anthony,
> >
> > Did you consider reading the record without locks, and when an updated are
> > made, to take a write-lock, check that the original record are still the
> > same and then apply, otherwise fail.
> >
> > Your intentions might not work unless all writes are passed through the
> > container, as Oracle will not have any control, until a write occurs, i.e.
> > you will have to open with read only, and only take out a lock when you
> are
> > going to write, as described above. for safety sake your container will
> have
> > to re-read the data in any case, before commiting, otherwise it may update
> > changed data, e.g. updates that are made through other processes or even
> > triggers.
> >
> > If my memory serves me right, that is something you can do easily with
> > Oracle (i.e. there's a standard feature implemented), even with Oracle
> 6/7.

Jean-Louis CLAUSS



Re: Design advice needed.

Posted by Antony Paul <an...@hotmail.com>.
It is not a scenario of threading at all. I found a document related to this
at
http://theserverside.com/patterns/thread.jsp?thread_id=6894
----- Original Message -----
From: <ac...@saysit.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, November 03, 2003 1:18 PM
Subject: Re: Design advice needed.


> Ummm, didn't want to butt in, but why r u multi-threading a read, then
> write to Oracle?
> Without using roll locking, wouldn't it be the right thing to do using
> synchronized thread e.g. like this
> import java.io.*;
> public class ModifyAccountBalance
> {
>   DespositThread Deposit1, Deposit2;
>   Deposit1 = new DepositThread(account, 1234);
>   Deposit2 = new DepositThread(account, 4321);
>   // strut yourstuff here
> }
> synchronized void Deposit (int depositAmt, String accountName)
> {
>   // codes for updating the account balance
> }
> class DepositThread extends Thread
> {
>   // more codes
>    DepositThread
> (...)
>    { // you might like to set the amounts etc here
>    }
>    public void run()
>    {
>      account.Deposit(depositAmt, accountName);
>    }
> }
>
> John Zukowski's books explain that in detail.
> Using synchronization, the first deposit will write and update Oracle
> before the second deposit kicks in.
> What I would like to know is if I have multile JVMs, would this model
> hold true ?????? It should since TC starts up one instance and
> multi-thread it, but we have programmatically forced it to be singled
> threaded.
> Like to hear back n this one.
>
> Johan Kok wrote:
> >
> > Wish I could, it's been eight years since I was did any DBA/DB
development
> > work. Either go to the manual, or contact a oracle list.
> >
> > > -----Original Message-----
> > > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > > Sent: 03 November 2003 09:10
> > > To: Tomcat Users List; jkok@messianic.dyndns.org
> > > Subject: Re: Design advice needed.
> > >
> > >
> > > Can u pls mention what is that Oracle feature ?. Reading the
> > > data again is
> > > time consuming.
> > > ----- Original Message -----
> > > From: "Johan Kok" <jk...@messianic.dyndns.org>
> > > To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> > > Sent: Monday, November 03, 2003 12:17 PM
> > > Subject: RE: Design advice needed.
> > >
> > >
> > > > Anthony,
> > > >
> > > > Did you consider reading the record without locks, and when
> > > an updated are
> > > > made, to take a write-lock, check that the original record
> > > are still the
> > > > same and then apply, otherwise fail.
> > > >
> > > > Your intentions might not work unless all writes are passed
> > > through the
> > > > container, as Oracle will not have any control, until a
> > > write occurs, i.e.
> > > > you will have to open with read only, and only take out a
> > > lock when you
> > > are
> > > > going to write, as described above. for safety sake your
> > > container will
> > > have
> > > > to re-read the data in any case, before commiting,
> > > otherwise it may update
> > > > changed data, e.g. updates that are made through other
> > > processes or even
> > > > triggers.
> > > >
> > > > If my memory serves me right, that is something you can do
> > > easily with
> > > > Oracle (i.e. there's a standard feature implemented), even
> > > with Oracle
> > > 6/7.
> > > >
> > > >
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > > > > Sent: 03 November 2003 08:36
> > > > > To: Tomcat Users List
> > > > > Subject: Design advice needed.
> > > > >
> > > > >
> > > > > Hi all,
> > > > >     I need a replacement for row level locking in database.
> > > > > The requirement
> > > > > is if two users are updating the same row of a table only
> > > the user who
> > > > > updates first will be made to database second user must
> > > get a failed
> > > > > message. This can be done using row level locking. But it
> > > > > allows only one
> > > > > user to open page for editing at same time. If another user
> > > > > has locked the
> > > > > row then second user cannot lock the same row or update it.
> > > > > So I want to
> > > > > implement locking in Container. Is there any design patterns
> > > > > available for
> > > > > this. Or have anyone implemented this. I am using Tomcat
> > > > > 4.1,Servlets JSP
> > > > > and Oracle 8i. The application is using  MVC pattern but do
> > > > > not use Struts.
> > > > >
> > > > > Antony Paul
> > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> > > tomcat-user-help@jakarta.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Design advice needed.

Posted by ac...@saysit.com.
Ummm, didn't want to butt in, but why r u multi-threading a read, then
write to Oracle?
Without using roll locking, wouldn't it be the right thing to do using
synchronized thread e.g. like this
import java.io.*;
public class ModifyAccountBalance
{
  DespositThread Deposit1, Deposit2;
  Deposit1 = new DepositThread(account, 1234);
  Deposit2 = new DepositThread(account, 4321);
  // strut yourstuff here
}
synchronized void Deposit (int depositAmt, String accountName)
{
  // codes for updating the account balance
}
class DepositThread extends Thread
{
  // more codes
   DepositThread
(...)
   { // you might like to set the amounts etc here
   }
   public void run()
   {
     account.Deposit(depositAmt, accountName);
   }
}

John Zukowski's books explain that in detail. 
Using synchronization, the first deposit will write and update Oracle
before the second deposit kicks in.
What I would like to know is if I have multile JVMs, would this model
hold true ?????? It should since TC starts up one instance and
multi-thread it, but we have programmatically forced it to be singled
threaded.
Like to hear back n this one.

Johan Kok wrote:
> 
> Wish I could, it's been eight years since I was did any DBA/DB development
> work. Either go to the manual, or contact a oracle list.
> 
> > -----Original Message-----
> > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > Sent: 03 November 2003 09:10
> > To: Tomcat Users List; jkok@messianic.dyndns.org
> > Subject: Re: Design advice needed.
> >
> >
> > Can u pls mention what is that Oracle feature ?. Reading the
> > data again is
> > time consuming.
> > ----- Original Message -----
> > From: "Johan Kok" <jk...@messianic.dyndns.org>
> > To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> > Sent: Monday, November 03, 2003 12:17 PM
> > Subject: RE: Design advice needed.
> >
> >
> > > Anthony,
> > >
> > > Did you consider reading the record without locks, and when
> > an updated are
> > > made, to take a write-lock, check that the original record
> > are still the
> > > same and then apply, otherwise fail.
> > >
> > > Your intentions might not work unless all writes are passed
> > through the
> > > container, as Oracle will not have any control, until a
> > write occurs, i.e.
> > > you will have to open with read only, and only take out a
> > lock when you
> > are
> > > going to write, as described above. for safety sake your
> > container will
> > have
> > > to re-read the data in any case, before commiting,
> > otherwise it may update
> > > changed data, e.g. updates that are made through other
> > processes or even
> > > triggers.
> > >
> > > If my memory serves me right, that is something you can do
> > easily with
> > > Oracle (i.e. there's a standard feature implemented), even
> > with Oracle
> > 6/7.
> > >
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > > > Sent: 03 November 2003 08:36
> > > > To: Tomcat Users List
> > > > Subject: Design advice needed.
> > > >
> > > >
> > > > Hi all,
> > > >     I need a replacement for row level locking in database.
> > > > The requirement
> > > > is if two users are updating the same row of a table only
> > the user who
> > > > updates first will be made to database second user must
> > get a failed
> > > > message. This can be done using row level locking. But it
> > > > allows only one
> > > > user to open page for editing at same time. If another user
> > > > has locked the
> > > > row then second user cannot lock the same row or update it.
> > > > So I want to
> > > > implement locking in Container. Is there any design patterns
> > > > available for
> > > > this. Or have anyone implemented this. I am using Tomcat
> > > > 4.1,Servlets JSP
> > > > and Oracle 8i. The application is using  MVC pattern but do
> > > > not use Struts.
> > > >
> > > > Antony Paul
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > tomcat-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

RE: Design advice needed.

Posted by Johan Kok <jk...@messianic.dyndns.org>.
Wish I could, it's been eight years since I was did any DBA/DB development
work. Either go to the manual, or contact a oracle list.

> -----Original Message-----
> From: Antony Paul [mailto:antonypaul24@hotmail.com]
> Sent: 03 November 2003 09:10
> To: Tomcat Users List; jkok@messianic.dyndns.org
> Subject: Re: Design advice needed.
>
>
> Can u pls mention what is that Oracle feature ?. Reading the
> data again is
> time consuming.
> ----- Original Message -----
> From: "Johan Kok" <jk...@messianic.dyndns.org>
> To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> Sent: Monday, November 03, 2003 12:17 PM
> Subject: RE: Design advice needed.
>
>
> > Anthony,
> >
> > Did you consider reading the record without locks, and when
> an updated are
> > made, to take a write-lock, check that the original record
> are still the
> > same and then apply, otherwise fail.
> >
> > Your intentions might not work unless all writes are passed
> through the
> > container, as Oracle will not have any control, until a
> write occurs, i.e.
> > you will have to open with read only, and only take out a
> lock when you
> are
> > going to write, as described above. for safety sake your
> container will
> have
> > to re-read the data in any case, before commiting,
> otherwise it may update
> > changed data, e.g. updates that are made through other
> processes or even
> > triggers.
> >
> > If my memory serves me right, that is something you can do
> easily with
> > Oracle (i.e. there's a standard feature implemented), even
> with Oracle
> 6/7.
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > > Sent: 03 November 2003 08:36
> > > To: Tomcat Users List
> > > Subject: Design advice needed.
> > >
> > >
> > > Hi all,
> > >     I need a replacement for row level locking in database.
> > > The requirement
> > > is if two users are updating the same row of a table only
> the user who
> > > updates first will be made to database second user must
> get a failed
> > > message. This can be done using row level locking. But it
> > > allows only one
> > > user to open page for editing at same time. If another user
> > > has locked the
> > > row then second user cannot lock the same row or update it.
> > > So I want to
> > > implement locking in Container. Is there any design patterns
> > > available for
> > > this. Or have anyone implemented this. I am using Tomcat
> > > 4.1,Servlets JSP
> > > and Oracle 8i. The application is using  MVC pattern but do
> > > not use Struts.
> > >
> > > Antony Paul
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Design advice needed.

Posted by Antony Paul <an...@hotmail.com>.
Can u pls mention what is that Oracle feature ?. Reading the data again is
time consuming.
----- Original Message -----
From: "Johan Kok" <jk...@messianic.dyndns.org>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Monday, November 03, 2003 12:17 PM
Subject: RE: Design advice needed.


> Anthony,
>
> Did you consider reading the record without locks, and when an updated are
> made, to take a write-lock, check that the original record are still the
> same and then apply, otherwise fail.
>
> Your intentions might not work unless all writes are passed through the
> container, as Oracle will not have any control, until a write occurs, i.e.
> you will have to open with read only, and only take out a lock when you
are
> going to write, as described above. for safety sake your container will
have
> to re-read the data in any case, before commiting, otherwise it may update
> changed data, e.g. updates that are made through other processes or even
> triggers.
>
> If my memory serves me right, that is something you can do easily with
> Oracle (i.e. there's a standard feature implemented), even with Oracle
6/7.
>
>
>
>
> > -----Original Message-----
> > From: Antony Paul [mailto:antonypaul24@hotmail.com]
> > Sent: 03 November 2003 08:36
> > To: Tomcat Users List
> > Subject: Design advice needed.
> >
> >
> > Hi all,
> >     I need a replacement for row level locking in database.
> > The requirement
> > is if two users are updating the same row of a table only the user who
> > updates first will be made to database second user must get a failed
> > message. This can be done using row level locking. But it
> > allows only one
> > user to open page for editing at same time. If another user
> > has locked the
> > row then second user cannot lock the same row or update it.
> > So I want to
> > implement locking in Container. Is there any design patterns
> > available for
> > this. Or have anyone implemented this. I am using Tomcat
> > 4.1,Servlets JSP
> > and Oracle 8i. The application is using  MVC pattern but do
> > not use Struts.
> >
> > Antony Paul
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Design advice needed.

Posted by Johan Kok <jk...@messianic.dyndns.org>.
Anthony,

Did you consider reading the record without locks, and when an updated are
made, to take a write-lock, check that the original record are still the
same and then apply, otherwise fail.

Your intentions might not work unless all writes are passed through the
container, as Oracle will not have any control, until a write occurs, i.e.
you will have to open with read only, and only take out a lock when you are
going to write, as described above. for safety sake your container will have
to re-read the data in any case, before commiting, otherwise it may update
changed data, e.g. updates that are made through other processes or even
triggers.

If my memory serves me right, that is something you can do easily with
Oracle (i.e. there's a standard feature implemented), even with Oracle 6/7.




> -----Original Message-----
> From: Antony Paul [mailto:antonypaul24@hotmail.com]
> Sent: 03 November 2003 08:36
> To: Tomcat Users List
> Subject: Design advice needed.
>
>
> Hi all,
>     I need a replacement for row level locking in database.
> The requirement
> is if two users are updating the same row of a table only the user who
> updates first will be made to database second user must get a failed
> message. This can be done using row level locking. But it
> allows only one
> user to open page for editing at same time. If another user
> has locked the
> row then second user cannot lock the same row or update it.
> So I want to
> implement locking in Container. Is there any design patterns
> available for
> this. Or have anyone implemented this. I am using Tomcat
> 4.1,Servlets JSP
> and Oracle 8i. The application is using  MVC pattern but do
> not use Struts.
>
> Antony Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org