Example of class. Just an object between all of them in my program:
class Example:
def __init__(self, value):
self.value = value
return
def getValue(self):
return self.value
def setValue(self, value):
self.value = value
return
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?).
Adding persistence:
class Example:
def __init__(self, value):
self.value = value
# create in sql server
return
def getValue(self):
return self.value
def setValue(self, value):
self.value = value
# modify in sql server
return
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?
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).
Thanks for all.
.. Facundo 2 1350
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
Timo Warns wrote: Batista, Facundo wrote: [Example of class with get- and set-methods]
[...]
This is some kind of a design pattern often called "data access objects". Java has this already built-in with its JDOs.
Actually "built-in" is a little misleading ;-) There is an optional
package from Sun available. Strictly it is not part of the language.
Sorry for that.
Timo This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Manlio Perillo |
last post by:
Hi.
This post follows "does python have useless destructors".
I'm not an expert, so I hope what I will write is meaningfull and
clear.
Actually in Python there is no possibility to write code...
|
by: Glabbeek |
last post by:
I'm changing the layout of my site. Instead of using tables, I will use
DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not
the correct width. Mozilla and Opera are showing the...
|
by: Guy Mahieu |
last post by:
Hello all,
I am currently laying the baseline for a relatively small, single tier
application in which a small number of workstations will retrieve their data
from a MySQL database on a central...
|
by: Vijay Kumar R. Zanvar |
last post by:
Hello,
Unlike register, auto keyword can not be used to
declare formal parameter(s). Is there any specific
reason for this?
Kind regards,
Vijay Kumar R. Zanvar
|
by: Alpha |
last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key
column and the 2nd is a string. When I add a new row to the dataset to be
updated back to the database. What should I...
| |
by: Samuel |
last post by:
Hi,
I am running into a problem of mixing UICulture = auto and allowing users to
select culture using a dropdown list.
I am detecting a querystring, "setlang", and when found, setting the...
|
by: maya |
last post by:
at work they decided to center divs thus:
body {text-align:center}
#content {width: 612px; text-align:left; margin: 0 auto 0 auto; }
this works fine in IE & FF, EXCEPT in FF it doesn't work if...
|
by: King |
last post by:
This is a new test for object persistency. I am trying to store the
relationship between instances externally.
It's not working as expected. May be I am doing it in wrong way. Any
suggestions?
...
|
by: JOYCE |
last post by:
Look the subject,that's my problem!
I hope someone can help me, thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |