def __init__(self, **kwargs):
        GenericDBInterface.__init__(self)
        
        self.dir = settings['store']['bdb_data_dir']
        
        # add trailing '/'
        if self.dir[-1] != '/':
            self.dir += '/'

        try:
            self.trans_max_retries = int(settings['store']['trans_max_retries'])
        except KeyError:
            # trans max retries default setting is 12
            self.trans_max_retries = 12

        try:
            self.checkpoint_interval = int(settings['store']['checkpoint_interval'])
        except KeyError:
            # default checkpoint interval set to 1 minute
            self.checkpoint_interval = 1

        additional_flags = kwargs.get('flags', 0)

        # create db environment
        self._env = db.DBEnv()
        self._env.open(
            self.dir,
            db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
            db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_CREATE  | additional_flags
        )

        self._env.set_flags(db.DB_AUTO_COMMIT, 1)

        dbMode = 0660
        # open items db
        self._itemdb = db.DB(self._env)
        self._itemdb.open(
            'porcupine.db',
            'items',
            dbtype=db.DB_HASH,
            mode=dbMode,
            flags=db.DB_THREAD | db.DB_CREATE
        )
        # open documents db
        self._docdb = db.DB(self._env)
        self._docdb.open(
            'porcupine.db',
            'docs',
            dbtype=db.DB_HASH,
            mode=dbMode,
            flags=db.DB_THREAD | db.DB_CREATE
        )
        self.running = True
        self.mt = Thread(target=self.maintain, \
                         name='Berkeley DB maintenance thread')
        self.mt.start()
    def __init__(self):
        GenericDBInterface.__init__(self)
        
        from porcupine.config import dbparams
        
        try:
            self.dir = dbparams.params['bdb_data_dir']
        except KeyError:
            raise serverExceptions.ConfigurationError, (('bdb_data_dir', \
                    'storeparameters'),)
        
        # add trailing '/'
        if self.dir[-1] != '/':
            self.dir += '/'

        try:
            self.trans_max_retries = int(dbparams.params['trans_max_retries'])
        except KeyError:
            # trans max retries default setting is 12
            trans_max_retries = 12
        except ValueError:
            raise serverExceptions.ConfigurationError, \
                'Invalid trans_max_retries setting: %s' % \
                dbparams.params[trans_max_retries]

        try:
            self.checkpoint_interval = int(dbparams.params['checkpoint_interval'])
        except KeyError:
            # default checkpoint interval set to 1 minute
            self.checkpoint_interval = 1
        except ValueError:
            raise serverExceptions.ConfigurationError, \
                'Invalid checkpoint_interval setting: %s' % \
                dbparams.params[checkpoint_interval]

        # create db environment
        self._env = db.DBEnv()
        self._env.open(
            self.dir,
            db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
            db.DB_INIT_LOG | db.DB_INIT_TXN | db.DB_CREATE  | db.DB_RECOVER
        )

        self._env.set_flags(db.DB_AUTO_COMMIT, 1)

        dbMode = 0660
        # open items db
        self._itemdb = db.DB(self._env)
        self._itemdb.open(
            'porcupine.db',
            'items',
            dbtype=db.DB_HASH,
            mode=dbMode,
            flags=db.DB_THREAD | db.DB_CREATE
        )
        # open documents db
        self._docdb = db.DB(self._env)
        self._docdb.open(
            'porcupine.db',
            'docs',
            dbtype=db.DB_HASH,
            mode=dbMode,
            flags=db.DB_THREAD | db.DB_CREATE
        )
        self.running = True
        self.mt = Thread(target=self.maintain, \
                         name='Berkeley DB maintenance thread')
        self.mt.start()