~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transactions.py

Add finished() notifications to transactions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
            else:
110
110
                offset += 1
111
111
 
 
112
    def writeable(self):
 
113
        """Read only transactions do not allow writes."""
 
114
 
112
115
 
113
116
class WriteTransaction(ReadOnlyTransaction):
114
117
    """A write transaction
118
121
    - dirty objects are retained.
119
122
    """
120
123
 
 
124
    def finish(self):
 
125
        """Clean up this transaction."""
 
126
        for thing in self._dirty_objects:
 
127
            callback = getattr(thing, 'transaction_finished', None)
 
128
            if callback is not None:
 
129
                callback()
 
130
 
121
131
    def __init__(self):
122
132
        super(WriteTransaction, self).__init__()
123
133
        self._dirty_objects = set()
130
140
        """Register an_object as being dirty.
131
141
        
132
142
        Dirty objects are not ejected from the identity map
133
 
        until the transaction finishes.
 
143
        until the transaction finishes and get informed
 
144
        when the transaction finishes.
134
145
        """
135
146
        self._dirty_objects.add(an_object)
136
147
        if self.is_clean(an_object):
138
149
            del self._clean_queue[self._clean_queue.index(an_object)]
139
150
        self._trim()
140
151
 
 
152
    def writeable(self):
 
153
        """Write transactions allow writes."""
 
154
        return True
 
155
 
141
156
        
142
157
class PassThroughTransaction(object):
143
158
    """A pass through transaction
148
163
 
149
164
    def finish(self):
150
165
        """Clean up this transaction."""
 
166
        for thing in self._dirty_objects:
 
167
            callback = getattr(thing, 'transaction_finished', None)
 
168
            if callback is not None:
 
169
                callback()
151
170
 
152
171
    def __init__(self):
153
172
        super(PassThroughTransaction, self).__init__()
154
173
        self.map = NullIdentityMap()
 
174
        self._dirty_objects = set()
155
175
 
156
176
    def register_clean(self, an_object, precious=False):
157
177
        """Register an_object as being clean.
161
181
        """
162
182
 
163
183
    def register_dirty(self, an_object):
164
 
        """Register an_object as being dirty."""
 
184
        """Register an_object as being dirty.
 
185
        
 
186
        Dirty objects get informed
 
187
        when the transaction finishes.
 
188
        """
 
189
        self._dirty_objects.add(an_object)
165
190
 
166
191
    def set_cache_size(self, ignored):
167
192
        """Do nothing, we are passing through."""
 
193
 
 
194
    def writeable(self):
 
195
        """Pass through transactions allow writes."""
 
196
        return True