[ZODB-Dev] Sample applications?

Patrick K. O'Brien pobrien@orbtech.com
Tue, 9 Oct 2001 08:33:35 -0500


It really isn't as complex as I made it sound. I still have a string in root
that points to an instance of FolderManager, instead of an instance of
IOBTree. FolderManager gives me a place to encapsulate functionality that I
think the container should have. So my folder module looks like this:

from alpha import AlphaPersistent
from BTrees import IOBTree
import transaction

class Folder(AlphaPersistent):
    """Folder class."""

    def __init__(self, name=''):
        """Create a Folder instance."""
        self.name = name


class FolderManager(AlphaPersistent):
    """FolderManager class."""

    def __init__(self):
        """Create a FolderManager instance."""
        self.folders = IOBTree.IOBTree()

    def new(self, name='New Folder'):
        """Return a new Folder instance."""
        f = Folder(name)
        success = 0
        while not success:
            if self.folders:
                success = self.folders.insert(self.folders.maxKey()+1, f)
            else:
                success = self.folders.insert(0, f)
        transaction.commit(1)
        return f

And I stick a FolderManager instance in the root like this:

        from ZODBrowser.folder import FolderManager
        self.folderManager = self.branch('FolderManager', FolderManager())

Which use this method of another class (my DatabaseManager class):

    def branch(self, key, branch=None):
        """Return the branch assigned to key.
        If necessary, creates a new branch for key."""
        if branch is not None and not self.root.has_key(key):
            self.root[key] = branch
        return self.root[key]

---
Patrick K. O'Brien
Orbtech (http://www.orbtech.com)
"I am, therefore I think."

-----Original Message-----
From: zodb-dev-admin@zope.org [mailto:zodb-dev-admin@zope.org]On Behalf Of
Christian Robottom Reis
Sent: Tuesday, October 09, 2001 12:34 AM
To: Patrick K. O'Brien
Cc: ZODB
Subject: RE: [ZODB-Dev] Sample applications?


> FolderManager is a class that has a property that is an IOBTree where new
> folders are stored.

Well, I find that a bit complex. I just have a string that indexes the
root object that identifies a Catalog - "SalesCatalog", for instance.
Avoids the exec/compile. If that's a common solution, I know not, but it
WFM(tm).