[Zope-dev] API for creating sub-ZODBs

Jim Fulton jim@digicool.com
Wed, 20 Oct 1999 00:13:03 +0000


"Andrew M. Kuchling" wrote:
> 
> Recently people were commenting on the recent session tracking HOWTO,
> which stores sessions in files inside a directory.  This would be made
> much easier if there was some API for creating a single connection to
> a new ZODB; your code would have to retrieve the relevant root object,
> but you could at least count on it being cleaned up nicely when the
> server is shut down.  Another application for this is my ODP code,
> which is an amount of data so large that you probably don't want to
> mix it in with the rest of your database.  If we have a powerful
> object persistency system in the form of the ZODB, why not use it?
> 
> In the ODP code release, I have an external method which looks like
> this:
> 
> from ZODB import FileStorage, DB
> 
> # Cache of ZODB objects
> ZODBs = {}
> 
> def get_odp(filename):
>     if ZODBs.has_key( filename ):
>         db = ZODBs[filename]
>     else:
>         # Open ZODB
>         fs = FileStorage.FileStorage(filename, read_only = 1)
>         db = DB( fs )
>         ZODBs[ filename ] = db
> 
>     conn = db.open()
>     root = conn.root()
>     return root['ODP']
> 
> This may well be leaking connections; I'm not sure. 

It is.  After your through with the object, you should
close the connection.

Also, ExternalMethod files are not really modules
and are not good places to put things like your ZODB 
cache.

> Why not add some
> function to the Zope API which does this job? 

Which job? What part do you want to automate?


> You would provide it
> with a Storage class (so you can use a non-versioning storage for
> transient sessions) and an argument tuple for the Storage class; if
> the Storage had been previously opened, it's returned from a cache.
> Invocation would be something like:
> 
> conn = Zope.App.openExtraZODB( FileStorage, ('/tmp/mystorage.fs',) )
> root = conn.root()
> ... whatever ...

What do you intend to do with the objects you get this way?
 
Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.