14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""This module provides a transactional facility.
30
30
write ordering approach we use for consistency 'dirty' is a misleading term.
31
31
A dirty object is one we have modified.
33
Both read and write transactions *may* flush unchanged objects out of
34
memory, unless they are marked as 'precious' which indicates that
33
Both read and write transactions *may* flush unchanged objects out of
34
memory, unless they are marked as 'precious' which indicates that
35
35
repeated reads cannot be obtained if the object is ejected, or that
36
36
the object is an expensive one for obtaining.
60
60
def is_clean(self, an_object):
61
61
"""Return True if an_object is clean."""
62
return (an_object in self._clean_objects)
62
return an_object in self._clean_objects
64
64
def register_clean(self, an_object, precious=False):
65
65
"""Register an_object as being clean.
67
67
If the precious hint is True, the object will not
68
68
be ejected from the object identity map ever.
122
118
- dirty objects are retained.
126
"""Clean up this transaction."""
127
for thing in self._dirty_objects:
128
callback = getattr(thing, 'transaction_finished', None)
129
if callback is not None:
132
121
def __init__(self):
133
122
super(WriteTransaction, self).__init__()
134
123
self._dirty_objects = set()
136
125
def is_dirty(self, an_object):
137
126
"""Return True if an_object is dirty."""
138
return (an_object in self._dirty_objects)
127
return an_object in self._dirty_objects
140
129
def register_dirty(self, an_object):
141
130
"""Register an_object as being dirty.
143
132
Dirty objects are not ejected from the identity map
144
until the transaction finishes and get informed
145
when the transaction finishes.
133
until the transaction finishes.
147
135
self._dirty_objects.add(an_object)
148
136
if self.is_clean(an_object):
150
138
del self._clean_queue[self._clean_queue.index(an_object)]
154
"""Write transactions allow writes."""
158
142
class PassThroughTransaction(object):
159
143
"""A pass through transaction
161
145
- nothing is cached.
162
146
- nothing ever gets into the identity map.
165
149
def finish(self):
166
150
"""Clean up this transaction."""
167
for thing in self._dirty_objects:
168
callback = getattr(thing, 'transaction_finished', None)
169
if callback is not None:
172
152
def __init__(self):
173
153
super(PassThroughTransaction, self).__init__()
174
154
self.map = NullIdentityMap()
175
self._dirty_objects = set()
177
156
def register_clean(self, an_object, precious=False):
178
157
"""Register an_object as being clean.
180
159
Note that precious is only a hint, and PassThroughTransaction
184
163
def register_dirty(self, an_object):
185
"""Register an_object as being dirty.
187
Dirty objects get informed
188
when the transaction finishes.
190
self._dirty_objects.add(an_object)
164
"""Register an_object as being dirty."""
192
166
def set_cache_size(self, ignored):
193
167
"""Do nothing, we are passing through."""
196
"""Pass through transactions allow writes."""