tailbone.db
¶
Database sessions etc.
- class tailbone.db.TailboneSessionDataManager(session, status, transaction_manager, keep_session=False)[source]¶
Integrate a top level sqlalchemy session transaction into a zope transaction
One phase variant.
Note
This class appears to be necessary in order for the SQLAlchemy-Continuum integration to work alongside the Zope transaction integration.
It subclasses
zope.sqlalchemy.datamanager.SessionDataManager
but injects some SQLAlchemy-Continuum logic withintpc_vote()
, and is sort of monkey-patched into the mix.
- class tailbone.db.ZopeTransactionEvents(initial_state='active', transaction_manager=<transaction._manager.ThreadTransactionManager object>, keep_session=False)[source]¶
Record that a flush has occurred on a session’s connection. This allows the DataManager to rollback rather than commit on read only transactions.
Note
This class appears to be necessary in order for the SQLAlchemy-Continuum integration to work alongside the Zope transaction integration.
It subclasses
zope.sqlalchemy.datamanager.ZopeTransactionEvents
but overrides various methods to ensure the customjoin_transaction()
is called, and is sort of monkey-patched into the mix.
- tailbone.db.join_transaction(session, initial_state='active', transaction_manager=<transaction._manager.ThreadTransactionManager object>, keep_session=False)[source]¶
Join a session to a transaction using the appropriate datamanager.
It is safe to call this multiple times, if the session is already joined then it just returns.
initial_state is either STATUS_ACTIVE, STATUS_INVALIDATED or STATUS_READONLY
If using the default initial status of STATUS_ACTIVE, you must ensure that mark_changed(session) is called when data is written to the database.
The ZopeTransactionExtesion SessionExtension can be used to ensure that this is called automatically after session write operations.
Note
This function appears to be necessary in order for the SQLAlchemy-Continuum integration to work alongside the Zope transaction integration.
It overrides
zope.sqlalchemy.datamanager.join_transaction()
to ensure the customTailboneSessionDataManager
is used, and is sort of monkey-patched into the mix.
- tailbone.db.register(session, initial_state='active', transaction_manager=<transaction._manager.ThreadTransactionManager object>, keep_session=False)[source]¶
Register ZopeTransaction listener events on the given Session or Session factory/class.
This function requires at least SQLAlchemy 0.7 and makes use of the newer sqlalchemy.event package in order to register event listeners on the given Session.
The session argument here may be a Session class or subclass, a sessionmaker or scoped_session instance, or a specific Session instance. Event listening will be specific to the scope of the type of argument passed, including specificity to its subclass as well as its identity.
Note
This function appears to be necessary in order for the SQLAlchemy-Continuum integration to work alongside the Zope transaction integration.
It overrides
zope.sqlalchemy.datamanager.regsiter()
to ensure the customZopeTransactionEvents
is used.