Mercurial > p > roundup > code
diff roundup/backends/back_bsddb3.py @ 891:974a4b94c5e3
Implemented the destroy() method needed by the session database...
(and possibly others). At the same time, I removed the leading
underscores from the hyperdb methods that Really Didn't Need Them.
The journal also raises IndexError now for all situations where there is a
request for the journal of a node that doesn't have one. It used to return
[] in _some_ situations, but not all. This _may_ break code, but the tests
pass...
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 19 Jul 2002 03:36:34 +0000 |
| parents | 2dd862af72ee |
| children | 32e41ddf2edb |
line wrap: on
line diff
--- a/roundup/backends/back_bsddb3.py Thu Jul 18 23:07:08 2002 +0000 +++ b/roundup/backends/back_bsddb3.py Fri Jul 19 03:36:34 2002 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb3.py,v 1.14 2002-07-14 02:05:54 richard Exp $ +#$Id: back_bsddb3.py,v 1.15 2002-07-19 03:36:34 richard Exp $ import bsddb3, os, marshal from roundup import hyperdb, date @@ -48,22 +48,22 @@ else: return bsddb3.btopen(path, 'c') - def _opendb(self, name, mode): + def opendb(self, name, mode): '''Low-level database opener that gets around anydbm/dbm eccentricities. ''' if __debug__: - print >>hyperdb.DEBUG, self, '_opendb', (self, name, mode) + print >>hyperdb.DEBUG, self, 'opendb', (self, name, mode) # determine which DB wrote the class file path = os.path.join(os.getcwd(), self.dir, name) if not os.path.exists(path): if __debug__: - print >>hyperdb.DEBUG, "_opendb bsddb3.open(%r, 'c')"%path + print >>hyperdb.DEBUG, "opendb bsddb3.open(%r, 'c')"%path return bsddb3.btopen(path, 'c') # open the database with the correct module if __debug__: - print >>hyperdb.DEBUG, "_opendb bsddb3.open(%r, %r)"%(path, mode) + print >>hyperdb.DEBUG, "opendb bsddb3.open(%r, %r)"%(path, mode) return bsddb3.btopen(path, mode) # @@ -77,10 +77,11 @@ try: db = bsddb3.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'r') - except bsddb3.NoSuchFileError: - return [] - # mor handling of bad journals - if not db.has_key(nodeid): return [] + except bsddb3._db.DBNoSuchFileError: + raise IndexError, 'no such %s %s'%(classname, nodeid) + # more handling of bad journals + if not db.has_key(nodeid): + raise IndexError, 'no such %s %s'%(classname, nodeid) journal = marshal.loads(db[nodeid]) res = [] for entry in journal: @@ -90,7 +91,19 @@ db.close() return res - def _doSaveJournal(self, classname, nodeid, action, params): + def getCachedJournalDB(self, classname): + ''' get the journal db, looking in our cache of databases for commit + ''' + # get the database handle + db_name = 'journals.%s'%classname + if self.databases.has_key(db_name): + return self.databases[db_name] + else: + db = bsddb3.btopen(os.path.join(self.dir, db_name), 'c') + self.databases[db_name] = db + return db + + def doSaveJournal(self, classname, nodeid, action, params): # serialise first if action in ('set', 'create'): params = self.serialise(classname, params) @@ -99,9 +112,9 @@ params) if __debug__: - print >>hyperdb.DEBUG, '_doSaveJournal', entry + print >>hyperdb.DEBUG, 'doSaveJournal', entry - db = bsddb3.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'c') + db = self.getCachedJournalDB(classname) if db.has_key(nodeid): s = db[nodeid] @@ -111,10 +124,12 @@ l = [entry] db[nodeid] = marshal.dumps(l) - db.close() # #$Log: not supported by cvs2svn $ +#Revision 1.14 2002/07/14 02:05:54 richard +#. all storage-specific code (ie. backend) is now implemented by the backends +# #Revision 1.13 2002/07/08 06:41:03 richard #Was reopening the database with 'n'. #
