Need help porting Prevayler (Java) to Python
Michal Wallace
sabren at manifestation.com
Wed Oct 2 16:19:16 EDT 2002
On Wed, 2 Oct 2002, Patrick K. O'Brien wrote:
> Prevayler is an interesting object persistence system written in Java that
> I'd like to see ported to Python. The system is simple, and the code is only
> a couple of hundred lines, so this should be relatively easy to do. I'm
> looking for people with good Java skills to help create a similar system in
> Python. Anyone interested?
This is pretty smart.
I wrote a couple packages ("arlo" and "storage") that do
something very much like this. It's meant to be a front-end
to various storage systems (MetaKit, MySQL, etc), and for
testing purposes, I implemented a purely in-memory database.
My stuff actually transforms the objects to and from
dictionaries, but you wouldn't have to.
I like the idea of persisting the commands, but the idea of
writing your own for every Add/Insert/Delete seems to be
java nastiness to work around the static typing.
I don't think I would port it directly; it's just not very
pythonic. Instead, wouldn't you want something like:
class PyPrevalance:
def __init__(self):
self._data = {}
def add(self, obj):
klass = obj.__class__
try:
self._data.setdefault(klass, [])
self._data[klass].append(obj)
self.log("add", object)
except Exception, e:
pass # really, rollback...
# etc...
It *is* nice to be able to fire off actions on an
add/edit/delete, which their use of the Command pattern
gives you. In that case, add() might look like:
def add(self, obj):
self._do(GenericAddCommand(obj))
def _do(self, cmd):
cmd.execute(self)
self.log.append(cmd)
def undo(self):
cmd = self.log.pop()
cmd.rollback(self)
I marked _do as private because it seems like you're meant
to subclass the server itself to add your own commands and
queries.
Anyway, doesn't ZODB do all this?
Cheers,
- Michal http://www.sabren.net/ sabren at manifestation.com
------------------------------------------------------------
Switch to Cornerhost! http://www.cornerhost.com/
Low Priced, Reliable Blog Hosting, With a Human Touch. :)
------------------------------------------------------------
More information about the Python-list
mailing list