Commit 25c3184d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 599409a1
...@@ -264,6 +264,8 @@ ZODB.Connection.Connection.open = Connection_open ...@@ -264,6 +264,8 @@ ZODB.Connection.Connection.open = Connection_open
# patch for ZODB.Connection to support callback on after database view is changed # patch for ZODB.Connection to support callback on after database view is changed
ZODB.Connection.Connection._onResyncCallbacks = None ZODB.Connection.Connection._onResyncCallbacks = None
def Connection_onResyncCallback(self, f): def Connection_onResyncCallback(self, f):
if zmajor <= 4:
raise AssertionError("onResyncCallback: TODO: add support for ZODB34")
if self._onResyncCallbacks is None: if self._onResyncCallbacks is None:
# NOTE WeakSet does not work for bound methods - they are always created # NOTE WeakSet does not work for bound methods - they are always created
# anew for each obj.method access, and thus will go away almost immediately # anew for each obj.method access, and thus will go away almost immediately
...@@ -273,21 +275,27 @@ def Connection_onResyncCallback(self, f): ...@@ -273,21 +275,27 @@ def Connection_onResyncCallback(self, f):
assert not hasattr(ZODB.Connection.Connection, 'onResyncCallback') assert not hasattr(ZODB.Connection.Connection, 'onResyncCallback')
ZODB.Connection.Connection.onResyncCallback = Connection_onResyncCallback ZODB.Connection.Connection.onResyncCallback = Connection_onResyncCallback
# ZODB5: hook into Connection.newTransaction XXX .newTransaction .afterCompletion ? # ZODB5: hook into Connection.newTransaction
# ZODB4: hook into Connection._storage_sync XXX .newTransaction .afterCompletion ? if zmajor >= 5:
# ZODB3: TODO _orig_Connection_newTransaction = ZODB.Connection.Connection.newTransaction
# XXX ZODB5 only for now def _ZConnection_newTransaction(self, transaction, sync=True):
# XXX ERP5Type/patches/ZODBConnection.py overrides newTransaction without calling orig_newTransaction _orig_Connection_newTransaction(self, transaction, sync)
# -> fix it there.
_orig_Connection_newTransaction = ZODB.Connection.Connection.newTransaction
def _ZConnection_newTransaction(self, transaction, sync=True):
_orig_Connection_newTransaction(self, transaction, sync)
# FIXME method name hardcoded. Better not do it and allow f to be general # FIXME method name hardcoded. Better not do it and allow f to be general
# callable, but that does not work with bound method - see above. # callable, but that does not work with bound method - see above.
# ( Something like WeakMethod from py3 could help ) # ( Something like WeakMethod from py3 could help )
if self._onResyncCallbacks: if self._onResyncCallbacks:
for f in self._onResyncCallbacks: for f in self._onResyncCallbacks:
f.on_connection_resync() f.on_connection_resync()
ZODB.Connection.Connection.newTransaction = _ZConnection_newTransaction
ZODB.Connection.Connection.newTransaction = _ZConnection_newTransaction
# ZODB4: hook into Connection._storage_sync
elif zmajor == 4:
pass # raises in onResyncCallback
# ZODB3: TODO
else:
pass # raises in onResyncCallback
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment