[Zope] Concurrency/Atomicity in ZSQL/ZOracleDA ?

Casey Duncan casey@zope.com
Thu, 21 Mar 2002 10:31:37 -0700


Renaud Gu=E9rin wrote:
>=20
> The DB is Oracle8 with ZOracleDA.
>=20
> The trouble is, I need to generate this id in the first place, and =
as I said I'd
> rather not use a sequence. Thus the max(id)+1

I would not do this. It makes life more complicated. Why not use a=
=20
sequence? Then you are guaranteed atomicy. I am no Oracle expert, but=
=20
other database I have used let you retreive the next number in the=
=20
sequence (before the row has been added) while simultaneously locking=
=20
the table against other inserts for the duration of the transaction.

>=20
> thanks.
> But what I want to make sure is that a transaction implies atomic o=
peration, ie
> nobody else can perform another select max(id)+1 before the select =
of the first
> caller is performed.
> Is that OK with my current setup ?

No, if you must do this then you will need to explicitly lock the tab=
le=20
against inserts *before* you look up the next id (you can use the loc=
k=20
SQL statement for this). Then if another thread does the same operati=
on=20
concurrently, one will block the other and they will be executed=20
serially instead of in parallel.

good luck!

-Casey