[Zope] Re: How can I make class variables store in the zodb??

Stephen How stephenhow at mac.com
Mon Apr 25 20:41:54 EDT 2005


Peter,

I had the same question as you did, about getting my AT class variables 
stored in the ZODB.  The answer is pretty simple: almost all your class 
variables are automatically persistent in the ZODB, as the AT base 
class (e.g., BaseContent or BaseFolder) inherits from a persistent base 
class.  The ZODB and persistent classes are amazing.  Simple variables 
are automatically persistent; you don't have to do anything.  Shut down 
the server, restart it, and your variables are still there.  However, 
you do have to take an explicit step with mutable objects like 
dictionaries.  You have to add the line:
self._p_changed = 1
when you want to register the change to the mutable object into the 
ZODB.  Apparently, they redefined the assignment operator (=) or 
something, and used the reversed _p_changed member to do this function. 
 Before I knew this, I changed my dictionary, restarted the servevr, 
and it was gone.  After I did the self._p_changed = 1, it was saved in 
the ZODB.

Anyway, you can learn about the ZODB from the Zope Book (2.6).   
There's a section on persistent objects.

Originally, I wanted to use a lot of class variables, as this was my 
perspective from plain-old python.  However, I've learned that I really 
want to put everything possible into the schema, as it makes the AT 
future proof, and more robust.  It automatically creates accessors and 
mutators for these fields as well, which is preferred programming 
style.  I typically just change the visibility attributes of the field 
for privacy, and style in base_view.  However, I don't think there's a 
FieldType for a dictionary or array, so I use plain-old class variables 
for them.

Hope this helps.  I remember being very puzzled and frustrated over 
this concept before I asked around, and put the pieces together.

Stephen

On 2005-04-25 16:34:32 -0700, "Peter Millar" 
<peter.millar at parasyn.com.au> said:

> This is a multi-part message in MIME format.
> 
> 
> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_0188_01C54A43.26C535D0
> Content-Type: text/plain;
> 	charset="us-ascii"
> Content-Transfer-Encoding: 7bit
> 
> One thing we have noticed in our development of a plone archetype
> product is that archetype fields get stored in the zodb, whereas class
> variables do not (which is fine).  Plone portal tools have their
> properties stored in the zodb.
> 
> How do you get variables to store their data in the zodb??  If I wanted
> to store an archetype class variable to the zodb how could I do it .
> besides making it an archetype field??
> 
> ____________________________________________ Peter Millar Technical 
> Project Manager Parasyn Controls Pty Ltd
> Peter.Millar at Parasyn.com.au T: 61 7 3396 6388 F: 61 7 3396 6299 45 
> Millenium Place, Tingalpa QLD 4173 PO Box 400 Cannon Hill QLD 4170 
> Australia www.parasyn.com.au <http://www.parasyn.com.au/>
> 
> ------=_NextPart_000_0188_01C54A43.26C535D0
> Content-Type: text/html;
> 	charset="us-ascii"
> Content-Transfer-Encoding: quoted-printable
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
> <HTML>
> <HEAD>
> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
> charset=3Dus-ascii">
> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
> 6.0.4630.0">
> <TITLE>How can I make class variables store in the zodb??</TITLE>
> </HEAD>
> <BODY>
> <!-- Converted from text/rtf format -->
> 
> <P><FONT SIZE=3D2 FACE=3D"Arial">One thing we have noticed in our =
> development of a plone archetype product is that archetype fields get =
> stored in the zodb, whereas class variables do not (which is =
> fine).&nbsp; Plone portal tools have their properties stored in the =
> zodb.</FONT></P>
> 
> <P><FONT SIZE=3D2 FACE=3D"Arial">How do you get variables to store their =
> data in the zodb??&nbsp; If I wanted to store an archetype class =
> variable to the zodb how could I do it &#8230; besides making it an =
> archetype field??</FONT></P>
> 
> <P><FONT COLOR=3D"#0000FF" SIZE=3D1 =
> FACE=3D"Verdana">____________________________________________</FONT><BR>
> <B></B><B><FONT COLOR=3D"#0000CC" SIZE=3D2 FACE=3D"Verdana">Peter =
> Millar</FONT></B><FONT COLOR=3D"#0000CC" SIZE=3D2 =
> FACE=3D"Verdana"></FONT><BR>
> <B><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Verdana">Technical Project =
> Manager</FONT></B><FONT COLOR=3D"#808080" SIZE=3D1 =
> FACE=3D"Verdana"></FONT><BR>
> <B><FONT COLOR=3D"#0000CC" SIZE=3D1 FACE=3D"Verdana">Parasyn Controls =
> Pty Ltd</FONT></B><FONT COLOR=3D"#0000CC" SIZE=3D1 FACE=3D"Verdana"><BR>
> <BR>
> </FONT><A HREF=3D"mailto:Peter.Millar at Parasyn.com.au"><U></U><U><FONT =
> COLOR=3D"#0000FF" SIZE=3D1 =
> FACE=3D"Verdana">Peter.Millar at Parasyn.com.au</FONT></U></A><FONT =
> COLOR=3D"#0000CC" SIZE=3D1 FACE=3D"Verdana"><BR>
> </FONT><FONT COLOR=3D"#000000" SIZE=3D1 FACE=3D"Verdana">T: 61 7 3396 =
> 6388<BR>
> F: 61 7 3396 6299<BR>
> 45 Millenium Place, Tingalpa QLD 4173<BR>
> PO Box 400 Cannon Hill QLD 4170</FONT><BR>
> <B><FONT COLOR=3D"#0000CC" SIZE=3D1 =
> FACE=3D"Verdana">Australia</FONT></B><FONT COLOR=3D"#0000CC" SIZE=3D1 =
> FACE=3D"Verdana"><BR>
> </FONT><A HREF=3D"http://www.parasyn.com.au/"><U></U><U><FONT =
> COLOR=3D"#0000FF" SIZE=3D1 =
> FACE=3D"Verdana">www.parasyn.com.au</FONT></U></A><FONT =
> COLOR=3D"#0000CC" SIZE=3D1 FACE=3D"Verdana"></FONT>=20
> </P>
> 
> </BODY>
> </HTML>
> ------=_NextPart_000_0188_01C54A43.26C535D0--
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
> 
> --===============0509550955==--





More information about the Zope mailing list