8
6
'block_implicit_flushes',
9
7
'clear_current_connection_cache',
11
'ConflictingTransactionManagerError',
13
10
'convert_storm_clause_to_string',
16
12
'flush_database_caches',
17
13
'flush_database_updates',
18
14
'get_transaction_timestamp',
64
57
from zope.interface import implements
65
58
from zope.security.proxy import removeSecurityProxy
67
from canonical.config import (
60
from canonical.config import dbconfig
71
61
from canonical.database.interfaces import ISQLBase
72
62
from lp.services.propertycache import clear_property_cache
272
262
clear_property_cache(self)
275
alreadyInstalledMsg = ("A ZopelessTransactionManager with these settings is "
276
"already installed. This is probably caused by calling initZopeless twice.")
279
class ConflictingTransactionManagerError(Exception):
283
265
class ZopelessTransactionManager(object):
284
266
"""Compatibility shim for initZopeless()"""
286
268
_installed = None
287
_CONFIG_OVERLAY_NAME = 'initZopeless config overlay'
289
270
def __init__(self):
290
271
raise AssertionError("ZopelessTransactionManager should not be "
302
283
ISOLATION_LEVEL_READ_COMMITTED: 'read_committed',
303
284
ISOLATION_LEVEL_SERIALIZABLE: 'serializable'}[isolation]
305
# Construct a config fragment:
306
overlay = dedent("""\
308
isolation_level: %(isolation_level)s
313
isolation_level=isolation_level,
316
if cls._installed is not None:
317
if cls._config_overlay != overlay:
318
raise ConflictingTransactionManagerError(
319
"A ZopelessTransactionManager with different "
320
"settings is already installed")
321
# There's an identical ZopelessTransactionManager already
322
# installed, so return that one, but also emit a warning.
323
warnings.warn(alreadyInstalledMsg, stacklevel=3)
325
config.push(cls._CONFIG_OVERLAY_NAME, overlay)
326
cls._config_overlay = overlay
328
cls._isolation = isolation
331
return cls._installed
286
dbconfig.override(dbuser=dbuser, isolation_level=isolation_level)
289
cls._isolation = isolation
334
294
def _reset_stores():
367
327
assert cls._installed is not None, (
368
328
"ZopelessTransactionManager not installed")
369
config.pop(cls._CONFIG_OVERLAY_NAME)
329
dbconfig.override(dbuser=None, isolation_level=None)
370
330
cls._reset_stores()
371
331
cls._installed = None
374
def set_isolation_level(cls, isolation):
375
"""Set the transaction isolation level.
377
Level can be one of ISOLATION_LEVEL_AUTOCOMMIT,
378
ISOLATION_LEVEL_READ_COMMITTED or
379
ISOLATION_LEVEL_SERIALIZABLE. As changing the isolation level
380
must be done before any other queries are issued in the
381
current transaction, this method automatically issues a
382
rollback to ensure this is the case.
384
assert cls._installed is not None, (
385
"ZopelessTransactionManager not installed")
387
cls.initZopeless(cls._dbuser, isolation)
391
store = _get_sqlobject_store()
392
# Use of the raw connection will not be coherent with Storm's
394
connection = store._connection
395
connection._ensure_connected()
396
return connection._raw_connection
400
"""Begin a transaction."""
405
"""Commit the current transaction."""
410
"""Abort the current transaction."""
414
def registerSynch(synch):
415
"""Register an ISynchronizer."""
416
transaction.manager.registerSynch(synch)
419
def unregisterSynch(synch):
420
"""Unregister an ISynchronizer."""
421
transaction.manager.unregisterSynch(synch)
424
334
def clear_current_connection_cache():
425
335
"""Clear SQLObject's object cache. SQLObject compatibility - DEPRECATED.
427
337
_get_sqlobject_store().invalidate()
430
def expire_from_cache(obj):
431
"""Expires a single object from the SQLObject cache.
432
SQLObject compatibility - DEPRECATED."""
433
_get_sqlobject_store().invalidate(obj)
436
340
def get_transaction_timestamp():
437
341
"""Get the timestamp for the current transaction on the MAIN DEFAULT
438
342
store. DEPRECATED - if needed it should become a method on the store.
730
634
return mergeFunctionMetadata(func, reset_store_decorator)
733
# Some helpers intended for use with initZopeless. These allow you to avoid
734
# passing the transaction manager all through your code.
737
"""Begins a transaction."""
637
# DEPRECATED -- use transaction.commit() directly.
746
639
transaction.commit()