Hi,

Is transaction build in of ZODB? I have a product which keep a counter
property and a inc method which will increase the property with a integer
amount. I would like to make sure that concurrent inc call will not cause
problem. Is ZODB automatically do transaction and prevent corrupt of data?

My class is like this:

class Cid(
    OFS.SimpleItem.Item,   # A simple Principia object. Not Folderish.
    Persistent,            # Make us persistent. Yaah!
    Acquisition.Implicit,  # Uh, whatever.
    AccessControl.Role.RoleManager # Security manager.
    ):
    """Cid object.

    Keep an integer value and provide an way to inc it.
    """

    meta_type = 'Cid' # what do people think they're adding?

    manage_options = ( # what management options are there?
 {'label': 'Edit',       'action': 'manage_main'},
 {'label': 'View',       'action': ''}, # defaults to index_html
 {'label': 'Security',   'action': 'manage_access'},
        )

    __ac_permissions__=( # what permissions make sense for us?
 ('View management screens', ('manage_tabs','manage_main')),
 ('Change permissions',      ('manage_access',)           ),
 ('Change Cid'     ,     ('manage_edit',)             ),
 ('View Cid',            ('',)                        ),
 )

    def __init__(self, id, title='', initval=0):
        """initialise a new instance"""
        self.id = id
        self.title = title
        try:
            self.counter = int(initval)
        except:
            self.counter= 0

    def inc(self, increment=1):
        """ inc counter """
        self.counter = self.counter+increment
        return

    def __repr__(self):
        '''aa'''
        return self.counter

    def __str__(self):
        ''' a '''
        return str(self.counter)

    def index_html(self):
        ''' return data '''
        return self.counter

    manage_main = HTMLFile('CidEdit', globals()) # Management Interface

    def manage_edit(self, title, counter, REQUEST=None):
        """does this really need a doc string?"""
        self.title = title
        try:
            self.counter = int(counter)
        except:
            pass
        if REQUEST is not None:
            return MessageDialog(
     title = 'Edited',
     message = "Properties for %s changed." % self.id,
     action = './manage_main',
     )

I add an object aaa of Cid and make the following call on dtml:

<dtml-call "aaa.inc()">
Counter is now : <dtml-var aaa>

How could I prevent aaa get updated after inc() is call?


Rgs,

Kent Sin
---------------------------------
kentsin.weblogs.com
kentsin.imeme.net


_______________________________________________
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to