Commit 81d666f2 authored by Jeremy Hylton's avatar Jeremy Hylton

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.
parent 5b1cc377
......@@ -14,7 +14,7 @@
static char cPersistence_doc_string[] =
"Defines Persistent mixin class for persistent objects.\n"
"\n"
"$Id: cPersistence.c,v 1.59 2002/04/15 18:42:51 jeremy Exp $\n";
"$Id: cPersistence.c,v 1.60 2002/06/14 15:29:30 jeremy Exp $\n";
#include "cPersistence.h"
......@@ -214,35 +214,33 @@ deallocated(cPersistentObject *self)
static int
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;
......
......@@ -13,7 +13,7 @@
##############################################################################
"""Database connection support
$Id: Connection.py,v 1.69 2002/06/12 19:40:47 jeremy Exp $"""
$Id: Connection.py,v 1.70 2002/06/14 15:29:30 jeremy Exp $"""
from cPickleCache import PickleCache, MUCH_RING_CHECKING
from POSException import ConflictError, ReadConflictError
......@@ -480,7 +480,18 @@ class Connection(ExportImport.ExportImport):
except KeyError:
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
......
......@@ -14,7 +14,7 @@
static char cPersistence_doc_string[] =
"Defines Persistent mixin class for persistent objects.\n"
"\n"
"$Id: cPersistence.c,v 1.59 2002/04/15 18:42:51 jeremy Exp $\n";
"$Id: cPersistence.c,v 1.60 2002/06/14 15:29:30 jeremy Exp $\n";
#include "cPersistence.h"
......@@ -214,35 +214,33 @@ deallocated(cPersistentObject *self)
static int
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;
......
......@@ -14,7 +14,7 @@
static char cPersistence_doc_string[] =
"Defines Persistent mixin class for persistent objects.\n"
"\n"
"$Id: cPersistence.c,v 1.59 2002/04/15 18:42:51 jeremy Exp $\n";
"$Id: cPersistence.c,v 1.60 2002/06/14 15:29:30 jeremy Exp $\n";
#include "cPersistence.h"
......@@ -214,35 +214,33 @@ deallocated(cPersistentObject *self)
static int
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;
......
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