[Zodb-checkins] CVS: Zope3/src/zodb - conflict.py:1.6
Jeremy Hylton
jeremy@zope.com
Wed, 15 Jan 2003 18:28:34 -0500
Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv6701/zodb
Modified Files:
conflict.py
Log Message:
Simplify conflict error handling.
Rename tryToResolveConflict() to resolveConflict().
Change its contract to raise ConflictError on failure instead of
returning None. This reduces the name of places that ConflictError
is raised but slightly complicates code that wants to raise UndoError
instead.
=== Zope3/src/zodb/conflict.py 1.5 => 1.6 ===
--- Zope3/src/zodb/conflict.py:1.5 Wed Jan 15 14:07:22 2003
+++ Zope3/src/zodb/conflict.py Wed Jan 15 18:28:00 2003
@@ -22,7 +22,7 @@
from cPickle import PicklingError
import logging
-from transaction.interfaces import ConflictError
+from zodb.interfaces import ConflictError
from zodb.serialize import BaseObjectReader, ObjectWriter, getClassMetadata
ResolvedSerial = "rs"
@@ -137,8 +137,23 @@
class ConflictResolvingStorage:
"Mix-in class that provides conflict resolution handling for storages"
- def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
- committedData=None):
+ def resolveConflict(self, oid, committedSerial, oldSerial, newpickle,
+ committedData=None):
+ """Attempt to resolve conflict for object oid.
+
+ Raises ConflictError if the conflict can no be resolved. If
+ the object oid defines an _p_resolveConflict() method, call it
+ to resolve the conflict.
+ """
+ r = self._resolve(oid, committedSerial, oldSerial, newpickle,
+ committedData)
+ if r is None:
+ raise ConflictError(oid=oid,
+ serials=(committedSerial, oldSerial))
+ return r
+
+ def _resolve(self, oid, committedSerial, oldSerial, newpickle,
+ committedData):
reader = ResolveObjectReader()
resolve = reader.getResolver(newpickle)
if resolve is None: