1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- #$Id: back_anydbm.py,v 1.44 2002-07-14 02:05:53 richard Exp $
18+ #$Id: back_anydbm.py,v 1.45 2002-07-14 04:03:14 richard Exp $
1919'''
2020This module defines a backend that saves the hyperdatabase in a database
2121chosen by anydbm. It is guaranteed to always be available in python
@@ -589,16 +589,24 @@ def __init__(self, db, classname, **properties):
589589 self .db = weakref .proxy (db ) # use a weak ref to avoid circularity
590590 self .key = ''
591591
592+ # should we journal changes (default yes)
593+ self .do_journal = 1
594+
592595 # do the db-related init stuff
593596 db .addclass (self )
594597
595598 self .auditors = {'create' : [], 'set' : [], 'retire' : []}
596599 self .reactors = {'create' : [], 'set' : [], 'retire' : []}
597600
598- def __repr__ (self ):
599- '''Slightly more useful representation
601+ def enableJournalling (self ):
602+ '''Turn journalling on for this class
600603 '''
601- return '<hypderdb.Class "%s">' % self .classname
604+ self .do_journal = 1
605+
606+ def disableJournalling (self ):
607+ '''Turn journalling off for this class
608+ '''
609+ self .do_journal = 0
602610
603611 # Editing nodes:
604612
@@ -672,7 +680,7 @@ def create(self, **propvalues):
672680 propvalues [key ] = value
673681
674682 # register the link with the newly linked node
675- if self .properties [key ].do_journal :
683+ if self .do_journal and self . properties [key ].do_journal :
676684 self .db .addjournal (link_class , value , 'link' ,
677685 (self .classname , newid , key ))
678686
@@ -703,7 +711,7 @@ def create(self, **propvalues):
703711 if not self .db .hasnode (link_class , id ):
704712 raise IndexError , '%s has no node %s' % (link_class , id )
705713 # register the link with the newly linked node
706- if self .properties [key ].do_journal :
714+ if self .do_journal and self . properties [key ].do_journal :
707715 self .db .addjournal (link_class , id , 'link' ,
708716 (self .classname , newid , key ))
709717
@@ -737,7 +745,8 @@ def create(self, **propvalues):
737745
738746 # done
739747 self .db .addnode (self .classname , newid , propvalues )
740- self .db .addjournal (self .classname , newid , 'create' , propvalues )
748+ if self .do_journal :
749+ self .db .addjournal (self .classname , newid , 'create' , propvalues )
741750
742751 self .fireReactors ('create' , newid , None )
743752
@@ -762,20 +771,26 @@ def get(self, nodeid, propname, default=_marker, cache=1):
762771 return nodeid
763772
764773 if propname == 'creation' :
774+ if not self .do_journal :
775+ raise ValueError , 'Journalling is disabled for this class'
765776 journal = self .db .getjournal (self .classname , nodeid )
766777 if journal :
767778 return self .db .getjournal (self .classname , nodeid )[0 ][1 ]
768779 else :
769780 # on the strange chance that there's no journal
770781 return date .Date ()
771782 if propname == 'activity' :
783+ if not self .do_journal :
784+ raise ValueError , 'Journalling is disabled for this class'
772785 journal = self .db .getjournal (self .classname , nodeid )
773786 if journal :
774787 return self .db .getjournal (self .classname , nodeid )[- 1 ][1 ]
775788 else :
776789 # on the strange chance that there's no journal
777790 return date .Date ()
778791 if propname == 'creator' :
792+ if not self .do_journal :
793+ raise ValueError , 'Journalling is disabled for this class'
779794 journal = self .db .getjournal (self .classname , nodeid )
780795 if journal :
781796 name = self .db .getjournal (self .classname , nodeid )[0 ][2 ]
@@ -901,7 +916,7 @@ class or a KeyError is raised.
901916 if not self .db .hasnode (link_class , value ):
902917 raise IndexError , '%s has no node %s' % (link_class , value )
903918
904- if self .properties [key ].do_journal :
919+ if self .do_journal and self . properties [key ].do_journal :
905920 # register the unlink with the old linked node
906921 if node [key ] is not None :
907922 self .db .addjournal (link_class , node [key ], 'unlink' ,
@@ -941,7 +956,7 @@ class or a KeyError is raised.
941956 if id in value :
942957 continue
943958 # register the unlink with the old linked node
944- if self .properties [key ].do_journal :
959+ if self .do_journal and self . properties [key ].do_journal :
945960 self .db .addjournal (link_class , id , 'unlink' ,
946961 (self .classname , nodeid , key ))
947962 l .remove (id )
@@ -954,7 +969,7 @@ class or a KeyError is raised.
954969 if id in l :
955970 continue
956971 # register the link with the newly linked node
957- if self .properties [key ].do_journal :
972+ if self .do_journal and self . properties [key ].do_journal :
958973 self .db .addjournal (link_class , id , 'link' ,
959974 (self .classname , nodeid , key ))
960975 l .append (id )
@@ -986,7 +1001,8 @@ class or a KeyError is raised.
9861001
9871002 # do the set, and journal it
9881003 self .db .setnode (self .classname , nodeid , node )
989- self .db .addjournal (self .classname , nodeid , 'set' , propvalues )
1004+ if self .do_journal :
1005+ self .db .addjournal (self .classname , nodeid , 'set' , propvalues )
9901006
9911007 self .fireReactors ('set' , nodeid , oldvalues )
9921008
@@ -1010,7 +1026,8 @@ def retire(self, nodeid):
10101026 node = self .db .getnode (self .classname , nodeid )
10111027 node [self .db .RETIRED_FLAG ] = 1
10121028 self .db .setnode (self .classname , nodeid , node )
1013- self .db .addjournal (self .classname , nodeid , 'retired' , None )
1029+ if self .do_journal :
1030+ self .db .addjournal (self .classname , nodeid , 'retired' , None )
10141031
10151032 self .fireReactors ('retire' , nodeid , None )
10161033
@@ -1027,6 +1044,8 @@ def history(self, nodeid):
10271044 'date' is a Timestamp object specifying the time of the change and
10281045 'tag' is the journaltag specified when the database was opened.
10291046 """
1047+ if not self .do_journal :
1048+ raise ValueError , 'Journalling is disabled for this class'
10301049 return self .db .getjournal (self .classname , nodeid )
10311050
10321051 # Locating nodes:
@@ -1596,6 +1615,9 @@ def __init__(self, db, classname, **properties):
15961615
15971616#
15981617#$Log: not supported by cvs2svn $
1618+ #Revision 1.44 2002/07/14 02:05:53 richard
1619+ #. all storage-specific code (ie. backend) is now implemented by the backends
1620+ #
15991621#Revision 1.43 2002/07/10 06:30:30 richard
16001622#...except of course it's nice to use valid Python syntax
16011623#
0 commit comments