Commit 77f9030e authored by Julien Muchembled's avatar Julien Muchembled

DemoStorage: update conflict resolution patch for ZODB 3.10

parent 4718f5e1
##############################################################################
#
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment