Commit a8857477 authored by Jim Fulton's avatar Jim Fulton

Refined interfaces to distinguish between data-manager savepoints and

transaction savepoints.

Updated some interface declarations.
parent ef517a14
...@@ -27,7 +27,7 @@ from persistent import PickleCache ...@@ -27,7 +27,7 @@ from persistent import PickleCache
# interfaces # interfaces
from persistent.interfaces import IPersistentDataManager from persistent.interfaces import IPersistentDataManager
from ZODB.interfaces import IConnection from ZODB.interfaces import IConnection
from transaction.interfaces import IDataManager from transaction.interfaces import ISavepointDataManager, IDataManagerSavepoint
from zope.interface import implements from zope.interface import implements
import transaction import transaction
...@@ -59,7 +59,7 @@ def resetCaches(): ...@@ -59,7 +59,7 @@ def resetCaches():
class Connection(ExportImport, object): class Connection(ExportImport, object):
"""Connection to ZODB for loading and storing objects.""" """Connection to ZODB for loading and storing objects."""
implements(IConnection, IDataManager, IPersistentDataManager) implements(IConnection, ISavepointDataManager, IPersistentDataManager)
_storage = _normal_storage = _savepoint_storage = None _storage = _normal_storage = _savepoint_storage = None
...@@ -319,7 +319,7 @@ class Connection(ExportImport, object): ...@@ -319,7 +319,7 @@ class Connection(ExportImport, object):
########################################################################## ##########################################################################
########################################################################## ##########################################################################
# Data manager (IDataManager) methods # Data manager (ISavepointDataManager) methods
def abort(self, transaction): def abort(self, transaction):
"""Abort a transaction and forget all changes.""" """Abort a transaction and forget all changes."""
...@@ -638,7 +638,7 @@ class Connection(ExportImport, object): ...@@ -638,7 +638,7 @@ class Connection(ExportImport, object):
"""Return a consistent sort key for this connection.""" """Return a consistent sort key for this connection."""
return "%s:%s" % (self._storage.sortKey(), id(self)) return "%s:%s" % (self._storage.sortKey(), id(self))
# Data manager (IDataManager) methods # Data manager (ISavepointDataManager) methods
########################################################################## ##########################################################################
########################################################################## ##########################################################################
...@@ -1061,6 +1061,8 @@ class Connection(ExportImport, object): ...@@ -1061,6 +1061,8 @@ class Connection(ExportImport, object):
class Savepoint: class Savepoint:
implements(IDataManagerSavepoint)
def __init__(self, datamanager, state): def __init__(self, datamanager, state):
self.datamanager = datamanager self.datamanager = datamanager
self.state = state self.state = state
......
...@@ -308,7 +308,25 @@ class IDataManager(zope.interface.Interface): ...@@ -308,7 +308,25 @@ class IDataManager(zope.interface.Interface):
class ISavepointDataManager(IDataManager): class ISavepointDataManager(IDataManager):
def savepoint(): def savepoint():
"""Return a savepoint (ISavepoint) """Return a data-manager savepoint (IDataManagerSavepoint)
"""
class IDataManagerSavepoint(zope.interface.Interface):
"""Savepoint for data-manager changes for use in transaction savepoints
Datamanager savepoints are used by, and only by, transaction savepoints.
Note that data manager savepoints don't have any notion of or
responsibility for validity. It isn't the responsibility of
data-manager savepoints to prevent multiple rollbacks or rollbacks
after transaction termination. Preventing invalid savepoint
rollback is the responsibility of transaction rollbacks.
Application code should never use data-manager savepoints.
"""
def rollback():
"""Rollback any work done since the savepoint
""" """
class ISavepoint(zope.interface.Interface): class ISavepoint(zope.interface.Interface):
......
...@@ -30,7 +30,7 @@ class SampleDataManager(UserDict.DictMixin): ...@@ -30,7 +30,7 @@ class SampleDataManager(UserDict.DictMixin):
This data manager stores named simple values, like strings and numbers. This data manager stores named simple values, like strings and numbers.
""" """
interface.implements(transaction.interfaces.ISavepointDataManager) interface.implements(transaction.interfaces.IDataManager)
def __init__(self, transaction_manager = None): def __init__(self, transaction_manager = None):
if transaction_manager is None: if transaction_manager is None:
...@@ -156,6 +156,8 @@ class SampleSavepointDataManager(SampleDataManager): ...@@ -156,6 +156,8 @@ class SampleSavepointDataManager(SampleDataManager):
This extends the basic data manager with savepoint support. This extends the basic data manager with savepoint support.
""" """
interface.implements(transaction.interfaces.ISavepointDataManager)
def savepoint(self): def savepoint(self):
# When we create the savepoint, we save the existing database state # When we create the savepoint, we save the existing database state
return SampleSavepoint(self, self.uncommitted.copy()) return SampleSavepoint(self, self.uncommitted.copy())
...@@ -166,6 +168,8 @@ class SampleSavepointDataManager(SampleDataManager): ...@@ -166,6 +168,8 @@ class SampleSavepointDataManager(SampleDataManager):
class SampleSavepoint: class SampleSavepoint:
interface.implements(transaction.interfaces.IDataManagerSavepoint)
def __init__(self, data_manager, data): def __init__(self, data_manager, data):
self.data_manager = data_manager self.data_manager = data_manager
self.data = data self.data = data
......
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