[orm-devel] Unified Connection Strings
Diedrich Vorberg
orm-devel@mailman.tux4web.de
Mon, 2 Dec 2002 10:50:11 +0100
Hi Ross,
>Hmm, what is a ORMDatasourcePool Product? I was just looking at what it
>would take use orm from inside other Zope products, using a Zope SQL DA
>as the datasource. Is that anything like what you're up to, or something
>even more integrated?
This is my solution using a Zope SQL DA (ZPsycopgDA), just
subclassing the PostgreSQL datasource.
class datasource(orm.adapters.psql.datasource.datasource):
"""
We're using Zope's mechanism for database connections here.
This is a subclass of orm's psycopg adapter.
"""
def __init__(self, context):
zope_ds = context.restrictedTraverse("zope_ds")
self._conn = zope_ds().db
self._encoding = "iso-8859-1"
self._dsn = ""
The problem I can see is, that there is only one connection to the
database. PostgreSQL will maintain transactions connection-wise. So
if one of my threads runs a couple of queries on one connection and
another runs a rollback() on that connection my changes are lost.
Even an unwanted commit() might lead to trouble.
The Zope Product I'm currently working on is in the CVS contrib
directory, but be warned it, is rather primitive :-) It provides
(besides the Zope Management facilities) two methods: aquire() and
release(). There is a minium and maximum number of connections the
Pool will create to the RDBMS. aquire() will return one to you if
one is available or open a new one for you. If the maximum number of
open connections is reached it will make you wait until one is
released().
This is untested, I'm going to start working with it today.
There is a rather nasty problem with ORM and Zope. ORM requires
Python 2.2, because of Python's builtin classmethod(). Zope will warn
about 2.1 being the preferred version to run it with, but to my
experience will run fine. The problem: starting Zope using Python 2.2
takes forever, which is a pain when developing a product.
My solution (er... workaround) is to have two version of my
Application, one that runs on 2.2 and one that runs on 2.1 using a
defunc version of ORM.
You can use 2.2 and Zope just make sure you have some kind of way to
reload() all your modules without restarting Zope.
Diedrich
--
_..._ Diedrich Vorberg
.' '.
/ _ _ \ http://www.tux4web.de
| (o)_(o) | info@tux4web.de
\( ) / .---.
//'._.'\ \ / \ Internet Dienstleistungen
// . \ \ \.@-@./ und 'Consulting'.
|| . \ \ /`\_/`\
|\ : / | // _ \\ Linux Rules!
\ `) ' (` /_ | \ )|_
_)``".____,.'"` (_ /`\_`> <_/ \
) )'--'( ( \__/'---'\__/
'---` `---`