author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 08 Feb 2010 09:57:25 +0100 | |
branch | stable |
changeset 4488 | e8e7f6a0e7b6 |
parent 4212 | ab6573088b4a |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
0 | 1 |
"""CubicWeb server connections pool : |
2 |
||
3 |
* the rql repository has a limited number of connections pools, each of them |
|
4 |
dealing with a set of connections on each source used by the repository |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
5 |
|
0 | 6 |
* operation may be registered by hooks during a transaction, which will be |
7 |
fired when the pool is commited or rollbacked |
|
8 |
||
9 |
This module defined the `ConnectionsPool` class and a set of abstract classes |
|
10 |
for operation. |
|
11 |
||
12 |
||
13 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3986
diff
changeset
|
14 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 15 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
16 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 17 |
""" |
18 |
__docformat__ = "restructuredtext en" |
|
19 |
||
20 |
import sys |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
21 |
|
0 | 22 |
class ConnectionsPool(object): |
23 |
"""handle connections on a set of sources, at some point associated to a |
|
24 |
user session |
|
25 |
""" |
|
26 |
||
27 |
def __init__(self, sources): |
|
28 |
# dictionnary of (source, connection), indexed by sources'uri |
|
29 |
self.source_cnxs = {} |
|
30 |
for source in sources: |
|
31 |
self.source_cnxs[source.uri] = (source, source.get_connection()) |
|
32 |
if not 'system' in self.source_cnxs: |
|
33 |
self.source_cnxs['system'] = self.source_cnxs[sources[0].uri] |
|
34 |
self._cursors = {} |
|
35 |
||
2765
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
36 |
def __getitem__(self, uri): |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
37 |
"""subscription notation provide access to sources'cursors""" |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
38 |
try: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
39 |
cursor = self._cursors[uri] |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
40 |
except KeyError: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
41 |
cursor = self.source_cnxs[uri][1].cursor() |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
42 |
if cursor is not None: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
43 |
# None possible on sources without cursor support such as ldap |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
44 |
self._cursors[uri] = cursor |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
45 |
return cursor |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
46 |
|
0 | 47 |
def commit(self): |
48 |
"""commit the current transaction for this user""" |
|
49 |
# FIXME: what happends if a commit fail |
|
50 |
# would need a two phases commit or like, but I don't know how to do |
|
51 |
# this using the db-api... |
|
52 |
for source, cnx in self.source_cnxs.values(): |
|
53 |
# let exception propagates |
|
54 |
cnx.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
55 |
|
0 | 56 |
def rollback(self): |
57 |
"""rollback the current transaction for this user""" |
|
58 |
for source, cnx in self.source_cnxs.values(): |
|
59 |
# catch exceptions, rollback other sources anyway |
|
60 |
try: |
|
61 |
cnx.rollback() |
|
62 |
except: |
|
63 |
source.critical('rollback error', exc_info=sys.exc_info()) |
|
64 |
||
65 |
def close(self, i_know_what_i_do=False): |
|
66 |
"""close all connections in the pool""" |
|
67 |
if i_know_what_i_do is not True: # unexpected closing safety belt |
|
68 |
raise RuntimeError('pool shouldn\'t be closed') |
|
69 |
for cu in self._cursors.values(): |
|
70 |
try: |
|
71 |
cu.close() |
|
72 |
except: |
|
73 |
continue |
|
74 |
for _, cnx in self.source_cnxs.values(): |
|
75 |
try: |
|
76 |
cnx.close() |
|
77 |
except: |
|
78 |
continue |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
79 |
|
0 | 80 |
# internals ############################################################### |
81 |
||
2063
fe4278b50388
fix [re]set_pool prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
82 |
def pool_set(self): |
0 | 83 |
"""pool is being set""" |
84 |
self.check_connections() |
|
85 |
||
2063
fe4278b50388
fix [re]set_pool prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
86 |
def pool_reset(self): |
0 | 87 |
"""pool is being reseted""" |
88 |
for source, cnx in self.source_cnxs.values(): |
|
89 |
source.pool_reset(cnx) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
90 |
|
0 | 91 |
def sources(self): |
92 |
"""return the source objects handled by this pool""" |
|
93 |
# implementation details of flying insert requires the system source |
|
94 |
# first |
|
2765
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
95 |
yield self.source_cnxs['system'][0] |
0 | 96 |
for uri, (source, cursor) in self.source_cnxs.items(): |
97 |
if uri == 'system': |
|
98 |
continue |
|
99 |
yield source |
|
100 |
#return [source_cnx[0] for source_cnx in self.source_cnxs.values()] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
101 |
|
0 | 102 |
def source(self, uid): |
103 |
"""return the source object with the given uri""" |
|
104 |
return self.source_cnxs[uid][0] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
105 |
|
0 | 106 |
def connection(self, uid): |
107 |
"""return the connection on the source object with the given uri""" |
|
108 |
return self.source_cnxs[uid][1] |
|
109 |
||
2765
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
110 |
def reconnect(self, source=None): |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
111 |
"""reopen a connection for this source or all sources if none specified |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
112 |
""" |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
113 |
if source is None: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
114 |
sources = self.sources() |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
115 |
else: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
116 |
sources = (source,) |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
117 |
for source in sources: |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
118 |
source.info('trying to reconnect') |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
119 |
self.source_cnxs[source.uri] = (source, source.get_connection()) |
5e2525d7b1b1
reconnect without argument reconnect all sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2063
diff
changeset
|
120 |
self._cursors.pop(source.uri, None) |
0 | 121 |
|
122 |
def check_connections(self): |
|
123 |
for source, cnx in self.source_cnxs.itervalues(): |
|
124 |
newcnx = source.check_connection(cnx) |
|
125 |
if newcnx is not None: |
|
126 |
self.reset_connection(source, newcnx) |
|
127 |
||
128 |
def reset_connection(self, source, cnx): |
|
129 |
self.source_cnxs[source.uri] = (source, cnx) |
|
130 |
self._cursors.pop(source.uri, None) |
|
131 |
||
132 |
||
133 |
class Operation(object): |
|
134 |
"""an operation is triggered on connections pool events related to |
|
135 |
commit / rollback transations. Possible events are: |
|
136 |
||
137 |
precommit: |
|
138 |
the pool is preparing to commit. You shouldn't do anything things which |
|
139 |
has to be reverted if the commit fail at this point, but you can freely |
|
140 |
do any heavy computation or raise an exception if the commit can't go. |
|
141 |
You can add some new operation during this phase but their precommit |
|
142 |
event won't be triggered |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
143 |
|
0 | 144 |
commit: |
145 |
the pool is preparing to commit. You should avoid to do to expensive |
|
146 |
stuff or something that may cause an exception in this event |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
147 |
|
0 | 148 |
revertcommit: |
149 |
if an operation failed while commited, this event is triggered for |
|
150 |
all operations which had their commit event already to let them |
|
151 |
revert things (including the operation which made fail the commit) |
|
152 |
||
153 |
rollback: |
|
154 |
the transaction has been either rollbacked either |
|
155 |
* intentionaly |
|
156 |
* a precommit event failed, all operations are rollbacked |
|
157 |
* a commit event failed, all operations which are not been triggered for |
|
158 |
commit are rollbacked |
|
159 |
||
160 |
order of operations may be important, and is controlled according to: |
|
161 |
* operation's class |
|
162 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
163 |
|
0 | 164 |
def __init__(self, session, **kwargs): |
165 |
self.session = session |
|
166 |
self.user = session.user |
|
167 |
self.repo = session.repo |
|
168 |
self.schema = session.repo.schema |
|
169 |
self.config = session.repo.config |
|
170 |
self.__dict__.update(kwargs) |
|
171 |
self.register(session) |
|
172 |
# execution information |
|
173 |
self.processed = None # 'precommit', 'commit' |
|
174 |
self.failed = False |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
175 |
|
0 | 176 |
def register(self, session): |
177 |
session.add_operation(self, self.insert_index()) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
178 |
|
0 | 179 |
def insert_index(self): |
180 |
"""return the index of the lastest instance which is not a |
|
181 |
LateOperation instance |
|
182 |
""" |
|
3691
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
183 |
# faster by inspecting operation in reverse order for heavy transactions |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
184 |
i = None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
185 |
for i, op in enumerate(reversed(self.session.pending_operations)): |
0 | 186 |
if isinstance(op, (LateOperation, SingleLastOperation)): |
3691
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
187 |
continue |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
188 |
return -i or None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
189 |
if i is None: |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
190 |
return None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
191 |
return -(i + 1) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
192 |
|
0 | 193 |
def handle_event(self, event): |
3986
cc29eddf51ad
add postcommit_event on Operations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3691
diff
changeset
|
194 |
"""delegate event handling to the operation""" |
0 | 195 |
getattr(self, event)() |
196 |
||
197 |
def precommit_event(self): |
|
198 |
"""the observed connections pool is preparing a commit""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
199 |
|
0 | 200 |
def revertprecommit_event(self): |
201 |
"""an error went when pre-commiting this operation or a later one |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
202 |
|
0 | 203 |
should revert pre-commit's changes but take care, they may have not |
204 |
been all considered if it's this operation which failed |
|
205 |
""" |
|
206 |
||
207 |
def commit_event(self): |
|
208 |
"""the observed connections pool is commiting""" |
|
209 |
raise NotImplementedError() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
210 |
|
0 | 211 |
def revertcommit_event(self): |
212 |
"""an error went when commiting this operation or a later one |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
213 |
|
0 | 214 |
should revert commit's changes but take care, they may have not |
215 |
been all considered if it's this operation which failed |
|
216 |
""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
217 |
|
0 | 218 |
def rollback_event(self): |
219 |
"""the observed connections pool has been rollbacked |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
220 |
|
0 | 221 |
do nothing by default, the operation will just be removed from the pool |
222 |
operation list |
|
223 |
""" |
|
224 |
||
3986
cc29eddf51ad
add postcommit_event on Operations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3691
diff
changeset
|
225 |
def postcommit_event(self): |
cc29eddf51ad
add postcommit_event on Operations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3691
diff
changeset
|
226 |
"""the observed connections pool has committed""" |
cc29eddf51ad
add postcommit_event on Operations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3691
diff
changeset
|
227 |
|
0 | 228 |
|
229 |
class PreCommitOperation(Operation): |
|
230 |
"""base class for operation only defining a precommit operation |
|
231 |
""" |
|
232 |
||
233 |
def precommit_event(self): |
|
234 |
"""the observed connections pool is preparing a commit""" |
|
235 |
raise NotImplementedError() |
|
236 |
||
237 |
def commit_event(self): |
|
238 |
"""the observed connections pool is commiting""" |
|
239 |
||
240 |
||
241 |
class LateOperation(Operation): |
|
242 |
"""special operation which should be called after all possible (ie non late) |
|
243 |
operations |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
244 |
""" |
0 | 245 |
def insert_index(self): |
246 |
"""return the index of the lastest instance which is not a |
|
247 |
SingleLastOperation instance |
|
248 |
""" |
|
3691
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
249 |
# faster by inspecting operation in reverse order for heavy transactions |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
250 |
i = None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
251 |
for i, op in enumerate(reversed(self.session.pending_operations)): |
0 | 252 |
if isinstance(op, SingleLastOperation): |
3691
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
253 |
continue |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
254 |
return -i or None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
255 |
if i is None: |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
256 |
return None |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
257 |
return -(i + 1) |
0 | 258 |
|
259 |
||
260 |
class SingleOperation(Operation): |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
261 |
"""special operation which should be called once""" |
0 | 262 |
def register(self, session): |
263 |
"""override register to handle cases where this operation has already |
|
264 |
been added |
|
265 |
""" |
|
266 |
operations = session.pending_operations |
|
267 |
index = self.equivalent_index(operations) |
|
268 |
if index is not None: |
|
269 |
equivalent = operations.pop(index) |
|
270 |
else: |
|
271 |
equivalent = None |
|
272 |
session.add_operation(self, self.insert_index()) |
|
273 |
return equivalent |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
274 |
|
0 | 275 |
def equivalent_index(self, operations): |
276 |
"""return the index of the equivalent operation if any""" |
|
3691
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
277 |
for i, op in enumerate(reversed(operations)): |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
278 |
if op.__class__ is self.__class__: |
ccd72f500daa
reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2765
diff
changeset
|
279 |
return -(i+1) |
0 | 280 |
return None |
281 |
||
282 |
||
283 |
class SingleLastOperation(SingleOperation): |
|
284 |
"""special operation which should be called once and after all other |
|
285 |
operations |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1132
diff
changeset
|
286 |
""" |
0 | 287 |
def insert_index(self): |
288 |
return None |
|
289 |
||
290 |
from logging import getLogger |
|
291 |
from cubicweb import set_log_methods |
|
292 |
set_log_methods(Operation, getLogger('cubicweb.session')) |