[Zope-DB] Zope database connectivity
Dieter Maurer
dieter at handshake.de
Sun Sep 24 13:48:39 EDT 2006
Maciej Wisniowski wrote at 2006-9-23 00:27 +0200:
> > You could recode DA's to close the connection at the end of every
> > transaction and reopen them on demand,
>Seems for me that difference betwen "connect on load"
>and "connect on demand" is in _begin, _finish and
>__init__ methods of TransactionManager (usually defined in db.py
>in specific database adapter).
The bad behaviour is in standard Zope code:
Shared.DC.ZRDB.Connection.Connection.__setstate__
It connects to the database as soon as the instance is loaded from
ZODB. My modified code looks like:
def __setstate__(self, state):
Globals.Persistent.__setstate__(self, state)
if self.connection_string:
# DM 2005-06-24: what a stupidity to connect on load!
# It should be delayed until the connections is really used.
# I do not change this here to not break DAs.
# DM 2005-06-24: "connect_" in order to protect '_v_' attributes
#try: self.connect(self.connection_string)
try: self.connect_(self.connection_string)
except:
LOG('Shared.DC.ZRDB.Connection',
ERROR,
'Error connecting to relational database.',
error=exc_info())
--
Dieter
More information about the Zope-DB
mailing list