Pool based connections can be tricky as well:

  When a DA instance is accessed several times during the
  same request, it *MUST* use the same connection.
To be able to finish whole transaction
for the relational DB...

I know that the "ZPsycopgDA" which comes with "psycopg 1.x" uses
"_v_" variables. I do not know whether that of "psycopg 2.x"
uses a connection pool and uses it in the correct way.
Unfortuantelly it still uses _v_database_connection... I've just found

I only know that the correct connection pool use is tricky...

The problem is to be able to determine which connection from
pool is being used during request (transaction). I think it is
possible to use request object or maybe the
Transaction object for this.

In _begin function (possibly) of TM I may define something like:

tr = transaction.get()
if hasattr(tr, 'id_of_con_from_pool_used'):
   # returns specific connection that is already marked
   # as 'taken' from the pool
   conn = pool.getConn(tr.id_of_con_from_pool_used')
   # returns free connection from the pool and marks
   # it as 'taken'
   conn = pool.getConn()
   setattr(tr, 'id_of_con_from_pool_used', conn.identifier)

and in _finish (abort etc.) method of TM remove additional attribute
and release connection to pool. It should give me the ability to
use same connection during transaction and because it is
'taken', it won't be used by any other threads.

The question is whether it is possible to use tranasction.get() for this?
Isn't Transaction something persistent? Or maybe its better to
use request object instead (sounds a bit ugly but why not?)?

Seems to be too simple so I've possibly missed something :)
Any ideas?

Maciej Wisniowski _______________________________________________
Zope-DB mailing list

Reply via email to