Changeset 5654

Show
Ignore:
Timestamp:
11/03/08 17:36:49 (2 months ago)
Author:
mramm
Message:

Updated TG2 wiki example to explain the new transaction manager

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • docs/2.0/docs/main/Wiki20/wiki20.rst

    r5648 r5654  
    522522back to the viewing page. 
    523523 
    524 Although the ``page.data = data`` statement tells SQLAlchemy to store the page 
    525 data in the database, nothing happens until the ``DBSession.commit()``. This 
    526 structure allows SQLAlchemy to combine many operations into a single database 
    527 transaction and thus be much more efficient. You can also call 
    528 ``DBSession.flush()`` to send changes to the database, then do more work, then 
    529 ``flush()`` again, before finally committing. When you do a ``commit()``, that 
    530 will flush automatically for you if you haven't flushed explicitly. 
    531  
    532 You can now make changes and save the page we were editing, just like a real 
     524Although the ``page.data = data`` statement tells SQLAlchemy that you intend to store the page data in the database, nothing happens until the ``DBSession.flush()`` method is called. This is commonly refered to as the "unit of work" pattern, and it's an important structure for database developers because it allows SQLAlchemy to combine many operations into a single database update (or a minimized number of updates if some changes depend upon earlier changes) and thus be much more efficient in the database resources used. 
     525 
     526SQLALchemy also provides a ``DBSession.commit() method which flushes and commits any changes you've made in a trasaction.   TurboGears 2 provides a flexible transaction management system that automates this process wrapping each web request in it's own transaction and automatically rolling back that transaction if you get a python exception, or return an HTTP error code as your response.  
     527 
     528You don't have to do anything to use this transaction management system, it should just work. So, you can now make changes and save the page we were editing, just like a real 
    533529wiki. 
    534530