--- a/dbapi.py Wed Mar 10 16:07:24 2010 +0100
+++ b/dbapi.py Mon Mar 01 11:26:14 2010 +0100
@@ -57,6 +57,7 @@
etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
etypescls.etype_class = etypescls.orig_etype_class
+
class ConnectionProperties(object):
def __init__(self, cnxtype=None, lang=None, close=True, log=False):
self.cnxtype = cnxtype or 'pyro'
@@ -546,16 +547,16 @@
self._closed = 1
def commit(self):
- """Commit any pending transaction to the database. Note that if the
- database supports an auto-commit feature, this must be initially off. An
- interface method may be provided to turn it back on.
+ """Commit pending transaction for this connection to the repository.
- Database modules that do not support transactions should implement this
- method with void functionality.
+ may raises `Unauthorized` or `ValidationError` if we attempted to do
+ something we're not allowed to for security or integrity reason.
+
+ If the transaction is undoable, a transaction id will be returned.
"""
if not self._closed is None:
raise ProgrammingError('Connection is already closed')
- self._repo.commit(self.sessionid)
+ return self._repo.commit(self.sessionid)
def rollback(self):
"""This method is optional since not all databases provide transaction
@@ -582,6 +583,73 @@
req = self.request()
return self.cursor_class(self, self._repo, req=req)
+ # undo support ############################################################
+
+ def undoable_transactions(self, ueid=None, req=None, **actionfilters):
+ """Return a list of undoable transaction objects by the connection's
+ user, ordered by descendant transaction time.
+
+ Managers may filter according to user (eid) who has done the transaction
+ using the `ueid` argument. Others will only see their own transactions.
+
+ Additional filtering capabilities is provided by using the following
+ named arguments:
+
+ * `etype` to get only transactions creating/updating/deleting entities
+ of the given type
+
+ * `eid` to get only transactions applied to entity of the given eid
+
+ * `action` to get only transactions doing the given action (action in
+ 'C', 'U', 'D', 'A', 'R'). If `etype`, action can only be 'C', 'U' or
+ 'D'.
+
+ * `public`: when additional filtering is provided, their are by default
+ only searched in 'public' actions, unless a `public` argument is given
+ and set to false.
+ """
+ txinfos = self._repo.undoable_transactions(self.sessionid, ueid,
+ **actionfilters)
+ if req is None:
+ req = self.request()
+ for txinfo in txinfos:
+ txinfo.req = req
+ return txinfos
+
+ def transaction_info(self, txuuid, req=None):
+ """Return transaction object for the given uid.
+
+ raise `NoSuchTransaction` if not found or if session's user is not
+ allowed (eg not in managers group and the transaction doesn't belong to
+ him).
+ """
+ txinfo = self._repo.transaction_info(self.sessionid, txuuid)
+ if req is None:
+ req = self.request()
+ txinfo.req = req
+ return txinfo
+
+ def transaction_actions(self, txuuid, public=True):
+ """Return an ordered list of action effectued during that transaction.
+
+ If public is true, return only 'public' actions, eg not ones triggered
+ under the cover by hooks, else return all actions.
+
+ raise `NoSuchTransaction` if the transaction is not found or if
+ session's user is not allowed (eg not in managers group and the
+ transaction doesn't belong to him).
+ """
+ return self._repo.transaction_actions(self.sessionid, txuuid, public)
+
+ def undo_transaction(self, txuuid):
+ """Undo the given transaction. Return potential restoration errors.
+
+ raise `NoSuchTransaction` if not found or if session's user is not
+ allowed (eg not in managers group and the transaction doesn't belong to
+ him).
+ """
+ return self._repo.undo_transaction(self.sessionid, txuuid)
+
# cursor object ###############################################################