[Zope3-dev] RE: zope.app.rdb bug?
David Johnson
djohnson at jsatech.com
Mon Apr 17 11:12:12 EDT 2006
Good. I think I'm clear. That procedure is exactly what I am following,
except I don't cache queries for this application. My database connection
is a persistent utility. I'll give the global utility a try.
> -----Original Message-----
> From: Jeff Rush [mailto:jeff at taupro.com]
> Sent: Monday, April 17, 2006 9:27 AM
> To: David Johnson
> Cc: zope3-dev at zope.org
> Subject: Re: zope.app.rdb bug?
>
> David Johnson wrote:
> >>
> > In regards to persistence, are we saying this problem occurs when the
> > connection is an attribute of a persistent object? In our case the
> > connection resides in a persistent object but is called and used in a
> > non-persistent one.
>
> It doesn't matter if the 'caller' of the connection is persistent or not,
> but
> that the connector is itself a persistent, local utility stored in the
> site
> manager folder.
>
> > Specifically, we're using the connection in a
> > non-persistent shopping cart object. Upon initialization the cart
> object
> > retrieves the connection from a persistent parent in the context in
> which
> > the cart is initialized. In this way, different shopping cart items can
> be
> > stored in different databases depending upon the container. The parent
> is
> > essentially a copy of ISQLScript.
>
> I copied SQLScript as well. Be sure that on each SQL operation you re-
> fetch
> the connection object using the connection name. Do not hold on to the
> connection object itself, as it may change during system re-configuration.
>
> Here is my calling method:
>
> def invoke_SQL(self, query):
>
> cache = getCacheForObject(self)
> location = getLocationForCache(self)
> if cache and location:
> _marker = object()
> result = cache.query(location, {'query': query},
> default=_marker)
> if result is not _marker:
> return result
>
> try:
> connection = zapi.getUtility(IZopeDatabaseAdapter,
> self.connection_name)()
> except KeyError:
> raise AttributeError, (
> "The database connection '%s' cannot be found." % (
> self.connection_name))
>
> result = queryForResults(connection, query)
> if cache and location:
> cache.set(result, location, {'query': query})
> return result
>
> Notice the zapi.getUtility() call to re-fetch each time.
>
> -Jeff
More information about the Zope3-dev
mailing list