diff --git a/product/ERP5Type/patches/DemoStorage.py b/product/ERP5Type/patches/DemoStorage.py index 7feab074a09af3dfcff8cf4e05cd4e84f897dcce..d9fe84d86a727da9091d9eeeafd19fc0d0eaf64a 100644 --- a/product/ERP5Type/patches/DemoStorage.py +++ b/product/ERP5Type/patches/DemoStorage.py @@ -1,8 +1,7 @@ ############################################################################## # # Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved. -# All Rights Reserved. +# Copyright (c) 2010-2013 Nexedi SARL and Contributors. All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. @@ -13,43 +12,27 @@ # ############################################################################## -from ZODB.DemoStorage import DemoStorage -from ZODB.ConflictResolution import tryToResolveConflict, ResolvedSerial +from ZODB import DemoStorage as _DemoStorage +from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial +from ZODB.POSException import ConflictError -if 1: +assert not issubclass(_DemoStorage.DemoStorage, ConflictResolvingStorage) + +class DemoStorage(_DemoStorage.DemoStorage, ConflictResolvingStorage): ## # Implement conflict resolution for DemoStorage # - import ZODB.POSException def store(self, oid, serial, data, version, transaction): - assert version=='', "versions aren't supported" - if transaction is not self._transaction: - raise ZODB.POSException.StorageTransactionError(self, transaction) - - # Since the OID is being used, we don't have to keep up with it any - # more. Save it now so we can forget it later. :) - self._stored_oids.add(oid) - - # See if we already have changes for this oid try: - old = self.changes.load(oid, '')[1] - except ZODB.POSException.POSKeyError: - try: - old = self.base.load(oid, '')[1] - except ZODB.POSException.POSKeyError: - old = serial - - if old != serial: - # <patch> - rdata = tryToResolveConflict(self, oid, old, serial, data) - if rdata is None: - raise ZODB.POSException.ConflictError( - oid=oid, serials=(old, serial), data=data) + return super(DemoStorage, self).store( + oid, serial, data, version, transaction) + except ConflictError, e: + old = e.serials[0] + rdata = self.tryToResolveConflict(oid, old, serial, data) + if rdata is None: # BBB: Zope < 2.13 + raise ConflictError(oid=oid, serials=(old, serial), data=data) self.changes.store(oid, old, rdata, '', transaction) return ResolvedSerial - # </patch> - - return self.changes.store(oid, serial, data, '', transaction) - DemoStorage.store = store +_DemoStorage.DemoStorage = DemoStorage