Well, it is basically finished and working, combining a visible Product interface and a counter tag... But, overriding __setstate__, removing the temporary entry from the state, and called Persistent.__setstate__, while generating no errors, fails to prevent the temporary entry from being written into the database. Please help, I need two answers! 1. How can I create a variable within a Product that will not be persistent (i.e. will not be written to disk)? 2. What function is called at normal shutdown? I need to call a function at shutdown to move the current value from temp to real. Note: The counter is usable as is, so if the list members think that Paul's now repudiated fear of constant disk growth is a non-issue, I could drop the temporary variable, and just keep the advantages of the interface, and the potential for an SQL based backend whilst keeping the same front-end. Thanks again. Howard C. Shaw III Programmer/SysAdmin St. Thomas High School
On Wed, 24 Mar 1999, Shaw, Howard wrote:
Well, it is basically finished and working, combining a visible Product interface and a counter tag... But, overriding __setstate__, removing the temporary entry from the state, and called Persistent.__setstate__, while generating no errors, fails to prevent the temporary entry from being written into the database. Please help, I need two answers!
1. How can I create a variable within a Product that will not be persistent (i.e. will not be written to disk)?
ZODB cannot detect changes to mutable objects that are not treated as immutable. So I suppose that if your object includes a list, a dictionary or a non persistence instance then any changes to these objects will go undetected by ZODB. For instance you can have a counter class like: class Counter: def __init__(self): self.__counter=1 self.__startdate=DateTime.DateTime() def incr(self): self.__counter=self.__counter+1 def decr(self): self.__counter=self.__counter-1 def reset(self): self.__init__() def start_date(self): return self.__startdate def hits(self): return repr(self.__counter) def __repr__(self): return repr(self.__counter) __str__=__repr__ If you add an instance of the above class on a Zope object, lets say by calling an external method: def counter(self,name): setattr(self,name,Counter()) then calling <!--# call "counter('main_counter')"--> will (hopefully!) add a counter to your calling zope object, even if that is a DTML method, and get registered with the ZODB. calling <!--# call "main_counter.incr()"--> will update the internal counter of your instance without registering the new value of the internal counter with ZODB. You could for example set a Zope property to the value of the internal counter every so many hits and that will register with ZODB, or you could even write it in an external file in the var directory or something. the above example is lousy for many reasons, as I have found out, but I hope will provide some clues to your questions. Pavlos
On Wed, 24 Mar 1999, Shaw, Howard wrote:
Well, it is basically finished and working, combining a visible Product interface and a counter tag... But, overriding __setstate__, removing the temporary entry from the state, and called Persistent.__setstate__, while generating no errors, fails to prevent the temporary entry from being written into the database. Please help, I need two answers!
1. How can I create a variable within a Product that will not be persistent (i.e. will not be written to disk)?
2. What function is called at normal shutdown? I need to call a function at shutdown to move the current value from temp to real.
Note: The counter is usable as is, so if the list members think that Paul's now repudiated fear of constant disk growth is a non-issue, I could drop the temporary variable, and just keep the advantages of the interface, and the potential for an SQL based backend whilst keeping the same front-end.
I'm not sure if this will help but... I've noticed mutable objects (lists, dictionsries) don't change you need to call self.__changed__(1) whenever you add or edit an object to a list or dictionary. Makes me wonder what would happen if you call self.__changed__(0) at the end of your request.
participants (3)
-
Pavlos Christoforou -
Scott Robertson -
Shaw, Howard