[Zope3-checkins] CVS: Zope3/src/transaction - README.txt:1.2
util.py:1.2 __init__.py:1.4 interfaces.py:1.6 manager.py:NONE
txn.py:NONE
Fred L. Drake, Jr.
fred at zope.com
Fri Feb 20 11:57:58 EST 2004
Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv22507/src/transaction
Modified Files:
__init__.py interfaces.py
Added Files:
README.txt util.py
Removed Files:
manager.py txn.py
Log Message:
update to replace ZODB 4 with ZODB 3
=== Zope3/src/transaction/README.txt 1.1 => 1.2 ===
--- /dev/null Fri Feb 20 11:57:58 2004
+++ Zope3/src/transaction/README.txt Fri Feb 20 11:56:56 2004
@@ -0,0 +1,13 @@
+This package is currently a facade of the ZODB.Transaction module.
+
+It exists to support:
+
+- Application code that uses the ZODB 4 transaction API
+
+- ZODB4-style data managers (transaction.interfaces.IDataManager)
+
+Note that the data manager API, transaction.interfaces.IDataManager,
+is syntactically simple, but semantically complex. The semantics
+were not easy to express in the interface. This could probably use
+more work. The semantics are presented in detail through examples of
+a sample data manager in transaction.tests.test_SampleDataManager.
=== Zope3/src/transaction/util.py 1.1 => 1.2 ===
--- /dev/null Fri Feb 20 11:57:58 2004
+++ Zope3/src/transaction/util.py Fri Feb 20 11:56:56 2004
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Utility classes or functions
+
+$Id$
+"""
+
+from transaction.interfaces import IRollback
+
+try:
+ from zope.interface import implements
+except ImportError:
+ def implements(*args):
+ pass
+
+class NoSavepointSupportRollback:
+ """Rollback for data managers that don't support savepoints
+
+ >>> class DataManager:
+ ... def savepoint(self, txn):
+ ... return NoSavepointSupportRollback(self)
+ >>> rb = DataManager().savepoint('some transaction')
+ >>> rb.rollback()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: """ \
+ """DataManager data managers do not support """ \
+ """savepoints (aka subtransactions
+
+ """
+
+ implements(IRollback)
+
+ def __init__(self, dm):
+ self.dm = dm.__class__.__name__
+
+ def rollback(self):
+ raise NotImplementedError(
+ "%s data managers do not support savepoints (aka subtransactions"
+ % self.dm)
=== Zope3/src/transaction/__init__.py 1.3 => 1.4 ===
--- Zope3/src/transaction/__init__.py:1.3 Wed Mar 5 17:12:38 2003
+++ Zope3/src/transaction/__init__.py Fri Feb 20 11:56:56 2004
@@ -1,6 +1,6 @@
-##############################################################################
+############################################################################
#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001, 2002, 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -10,12 +10,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
-##############################################################################
+############################################################################
-from transaction.manager import ThreadedTransactionManager
+from ZODB.Transaction import get_transaction
-_manager = ThreadedTransactionManager()
-get_transaction = _manager.get
-
-def set_factory(factory):
- _manager.txn_factory = factory
=== Zope3/src/transaction/interfaces.py 1.5 => 1.6 ===
--- Zope3/src/transaction/interfaces.py:1.5 Thu Mar 20 12:25:54 2003
+++ Zope3/src/transaction/interfaces.py Fri Feb 20 11:56:56 2004
@@ -11,131 +11,107 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-from zope.interface import Interface
-class TransactionError(StandardError):
- """An error occured due to normal transaction processing."""
+try:
+ from zope.interface import Interface
+except ImportError:
+ class Interface:
+ pass
-class ConflictError(TransactionError):
- """Two transactions tried to modify the same object at once
-
- This transaction should be resubmitted.
- """
-
-class IllegalStateError(TransactionError):
- """An operation was invoked that wasn't valid in the current
- transaction state.
- """
-
- def __init__(self, verb, state):
- self._verb = verb
- self._state = state
-
- def __str__(self):
- return "Can't %s transaction in %s state" % (self._verb,
- self._state)
-
-class AbortError(TransactionError):
- """Transaction commit failed and the application must abort."""
-
- def __init__(self, datamgr):
- self.datamgr = datamgr
-
- def __str__(self):
- str = self.__class__.__doc__ + " Failed data manager: %s"
- return str % self.datamgr
-
-class RollbackError(TransactionError):
- """An error occurred rolling back a savepoint."""
class IDataManager(Interface):
"""Data management interface for storing objects transactionally
This is currently implemented by ZODB database connections.
+
+ XXX This exists to document ZODB4 behavior, to help create some
+ backward-compatability support for Zope 3. New classes shouldn't
+ implement this. They should implement ZODB.interfaces.IDataManager
+ for now. Our hope is that there will eventually be an interface
+ like this or that this interface will evolve and become the
+ standard interface. There are some issues to be resolved first, like:
+
+ - Probably want separate abort methods for use in and out of
+ two-phase commit.
+
+ - The savepoint api may need some more thought.
+
"""
def prepare(transaction):
- """Begin two-phase commit of a transaction.
+ """Perform the first phase of a 2-phase commit
+
+ The data manager prepares for commit any changes to be made
+ persistent. A normal return from this method indicated that
+ the data manager is ready to commit the changes.
The data manager must raise an exception if it is not prepared
to commit the transaction after executing prepare().
+
+ The transaction must match that used for preceeding
+ savepoints, if any.
"""
+
+ # This is equivalent to zodb3's tpc_begin, commit, and
+ # tpc_vote combined.
def abort(transaction):
- """Abort changes made by transaction."""
+ """Abort changes made by transaction
- def commit(transaction):
- """Commit changes made by transaction."""
+ This may be called before two-phase commit or in the second
+ phase of two-phase commit.
- def savepoint(transaction):
- """Do tentative commit of changes to this point.
+ The transaction must match that used for preceeding
+ savepoints, if any.
- Should return an object implementing IRollback
"""
-class IRollback(Interface):
-
- def rollback():
- """Rollback changes since savepoint."""
-
-class ITransaction(Interface):
- """Transaction objects
-
- Application code typically gets these by calling
- get_transaction().
- """
+ # This is equivalent to *both* zodb3's abort and tpc_abort
+ # calls. This should probably be split into 2 methods.
- def abort():
- """Abort the current transaction."""
-
- def begin():
- """Begin a transaction."""
+ def commit(transaction):
+ """Finish two-phase commit
- def commit():
- """Commit a transaction."""
+ The prepare method must be called, with the same transaction,
+ before calling commit.
+
+ """
- def join(resource):
- """Join a resource manager to the current transaction."""
+ # This is equivalent to zodb3's tpc_finish
- def status():
- """Return status of the current transaction."""
+ def savepoint(transaction):
+ """Do tentative commit of changes to this point.
- def suspend():
- """Suspend the current transaction.
+ Should return an object implementing IRollback that can be used
+ to rollback to the savepoint.
+
+ Note that (unlike zodb3) this doesn't use a 2-phase commit
+ protocol. If this call fails, or if a rollback call on the
+ result fails, the (containing) transaction should be
+ aborted. Aborting the containing transaction is *not* the
+ responsibility of the data manager, however.
+
+ An implementation that doesn't support savepoints should
+ implement this method by returning a rollback implementation
+ that always raises an error when it's rollback method is
+ called. The savepoing method shouldn't raise an error. This
+ way, transactions that create savepoints can proceed as long
+ as an attempt is never made to roll back a savepoint.
- If a transaction is suspended, the transaction manager no
- longer treats it as active. The resume() method must be
- called before the transaction can be used.
"""
- def resume():
- """Resume the current transaction.
- If another transaction is active, it must be suspended before
- resume() is called.
- """
+class IRollback(Interface):
-class ITransactionManager(Interface):
- """Coordinates application use of transactional resources."""
+ def rollback():
+ """Rollback changes since savepoint.
- def get():
- """Return the curren transaction.
+ IOW, rollback to the last savepoint.
- Calls new() to start a new transaction if one does not exist.
- """
+ It is an error to rollback to a savepoint if:
- def begin():
- """Return a new transaction.
+ - An earlier savepoint within the same transaction has been
+ rolled back to, or
- If a transaction is currently active for the calling thread,
- it is aborted.
+ - The transaction has ended.
"""
-
- def commit(txn):
- """Commit txn."""
-
- def abort(txn):
- """Abort txn."""
-
- def savepoint(txn):
- """Return rollback object that can restore txn to current state."""
=== Removed File Zope3/src/transaction/manager.py ===
=== Removed File Zope3/src/transaction/txn.py ===
More information about the Zope3-Checkins
mailing list