[Checkins] SVN: zope2docs/trunk/articles/ZODB get_transaction() -> transaction

Andreas Jung andreas at andreas-jung.com
Sat Feb 21 11:03:10 EST 2009


Log message for revision 96958:
  get_transaction() -> transaction
  

Changed:
  U   zope2docs/trunk/articles/ZODB1.rst
  U   zope2docs/trunk/articles/ZODB2.rst

-=-
Modified: zope2docs/trunk/articles/ZODB1.rst
===================================================================
--- zope2docs/trunk/articles/ZODB1.rst	2009-02-21 15:58:51 UTC (rev 96957)
+++ zope2docs/trunk/articles/ZODB1.rst	2009-02-21 16:03:09 UTC (rev 96958)
@@ -91,9 +91,9 @@
 object, but this change is so far only temporary.  In order to
 make the change permanent, you must commit the current
 transaction::
+      >>> import transaction
+      >>> transaction.commit()
 
-      >>> get_transaction().commit()
-
 Transactions group of lots of changes in one atomic operation.  In
 a later article, I'll show you how this is a very powerful
 feature.  For now, you can think of committing transactions as
@@ -152,7 +152,7 @@
 the change will *not* take effect.  Consider this example::
 
       >>> root['employees'].append('Bill')
-      >>> get_transaction().commit()
+      >>> transaction.commit()
     
 You would expect this to work, but it doesn't.  The reason for
 this is that ZODB cannot detect that the 'employees' list
@@ -165,7 +165,7 @@
       >>> employees = root['employees']
       >>> employees.append('Bill')
       >>> root['employees'] = employees
-      >>> get_transaction().commit()
+      >>> _transaction.commit()
 
 Here, you move the employees list to a local variable, change the
 list, and then *reassign* the list back into the database and
@@ -208,7 +208,7 @@
       ...     employee.setName(name)
       ...     employees.append(employee)
       >>> root['employees']=employees
-      >>> get_transaction().commit()
+      >>> transaction.commit()
 
 Don't forget to call 'commit()', so that the changes you have made
 so far are committed to the database, and a new transaction is
@@ -219,14 +219,14 @@
 
       >>> bob=root['employees'][2]
       >>> bob.setName('Robert')
-      >>> get_transaction().commit()
+      >>> transaction.commit()
 
 You can even change attributes of persistent instaces without
 calling methods::
 
       >>> bob=root['employees'][2]
       >>> bob._coffee_prefs=('Cream', 'Sugar')
-      >>> get_transaction().commit()
+      >>> transaction.commit()
 
 It doesn't matter whether you change an attribute directly, or
 whether it's changed by a method.  As you can tell, all of the
@@ -285,6 +285,7 @@
       from ZODB.FileStorage import FileStorage
       from ZODB.PersistentMapping import PersistentMapping
       from Persistence import Persistent
+      import transaction
 
       class Employee(Persistent):
           """An employee"""
@@ -334,7 +335,7 @@
               employees[name]=Employee(name)
 
           root['employees'] = employees  # reassign to change
-          get_transaction().commit()
+          transaction.commit()
           print "Employee %s added." % name
           print
 

Modified: zope2docs/trunk/articles/ZODB2.rst
===================================================================
--- zope2docs/trunk/articles/ZODB2.rst	2009-02-21 15:58:51 UTC (rev 96957)
+++ zope2docs/trunk/articles/ZODB2.rst	2009-02-21 16:03:09 UTC (rev 96958)
@@ -307,7 +307,8 @@
 To abort a transaction, you need to call the 'abort' method of the
 transactions object::
 
-      get_transaction().abort()
+    >>> import transaction
+    >>>  transaction.abort()
 
     This will throw away all the currently changed objects and start a
     new, empty transaction.
@@ -341,8 +342,8 @@
 You can commit or abort a subtransaction by calling either
 commit() or abort() with an argument of 1::
 
-      get_transaction().commit(1) # or
-      get_transaction().abort(1)
+      transaction.commit(1) # or
+      transaction.abort(1)
 
 Subtransactions offer you a nice way to "batch" all of your "all
 or none" actions into smaller "all or none" actions while still



More information about the Checkins mailing list