473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Re: Trying ZODB, background in Relational: mimic auto_increment?

On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <de***@nospam.web.dewrote:
>Jean-Paul Calderone wrote:
>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
<ph************@gmail.comwrote:
>>[snip]

How would one assign a unique ID to the root at that point?

Here's one way

class Sequence(Persistence):
def __init__(self):
self.current = 0

def next(self):
self.current += 1
return self.current

ticketSequence = Sequence()

class Ticket(Persistence):
def __init__(self):
self.id = ticketSequence.next()

Be aware that this isn't working concurrently. Depending on your
application, this can be mitigated using a simple threading.Lock.
ZODB has transactions. That's probably the best way to make this
code safe for concurrent use. A threading.Lock would make threaded
use safe, but wouldn't give you multiprocess concurrency safety.

Jean-Paul
Aug 14 '08 #1
3 1669
Jean-Paul Calderone schrieb:
On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch"
<de***@nospam.web.dewrote:
>Jean-Paul Calderone wrote:
>>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
<ph************@gmail.comwrote:
[snip]

How would one assign a unique ID to the root at that point?

Here's one way

class Sequence(Persistence):
def __init__(self):
self.current = 0

def next(self):
self.current += 1
return self.current

ticketSequence = Sequence()

class Ticket(Persistence):
def __init__(self):
self.id = ticketSequence.next()

Be aware that this isn't working concurrently. Depending on your
application, this can be mitigated using a simple threading.Lock.

ZODB has transactions. That's probably the best way to make this
code safe for concurrent use.
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.

Diez
Aug 14 '08 #2
Diez B. Roggisch wrote:
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.
A lock doesn't do the job at all. ZODB supports clustering through ZEO.
Multiple ZEO clients can be attached to a single or more ZODB servers.
Any kind of thread based locking is local to each ZEO client.

You have to sync a sequence generator across multiple ZEO clients, hook
into the two phase commit protocol or use the conflict resolution hooks.
The problem is more complex than you think.

Christian

Aug 14 '08 #3
Le Thursday 14 August 2008 20:14:19 Christian Heimes, vous avez écrit*:
Diez B. Roggisch wrote:
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.

A lock doesn't do the job at all. ZODB supports clustering through ZEO.
Multiple ZEO clients can be attached to a single or more ZODB servers.
Any kind of thread based locking is local to each ZEO client.

You have to sync a sequence generator across multiple ZEO clients, hook
into the two phase commit protocol or use the conflict resolution hooks.
You don't have too if you manage the conflict error anywhere else in the
program just manage the exception ConflictError and let the user retry later,
that will not happen that much on most application.

But,
The problem is more complex than you think.
Not that complex, strength of ZODB is right here, this entirely covered by the
introduction to zodb (ZODB/ZEO programming guide), see userdb and chatter
examples.
Christian

--
http://mail.python.org/mailman/listinfo/python-list


--
_____________

Maric Michaud
Aug 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Paul Rubin | last post by:
I've started a few threads before on object persistence in medium to high end server apps. This one is about low end apps, for example, a simple cgi on a personal web site that might get a dozen...
10
by: ls | last post by:
Hi All, I looking for help with ZODB data export to text file. I have file Data.fs (file becomes from Plone CMS) and I have to display content structure, data like intro, body of article, etc...
1
by: Harald Armin Massa | last post by:
Hello, I am using ZODB "standalone" in version 3.3.1 within some application. Now I learn that the 3.3.x branch of ZODB is "retired". No problem so far, everything is running fine. BUT......
3
by: Rene Pijlman | last post by:
I have a productional Linux web server with a Python/Zope/Plone. Now I'd like to install a non-Zope Python/ZODB application on the same server. What is the recommended way of doing that? Option...
5
by: vd12005 | last post by:
Hello, While playing to write an inverted index (see: http://en.wikipedia.org/wiki/Inverted_index), i run out of memory with a classic dict, (i have thousand of documents and millions of terms,...
2
by: Petra Chong | last post by:
Hello all I am using Python 2.3 and ZODB (without the rest of Zope) with the following pattern: * One process which writes stuff to a ZODB instance (call it test.db) * Another process which...
10
by: teddysnips | last post by:
SQL Server 2000 (DDL below) If I try to run this code in QA: SET IDENTITY_INSERT tblAdminUsers ON INSERT INTO tblAdminUsers (fldUserID, fldUsername, fldPassword, fldFullname,
17
by: Aaron Watters | last post by:
I've been poking around the world of object-relational mappers and it inspired me to coin a corellary to the the famous quote on regular expressions: "You have objects and a database: that's 2...
0
by: Phillip B Oldham | last post by:
Hi all. I'm playing with standalone ZODB at the moment trying to get a better understanding of its use in applications. I come from a PHP/MySQL background, and I'm taking my first steps with Python...
2
by: Jean-Paul Calderone | last post by:
On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham <phillip.oldham@gmail.comwrote: Here's one way class Sequence(Persistence): def __init__(self): self.current = 0 def next(self):...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.