1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- #$Id: back_bsddb3.py,v 1.18 2002-10-03 06:56:29 richard Exp $
18+ #$Id: back_bsddb3.py,v 1.19 2003-05-09 01:47:50 richard Exp $
1919'''
2020This module defines a backend that saves the hyperdatabase in BSDDB3.
2121'''
@@ -74,7 +74,31 @@ def opendb(self, name, mode):
7474 #
7575 def getjournal (self , classname , nodeid ):
7676 ''' get the journal for id
77+
78+ Raise IndexError if the node doesn't exist (as per history()'s
79+ API)
7780 '''
81+ if __debug__ :
82+ print >> hyperdb .DEBUG , 'getjournal' , (self , classname , nodeid )
83+
84+ # our journal result
85+ res = []
86+
87+ # add any journal entries for transactions not committed to the
88+ # database
89+ for method , args in self .transactions :
90+ if method != self .doSaveJournal :
91+ continue
92+ (cache_classname , cache_nodeid , cache_action , cache_params ,
93+ cache_creator , cache_creation ) = args
94+ if cache_classname == classname and cache_nodeid == nodeid :
95+ if not cache_creator :
96+ cache_creator = self .curuserid
97+ if not cache_creation :
98+ cache_creation = date .Date ()
99+ res .append ((cache_nodeid , cache_creation , cache_creator ,
100+ cache_action , cache_params ))
101+
78102 # attempt to open the journal - in some rare cases, the journal may
79103 # not exist
80104 try :
@@ -84,14 +108,17 @@ def getjournal(self, classname, nodeid):
84108 raise IndexError , 'no such %s %s' % (classname , nodeid )
85109 # more handling of bad journals
86110 if not db .has_key (nodeid ):
111+ db .close ()
112+ if res :
113+ # we have some unsaved journal entries, be happy!
114+ return res
87115 raise IndexError , 'no such %s %s' % (classname , nodeid )
88116 journal = marshal .loads (db [nodeid ])
89- res = []
90- for entry in journal :
91- (nodeid , date_stamp , user , action , params ) = entry
92- date_obj = date .Date (date_stamp )
93- res .append ((nodeid , date_obj , user , action , params ))
94117 db .close ()
118+
119+ # add all the saved journal entries for this node
120+ for nodeid , date_stamp , user , action , params in journal :
121+ res .append ((nodeid , date .Date (date_stamp ), user , action , params ))
95122 return res
96123
97124 def getCachedJournalDB (self , classname ):
0 commit comments