Plone uses the ZODB database which implements Multiversion concurrency control.
Plone will complete either all database modifications that occur during a request, or none of them. It will never write incomplete data to the database.
Plone and the underlying Zope handles transactions transparently.
Note
Every transaction is a read transaction until any of the objects participating in the transaction are mutated (object attribute set), turning the transaction to a write transaction.
Note
Old examples might refer to the get_transaction() function. This has been replaced by transaction.get() in the later Zope versions.
Please read this Zope transaction tutorial to get started how to use transactions with your code.
Normally transactions are managed by Plone and the developer should not be interested in them.
Special cases where one would want to manage transaction life-cycle may include:
Example code:
Normally, a Zope transaction keeps a list of objects modified within the transaction in a structure in RAM.
This list of objects can grow quite large when there is a lot of work done across a lot of objects in the context of a transaction. Subtransactions write portions of this object list out to disk, freeing the RAM required by the transaction list. Using subtransactions can allow you to build transactions involving objects whose combined size is larger than available RAM.
Example:
import transaction
...
done = 0
for brain in all_images:
done += 1
...
# Since this is HUGE operation (think resizing 2 GB images)
# it is not nice idea to buffer the transaction (all changed data)
# in the memory (Zope default transaction behavior).
# Using subtransactions we hint Zope when it would be a good time to
# flush the changes to the disk.
if done % 10 == 0:
# Commit subtransaction for every 10th processed item
transaction.get().commit(True)
It is possible to perform actions before and after transaction is written to the database.
http://svn.zope.org/transaction/trunk/transaction/_transaction.py?rev=81646&view=auto
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.
For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.