Jean-Paul Calderone schrieb:
On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
Jean-Paul Calderone wrote:

On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham
<[EMAIL PROTECTED]> wrote:
[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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to