~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/database/doc/db-policy.txt

  • Committer: Curtis Hovey
  • Date: 2011-12-24 17:49:30 UTC
  • mto: This revision was merged to the branch mainline in revision 14602.
  • Revision ID: curtis.hovey@canonical.com-20111224174930-xk1d5cvhyxq46ctf
Moved webapp to lp.services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
To alter this behavior, you can install a different database policy.
64
64
 
65
 
    >>> from canonical.launchpad.webapp.dbpolicy import SlaveDatabasePolicy
 
65
    >>> from lp.services.webapp.dbpolicy import SlaveDatabasePolicy
66
66
    >>> with SlaveDatabasePolicy():
67
67
    ...     default_janitor = IStore(Person).find(
68
68
    ...         Person, Person.name == 'janitor').one()
76
76
raise an exception if an attempt is made to access master database
77
77
resources.
78
78
 
79
 
    >>> from canonical.launchpad.webapp.dbpolicy import (
 
79
    >>> from lp.services.webapp.dbpolicy import (
80
80
    ...     SlaveOnlyDatabasePolicy)
81
81
    >>> with SlaveOnlyDatabasePolicy():
82
82
    ...     whoops = IMasterStore(Person).find(
90
90
the database at all starting a new and potentially long running
91
91
database transaction.
92
92
 
93
 
    >>> from canonical.launchpad.webapp.dbpolicy import DatabaseBlockedPolicy
 
93
    >>> from lp.services.webapp.dbpolicy import DatabaseBlockedPolicy
94
94
    >>> with DatabaseBlockedPolicy():
95
95
    ...     whoops = IStore(Person).find(
96
96
    ...         Person, Person.name == 'janitor').one()
102
102
IStoreSelector utility for cases where the 'with' syntax cannot
103
103
be used.
104
104
 
105
 
    >>> from canonical.launchpad.webapp.interfaces import IStoreSelector
 
105
    >>> from lp.services.webapp.interfaces import IStoreSelector
106
106
    >>> getUtility(IStoreSelector).push(SlaveDatabasePolicy())
107
107
    >>> try:
108
108
    ...     default_janitor = IStore(Person).find(
132
132
for a master store fail and the default store is always the slave.
133
133
 
134
134
    >>> from lp.services.database.tests.readonly import read_only_mode
135
 
    >>> from canonical.launchpad.webapp.dbpolicy import MasterDatabasePolicy
 
135
    >>> from lp.services.webapp.dbpolicy import MasterDatabasePolicy
136
136
    >>> from contextlib import nested
137
137
 
138
138
    >>> with nested(read_only_mode(), MasterDatabasePolicy()):