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 3 1673
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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......
|
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...
|
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,...
|
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...
|
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,
|
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...
|
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...
|
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):...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |