Package Products :: Package ZenUtils :: Module ZeoConn |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenUtils.ZeoConn

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  from zope.component import getUtility
    12  from Products.ZenUtils.Utils import set_context
    13  from Products.ZenUtils.ZodbFactory import IZodbFactoryLookup
    14
    15 -class ZeoConn(object):
    16
    17 -    def __init__(self, **kwargs):
    18          connectionFactory = getUtility(IZodbFactoryLookup).get()
    19          self.db, self.storage = connectionFactory.getConnection(**kwargs)
    20
    21          self.app = None
    22          self.dmd = None
    23          self.opendb()
    24
    25
    26 -    def opendb(self):
    27          if self.app: return
    28          self.connection=self.db.open()
    29          root=self.connection.root()
    30          app = root['Application']
    31          self.app = set_context(app)
    32          self.dmd = self.app.zport.dmd
    33
    34
    35 -    def syncdb(self):
    36          self.connection.sync()
    37
    38
    39 -    def closedb(self):
    40          self.connection.close()
    41          self.db.close()
    42          self.app = None
    43          self.dmd = None
    44