[Zodb-checkins] CVS: StandaloneZODB/ZODB - Connection.py:1.70 cPersistence.c:1.60
Jeremy Hylton
jeremy@zope.com
Fri, 14 Jun 2002 11:29:31 -0400
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv447/ZODB
Modified Files:
Connection.py cPersistence.c
Log Message:
Add a level of redirection to change registration for persistent objects.
changed() in cPersistence.c now calls the jar's register() method.
Connection's register() method just calls get_transaction().register().
This redirection would allow specialized Connection's to change the
default policy on how the transaction manager is selected without
hacking the Transaction module.
The cPersistence.c code is based on _PyPersist_RegisterDataManager()
from the Zope3 code.
=== StandaloneZODB/ZODB/Connection.py 1.69 => 1.70 ===
return self._version
- def root(self): return self['\0\0\0\0\0\0\0\0']
+ def register(self, object):
+ """Register an object with the appropriate transaction manager.
+
+ A subclass could override this method to customize the default
+ policy of one transaction manager for each thread.
+ """
+ assert object._p_jar is self
+ assert object._p_oid is not None
+ get_transaction().register(object)
+
+ def root(self):
+ return self['\0\0\0\0\0\0\0\0']
def setstate(self, object):
oid = object._p_oid
=== StandaloneZODB/ZODB/cPersistence.c 1.59 => 1.60 ===
changed(cPersistentObject *self)
{
- static PyObject *builtins=0, *get_transaction=0, *py_register=0;
- PyObject *T;
-
if ((self->state == cPersistent_UPTODATE_STATE ||
self->state == cPersistent_STICKY_STATE)
&& self->jar)
{
- UNLESS (get_transaction)
- {
- UNLESS (py_register=PyString_FromString("register")) return -1;
- UNLESS (T=PyImport_ImportModule("__main__")) return -1;
- ASSIGN(T,PyObject_GetAttrString(T,"__builtins__"));
- UNLESS (T) return -1;
- builtins=T;
- UNLESS (get_transaction=PyObject_GetAttrString(builtins,
- "get_transaction"))
- PyErr_Clear();
- }
- if (get_transaction)
- {
- UNLESS (T=PyObject_CallObject(get_transaction,NULL)) return -1;
- ASSIGN(T,PyObject_GetAttr(T,py_register));
- UNLESS (T) return -1;
- ASSIGN(T, PyObject_CallFunction(T,"O",self));
- if (T) Py_DECREF(T);
- else return -1;
+ PyObject *meth, *arg, *result;
+ static PyObject *s_register;
+
+ if (s_register == NULL)
+ s_register = PyString_InternFromString("register");
+ meth = PyObject_GetAttr((PyObject *)self->jar, s_register);
+ if (meth == NULL)
+ return -1;
+ arg = PyTuple_New(1);
+ if (arg == NULL) {
+ Py_DECREF(meth);
+ return -1;
}
+ PyTuple_SET_ITEM(arg, 0, (PyObject *)self);
+ result = PyObject_Call(meth, arg, NULL);
+ PyTuple_SET_ITEM(arg, 0, NULL);
+ Py_DECREF(arg);
+ Py_DECREF(meth);
+ if (result == NULL)
+ return -1;
+ Py_DECREF(result);
- self->state=cPersistent_CHANGED_STATE;
+ self->state = cPersistent_CHANGED_STATE;
}
return 0;