Auto persistency

Timo Warns timow at
Wed Aug 6 09:07:43 CEST 2003

Batista, Facundo wrote:
> [Example of class with get- and set-methods]
>  I want to implement persistency. I think it's a good idea to each object be
>  the responsible of it's own persistence in a file, in a sql server, anywhere
>  (opinions?).

This is some kind of a design pattern often called "data access
objects". Java has this already built-in with its JDOs. 
Hava a look at this design pattern and how it is implemented in other
languages or python packages. 
Do you need any kind of capabilities like transactions?

> [...]
>  Now I have two questions:
>  	1) How do I implement the dead of the object. I need it to erase
>  itself from the sql server. Should I define the __del__ method?

You probably should create another method like "drop". If you implement
the __del__ method, you will not have any persistency, because any time
your object is deleted, the data will be deleted in your data source. 

>  	2) When the program starts, how do I retrieve all the objects from
>  the sql server to memory? (considering that only the object knows how it's
>  persisted).

You could implement a factory, that generates the objects and loads the
data by a given primary key. 

HTH, Timo

More information about the Python-list mailing list