[Z3-sqlos] Different database connections for different sqlobject containers
Joseph Kocherhans
jkocherhans at mac.com
Fri Oct 8 21:45:24 CEST 2004
I've come up with a proof of concept of sorts for having different db
connections depending on the container. I'm not familiar enough with
zope.app.rdb, etc. to know all the implications of this, but I *am* a
little concerned about whether new connections are going to be
initialized on every request. Anyhow, if anyone sees anything blatantly
bad, or even has any concerns I can explore that would be great.
This really just consists of 3 extra lines in SQLObjectContainer's
items method. Right now the connection name is dependent on the name of
the container. Obviously that won't work in the real world, but I'm
just testing for now. If this pans out then I'll add an interface to
select the connection TTW.
Sidnei suggested I look in ConnectionDescriptor for a way to do this,
but I couldn't figure out how to access any contextual information from
there. Without the context I don't think there's a way to decide
between different connections.
Thanks,
Joseph
def items(self):
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
for factoryName in self.allowedFactories():
factory = getFactory(factoryName)
+ from sqlos.connection import ConnectionDescriptor
+ conn = ConnectionDescriptor(self.__name__)
+ factory.setConnection(conn) #<- should probably use an
adapter here to make sure factory implements setConnection
for obj in factory.select():
name = '%s.%s' % (factoryName, obj.id)
yield (name, contained(obj, parent=self, name=name))
More information about the z3-sqlos
mailing list