Re: psycopg2 vs psycopg1: the _v_database_connection problem in Zope 2

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <[email protected]>
Il giorno mer, 24/09/2008 alle 11.33 +0200, Marco Bizzarri ha scritto:
> On Wed, Sep 24, 2008 at 10:14 AM, Federico Di Gregorio <fog-NGVKUo/i/[email protected]> wrote:
> 
> >> But I do not understand what you're meaning about the persistent
> >> attribute. Can you explain it?
> >
> > An attribute that does not start with _v_.
> >
> > federico
> 
> Ehm... I know what a persisten attribute is ;)
> 
> The question was more in how you wanted to use it.

Let suppose that when you ask the pool for a connection the pool keeps
the connection in a hash table indexed by a serial number and you get

	(serial, conn)

then assign

	self.conn_serial = serial
	self._v_connection = conn

Then, before trying to use the connection you do:

	if not hasattr(self, "_v_connection") or not self._v_connection:
		self._v_connection = pool.getconn(self.conn_serial)

and you get exactly the living connection you had before. This way even
if the object is frozen and lose its _v_ attributes you have a way to
get back a living connection. Then, after the commit/rollback you do:

	pool.putconn(serial)

to "put back" the connection and make it available to other threads from
the pool.

federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
 Questa lista non pretende di essere il riferimento torinese per il
  software libero o altre cazzate del genere.       -- Silvano, su torte

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkjaG4AACgkQvcCgrgZGjetTjwCfVdwriRv9dWM+Jk+nxIyXUNPI
Nc4AnRtwOtLiu6576p9RVFaJpRn+IkYc
=4kym
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.