[storm] Zope - Storm Container Implementation
Gustavo Niemeyer
gustavo at niemeyer.net
Fri Nov 23 18:10:47 GMT 2007
Hey Christian,
> i played the last days a bit with storm.zope.
> Unfortunatly there is no Container for zope.storm,
>
> I´ve looked at the nice z3c.zalchemy [2],
> espacially the container implementation.
>
> I have taken the container.py from z3c.zalchemy as
> a base for the stormcontainer.py attached to this post.
Very nice! Thanks for publishing it.
> As i´m using grok[1]. I subclass the container from
> grok.Container. But i think this should work in a pure Z3
> Environment too. Maybe subclass from zope.container?
>
> I´m waiting for your comments.
A few things to perhaps look after:
- store.delete() is actually store.remove()
- The way that commit() is being done in delitem and
setitem seems dangerous. It means that as a side-effect
of removing an item from the container, all the changes
in the current transaction are persisted.
- You shouldn't have to do flush(). Storm does it
automatically when needed.
- for id in obj.__storm_object_info__.get('primary_vars'):
ident += str(id._value)
You're using private data here, which is not part of the
exposed API, meaning that it may change without warnings. Also,
this internal value may not be available by the time you access
it directly, unlike the actual property.
Besides these points, this isn't a very good way to extract the
key, since (1, 23) will yield the same key as (12, 3), for
instance.
- for obj in store.find(self._class):
if self._getInstanceKey(obj) == str(id):
return obj
That is a *very* expensive way to get an object out of the
database. It will walk through all the objects, potentially.
It should somehow look for the specific key instead.
--
Gustavo Niemeyer
http://niemeyer.net
More information about the storm
mailing list